lib/reek/source/source_code.rb in reek-2.0.4 vs lib/reek/source/source_code.rb in reek-2.1.0

- old
+ new

@@ -1,10 +1,10 @@ old_verbose, $VERBOSE = $VERBOSE, nil require 'parser/current' $VERBOSE = old_verbose -require 'reek/source/tree_dresser' -require 'reek/source/ast_node' +require_relative 'tree_dresser' +require_relative 'ast_node' module Reek module Source # # A +Source+ object represents a chunk of Ruby source code. @@ -14,9 +14,17 @@ def initialize(code, desc, parser = Parser::Ruby21) @source = code @desc = desc @parser = parser + end + + def self.from(source) + case source + when File then new(source.read, source.path) + when IO then new(source.readlines.join, 'STDIN') + when String then new(source, 'string') + end end def syntax_tree @syntax_tree ||= begin