Class: Outil::OCS::ObjectParser
- Inherits:
-
Object
- Object
- Outil::OCS::ObjectParser
- Defined in:
- lib/outil/ocs/parser.rb
Instance Attribute Summary collapse
-
#found ⇒ Object
readonly
Returns the value of attribute found.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #find ⇒ Object
-
#initialize(path, name) ⇒ ObjectParser
constructor
A new instance of ObjectParser.
- #node ⇒ Object
Constructor Details
#initialize(path, name) ⇒ ObjectParser
Returns a new instance of ObjectParser.
7 8 9 10 11 |
# File 'lib/outil/ocs/parser.rb', line 7 def initialize(path, name) @path = path @name = name @found = false end |
Instance Attribute Details
#found ⇒ Object (readonly)
Returns the value of attribute found.
5 6 7 |
# File 'lib/outil/ocs/parser.rb', line 5 def found @found end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/outil/ocs/parser.rb', line 5 def name @name end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
5 6 7 |
# File 'lib/outil/ocs/parser.rb', line 5 def path @path end |
Instance Method Details
#find ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/outil/ocs/parser.rb', line 21 def find return @found if @found set_and_stop = Proc.new do |node| return @found = node end traverse = Proc.new do |node| # if we're not at a node, we can move on next unless node.is_a?(Parser::AST::Node) # unless we're at a method definition # we're probably in a begin block, a class, or module # in which case traverse the children of the current node node.children.each &traverse unless [:defs, :def].include?(node.type) # bottom-level node interrogation... case node.type when :defs # class methods set_and_stop.call(node) if node.children[1] == name next when :def # instance method set_and_stop.call(node) if node.children.first == name next else # other kind of object if node.is_a?(Parser::AST::Node) # another parent node node.children.each &traverse else # the bottom of a node next end end end begin traverse.call(node) rescue false end end |
#node ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/outil/ocs/parser.rb', line 13 def node @node ||= Parser::CurrentRuby.parse( File.open(@path, 'r') do |f| f.read end ) end |