lib/reek/source/source_code.rb in reek-1.2.11 vs lib/reek/source/source_code.rb in reek-1.2.12
- old
+ new
@@ -1,6 +1,5 @@
-require 'ruby_parser'
require File.join(File.dirname(File.expand_path(__FILE__)), 'config_file')
require File.join(File.dirname(File.expand_path(__FILE__)), 'tree_dresser')
module Reek
module Source
@@ -20,10 +19,22 @@
end
end
attr_reader :desc
- def initialize(code, desc, parser = RubyParser.new)
+ # At runtime, reek tries to load ripper_ruby_parser. If that succeeds,
+ # reek uses that parser and will be able to handle Ruby 1.9 syntax. On
+ # Ruby versions below 1.9.3, it will fail and reek will use ruby_parser
+ # and handle Ruby 1.8 syntax only.
+ PARSER_CLASS = begin
+ require 'ripper_ruby_parser'
+ RipperRubyParser::Parser
+ rescue LoadError
+ require 'ruby_parser'
+ RubyParser
+ end
+
+ def initialize(code, desc, parser = PARSER_CLASS.new)
@source = code
@desc = desc
@parser = parser
end