Class: ActionviewPrecompiler::Ruby26ASTParser::Node
- Inherits:
-
Object
- Object
- ActionviewPrecompiler::Ruby26ASTParser::Node
- Defined in:
- lib/actionview_precompiler/ast_parser/ruby26.rb
Class Method Summary collapse
Instance Method Summary collapse
- #argument_nodes ⇒ Object
- #array? ⇒ Boolean
- #block_pass? ⇒ Boolean
- #call? ⇒ Boolean
- #call_method_name ⇒ Object
- #children ⇒ Object
- #fcall? ⇒ Boolean
- #fcall_named?(name) ⇒ Boolean
- #hash? ⇒ Boolean
-
#initialize(node) ⇒ Node
constructor
A new instance of Node.
- #inspect ⇒ Object
- #string? ⇒ Boolean
- #symbol? ⇒ Boolean
- #to_hash ⇒ Object
- #to_string ⇒ Object
- #to_symbol ⇒ Object
- #variable_name ⇒ Object
- #variable_reference? ⇒ Boolean
- #vcall? ⇒ Boolean
Constructor Details
#initialize(node) ⇒ Node
Returns a new instance of Node.
12 13 14 |
# File 'lib/actionview_precompiler/ast_parser/ruby26.rb', line 12 def initialize(node) @node = node end |
Class Method Details
.wrap(node) ⇒ Object
4 5 6 7 8 9 10 |
# File 'lib/actionview_precompiler/ast_parser/ruby26.rb', line 4 def self.wrap(node) if RubyVM::AbstractSyntaxTree::Node === node new(node) else node end end |
Instance Method Details
#argument_nodes ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/actionview_precompiler/ast_parser/ruby26.rb', line 26 def argument_nodes if children[1].array? children[1].children[0...-1] elsif children[1].block_pass? children[1].children[0].children[0...-1] else raise "can't call argument_nodes on #{inspect}" end end |
#array? ⇒ Boolean
36 37 38 |
# File 'lib/actionview_precompiler/ast_parser/ruby26.rb', line 36 def array? type == :ARRAY || type == :LIST end |
#block_pass? ⇒ Boolean
48 49 50 |
# File 'lib/actionview_precompiler/ast_parser/ruby26.rb', line 48 def block_pass? type == :BLOCK_PASS end |
#call? ⇒ Boolean
68 69 70 |
# File 'lib/actionview_precompiler/ast_parser/ruby26.rb', line 68 def call? type == :CALL end |
#call_method_name ⇒ Object
72 73 74 |
# File 'lib/actionview_precompiler/ast_parser/ruby26.rb', line 72 def call_method_name children[1].to_s end |
#children ⇒ Object
16 17 18 19 20 |
# File 'lib/actionview_precompiler/ast_parser/ruby26.rb', line 16 def children @children ||= @node.children.map do |child| self.class.wrap(child) end end |
#fcall? ⇒ Boolean
40 41 42 |
# File 'lib/actionview_precompiler/ast_parser/ruby26.rb', line 40 def fcall? type == :FCALL end |
#fcall_named?(name) ⇒ Boolean
99 100 101 102 103 104 |
# File 'lib/actionview_precompiler/ast_parser/ruby26.rb', line 99 def fcall_named?(name) fcall? && children[0] == name && children[1] && (children[1].array? || (children[1].block_pass? && children[1].children[0].array?)) end |
#hash? ⇒ Boolean
44 45 46 |
# File 'lib/actionview_precompiler/ast_parser/ruby26.rb', line 44 def hash? type == :HASH end |
#inspect ⇒ Object
22 23 24 |
# File 'lib/actionview_precompiler/ast_parser/ruby26.rb', line 22 def inspect "#<#{self.class} #{@node.inspect}>" end |
#string? ⇒ Boolean
52 53 54 |
# File 'lib/actionview_precompiler/ast_parser/ruby26.rb', line 52 def string? type == :STR && String === children[0] end |
#symbol? ⇒ Boolean
76 77 78 |
# File 'lib/actionview_precompiler/ast_parser/ruby26.rb', line 76 def symbol? (type == :SYM) || (type == :LIT && Symbol === children[0]) end |
#to_hash ⇒ Object
80 81 82 83 84 85 86 87 88 89 |
# File 'lib/actionview_precompiler/ast_parser/ruby26.rb', line 80 def to_hash list = children[0] if list.nil? {} else hash = list.children[0..-2].each_slice(2).to_h return nil if hash.key?(nil) hash end end |
#to_string ⇒ Object
91 92 93 |
# File 'lib/actionview_precompiler/ast_parser/ruby26.rb', line 91 def to_string children[0] end |
#to_symbol ⇒ Object
95 96 97 |
# File 'lib/actionview_precompiler/ast_parser/ruby26.rb', line 95 def to_symbol children[0] end |
#variable_name ⇒ Object
60 61 62 |
# File 'lib/actionview_precompiler/ast_parser/ruby26.rb', line 60 def variable_name children[0].to_s end |
#variable_reference? ⇒ Boolean
56 57 58 |
# File 'lib/actionview_precompiler/ast_parser/ruby26.rb', line 56 def variable_reference? type == :IVAR || type == :GVAR || type == :CVAR end |
#vcall? ⇒ Boolean
64 65 66 |
# File 'lib/actionview_precompiler/ast_parser/ruby26.rb', line 64 def vcall? type == :VCALL end |