forked from troessner/reek
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4f33719
commit 46e5b18
Showing
6 changed files
with
40 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,45 @@ | ||
module Reek | ||
def can_parse_objects? | ||
begin | ||
require 'parse_tree' | ||
true | ||
rescue LoadError | ||
false | ||
class Source | ||
# | ||
# Factory method: creates a +Source+ from obj. | ||
# The code is not parsed until +report+ is called. | ||
# (This feature is only enabled if you have the ParseTree gem installed.) | ||
# | ||
def self.from_object(obj) | ||
return ObjectSource.new(obj, obj.to_s) | ||
end | ||
end | ||
module_function :can_parse_objects? | ||
end | ||
|
||
if Reek.can_parse_objects? | ||
module Reek | ||
class Source | ||
# | ||
# Factory method: creates a +Source+ from obj. | ||
# The code is not parsed until +report+ is called. | ||
# (This feature is only enabled if you have the ParseTree gem installed.) | ||
# | ||
def self.from_object(obj) | ||
return ObjectSource.new(obj, obj.to_s) | ||
class ObjectSource < Source # :nodoc: | ||
def can_parse_objects? | ||
return true if Object.const_defined?(:ParseTree) | ||
begin | ||
require 'parse_tree' | ||
true | ||
rescue LoadError | ||
false | ||
end | ||
end | ||
|
||
class ObjectSource < Source # :nodoc: | ||
def check(parser) # :nodoc: | ||
def check(parser) # :nodoc: | ||
if can_parse_objects? | ||
sexp = CodeParser.unify(ParseTree.new.parse_tree(@source)) | ||
parser.process(sexp) | ||
else | ||
throw ArgumentError.new('You must install the ParseTree gem to use this feature') | ||
end | ||
end | ||
end | ||
end | ||
|
||
class Object | ||
# | ||
# Constructs a Source representing this object; the source can then be used | ||
# to generate an abstract syntax tree for the object, which can in turn then | ||
# be examined for code smells. | ||
# (This feature is only enabled if you have the ParseTree gem installed.) | ||
# | ||
def to_source | ||
Reek::Source.from_object(self) | ||
end | ||
end | ||
else | ||
class Object | ||
def to_source | ||
throw ArgumentError.new('You must install the ParseTree gem to use this feature') | ||
end | ||
class Object | ||
# | ||
# Constructs a Source representing this object; the source can then be used | ||
# to generate an abstract syntax tree for the object, which can in turn then | ||
# be examined for code smells. | ||
# (This feature is only enabled if you have the ParseTree gem installed.) | ||
# | ||
def to_source | ||
Reek::Source.from_object(self) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters