Class: BetterHtml::TestHelper::RubyNode
  
  
  
  
  
    - Inherits:
 
    - 
      AST::Node
      
        
          - Object
 
          
            - AST::Node
 
          
            - AST::Node
 
          
            - BetterHtml::TestHelper::RubyNode
 
          
        
        show all
      
     
  
  
  
  
  
  
  
  
  
  
    - Defined in:
 
    - lib/better_html/test_helper/ruby_node.rb
 
  
  
 
Defined Under Namespace
  
    
  
    
      Classes: Builder, ParseError
    
  
  
    
      Constant Summary
      collapse
    
    
      
        - BLOCK_EXPR =
          
        
 
        /\s*((\s+|\))do|\{)(\s*\|[^|]*\|)?\s*\Z/ 
      
        - STATIC_TYPES =
          
        
 
        [:str, :int, :true, :false, :nil]
 
      
    
  
  Instance Attribute Summary
  
  Attributes inherited from AST::Node
  #loc
  
    
      Class Method Summary
      collapse
    
    
  
    
      Instance Method Summary
      collapse
    
    
  
  
  
  
  
  
  
  
  
  Methods inherited from AST::Node
  #descendants, #location
  
  
    Class Method Details
    
      
  
  
    .parse(code)  ⇒ Object 
  
  
  
  
    
      
16
17
18
19
20
21
22
23
24
25 
     | 
    
      # File 'lib/better_html/test_helper/ruby_node.rb', line 16
def self.parse(code)
  parser = ::Parser::CurrentRuby.new(Builder.new)
  parser.diagnostics.ignore_warnings = true
  parser.diagnostics.all_errors_are_fatal = false
  parser.diagnostics.consumer = nil
  buf = ::Parser::Source::Buffer.new('(string)')
  buf.source = code.sub(BLOCK_EXPR, '')
  parser.parse(buf)
end
     | 
  
 
    
   
  
    Instance Method Details
    
      
  
  
    #arguments  ⇒ Object 
  
  
  
  
    
      
90
91
92 
     | 
    
      # File 'lib/better_html/test_helper/ruby_node.rb', line 90
def arguments
  children[2..-1] if method_call?
end 
     | 
  
 
    
      
  
  
    #begin?  ⇒ Boolean 
  
  
  
  
    
      
82
83
84 
     | 
    
      # File 'lib/better_html/test_helper/ruby_node.rb', line 82
def begin?
  type?(:begin)
end 
     | 
  
 
    
      
  
  
    #child_nodes  ⇒ Object 
  
  
  
  
    
      
27
28
29 
     | 
    
      # File 'lib/better_html/test_helper/ruby_node.rb', line 27
def child_nodes
  children.select { |child| node?(child) }
end
     | 
  
 
    
      
  
  
    #hash?  ⇒ Boolean 
  
  
  
  
    
      
74
75
76 
     | 
    
      # File 'lib/better_html/test_helper/ruby_node.rb', line 74
def hash?
  type?(:hash)
end 
     | 
  
 
    
      
  
  
    #method_call?  ⇒ Boolean 
  
  
  
  
    
      
70
71
72 
     | 
    
      # File 'lib/better_html/test_helper/ruby_node.rb', line 70
def method_call?
  [:send, :csend].include?(type)
end 
     | 
  
 
    
      
  
  
    #method_name  ⇒ Object 
  
  
  
  
    
      
86
87
88 
     | 
    
      # File 'lib/better_html/test_helper/ruby_node.rb', line 86
def method_name
  children[1] if method_call?
end 
     | 
  
 
    
      
  
  
    #method_name?(name)  ⇒ Boolean 
  
  
  
  
    
      
98
99
100 
     | 
    
      # File 'lib/better_html/test_helper/ruby_node.rb', line 98
def method_name?(name)
  method_call? && method_name == name
end 
     | 
  
 
    
      
  
  
    #node?(current)  ⇒ Boolean 
  
  
  
  
    
      
31
32
33 
     | 
    
      # File 'lib/better_html/test_helper/ruby_node.rb', line 31
def node?(current)
  current.is_a?(self.class)
end 
     | 
  
 
    
      
  
  
    #pair?  ⇒ Boolean 
  
  
  
  
    
      
78
79
80 
     | 
    
      # File 'lib/better_html/test_helper/ruby_node.rb', line 78
def pair?
  type?(:pair)
end 
     | 
  
 
    
      
  
  
    #receiver  ⇒ Object 
  
  
  
  
    
      
94
95
96 
     | 
    
      # File 'lib/better_html/test_helper/ruby_node.rb', line 94
def receiver
  children[0] if method_call?
end 
     | 
  
 
    
      
  
  
    #return_values  ⇒ Object 
  
  
  
  
    
      
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63 
     | 
    
      # File 'lib/better_html/test_helper/ruby_node.rb', line 46
def return_values
  Enumerator.new do |yielder|
    case type
    when :send, :csend, :ivar, *STATIC_TYPES
      yielder.yield(self)
    when :if, :masgn, :lvasgn
                  children[1..-1].each do |child|
        child.return_values.each { |v| yielder.yield(v) } if node?(child)
      end
    else
      child_nodes.each do |child|
        child.return_values.each { |v| yielder.yield(v) }
      end
    end
  end
end
     | 
  
 
    
      
  
  
    #static_return_value?  ⇒ Boolean 
  
  
  
  
    
      
65
66
67
68 
     | 
    
      # File 'lib/better_html/test_helper/ruby_node.rb', line 65
def static_return_value?
  return false if (possible_values = return_values.to_a).empty?
  possible_values.all?(&:static_value?)
end 
     | 
  
 
    
      
  
  
    #static_value?  ⇒ Boolean 
  
  
  
  
    
      
41
42
43
44 
     | 
    
      # File 'lib/better_html/test_helper/ruby_node.rb', line 41
def static_value?
  type?(STATIC_TYPES) ||
    (type?(:dstr) && !children.any? { |child| !child.type?(:str) })
end
     | 
  
 
    
      
  
  
    #type?(wanted_type)  ⇒ Boolean 
  
  
  
  
    
      
35
36
37 
     | 
    
      # File 'lib/better_html/test_helper/ruby_node.rb', line 35
def type?(wanted_type)
  Array.wrap(wanted_type).include?(type)
end 
     |