Class: Mbeditor::JsMembersService

Inherits:
Object
  • Object
show all
Defined in:
app/services/mbeditor/js_members_service.rb

Overview

Searches JS/JSX/TS/TSX files for properties/methods attached to a named global object (direct assignment and prototype assignment patterns).

Examples matched for symbol “ReactWindow”:

ReactWindow.open = function() { ... }
ReactWindow.prototype.close = function() { ... }

Returns an array of hashes:

{ name: String, snippet: String }

Constant Summary collapse

MAX_RESULTS =
50
JS_GLOBS =
%w[*.js *.jsx *.ts *.tsx *.js.jsx *.js.erb *.jsx.erb].freeze

Instance Method Summary collapse

Constructor Details

#initialize(symbol, workspace_root) ⇒ JsMembersService

Returns a new instance of JsMembersService.



20
21
22
23
# File 'app/services/mbeditor/js_members_service.rb', line 20

def initialize(symbol, workspace_root)
  @symbol         = symbol.to_s
  @workspace_root = workspace_root.to_s.chomp("/")
end

Instance Method Details

#callObject



25
26
27
28
29
30
31
32
# File 'app/services/mbeditor/js_members_service.rb', line 25

def call
  return [] if @symbol.empty? || @workspace_root.empty?
  return [] unless File.directory?(@workspace_root)

  pattern = build_pattern
  lines   = run_search(pattern)
  parse_results(lines)
end