Class: BetterRailsDebugger::Parser::Analyzer
- Inherits:
-
Object
- Object
- BetterRailsDebugger::Parser::Analyzer
- Defined in:
- lib/better_rails_debugger/parser/analyzer.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#get_lang_from_path ⇒ Object
get file ext and return language as ‘ruby’, ‘javascript’, ‘php’ or nil if unknown.
- #get_lang_instance(lang) ⇒ Object
-
#initialize(path, options) ⇒ Analyzer
constructor
A new instance of Analyzer.
- #run ⇒ Object
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, ) @path = path @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, ) self.new(path, ).run end |
Instance Method Details
#get_lang_from_path ⇒ Object
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 |
#run ⇒ Object
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 |