Class: BetterRailsDebugger::Parser::Analyzer

Inherits:
Object
  • Object
show all
Defined in:
lib/better_rails_debugger/parser/analyzer.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, options) ⇒ Analyzer

Returns a new instance of Analyzer.



4
5
6
7
# File 'lib/better_rails_debugger/parser/analyzer.rb', line 4

def initialize(path, options)
  @path = path
  @options = options
end

Class Method Details

.analise(path, options) ⇒ Object



9
10
11
# File 'lib/better_rails_debugger/parser/analyzer.rb', line 9

def self.analise(path, options)
  self.new(path, options).run
end

Instance Method Details

#get_lang_from_pathObject

get file ext and return language as ‘ruby’, ‘javascript’, ‘php’ or nil if unknown



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/better_rails_debugger/parser/analyzer.rb', line 25

def get_lang_from_path
  case File.extname(@path).downcase
    when '.rb'
      'ruby'
    when '.js'
      'javascript'
    when '.php'
      'php'
    else
      nil
  end
end

#get_lang_instance(lang) ⇒ Object



38
39
40
# File 'lib/better_rails_debugger/parser/analyzer.rb', line 38

def get_lang_instance(lang)
  "BetterRailsDebugger::#{lang.classify}::Parser".constantize.new @path, @options
end

#runObject



13
14
15
16
17
18
19
20
21
22
# File 'lib/better_rails_debugger/parser/analyzer.rb', line 13

def run
  # Check if file exist or not
  raise ArgumentError.new "File #{@path} does not exist" if !File.exist? @path
  # Detect lang by file ext
  lang = get_lang_from_path
  raise ArgumentError.new "Sorry, we do not support that language" if lang != 'ruby' # Only ruby by the moment
  # Create lang instance with options
  lang_instance = get_lang_instance lang
  # parse
end