Class: ActionviewPrecompiler::RipperASTParser::Node
- Inherits:
-
Array
- Object
- Array
- ActionviewPrecompiler::RipperASTParser::Node
- Defined in:
- lib/actionview_precompiler/ast_parser/ripper.rb
Instance Attribute Summary collapse
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #argument_nodes ⇒ Object
- #call? ⇒ Boolean
- #call_method_name ⇒ Object
- #children ⇒ Object
- #fcall? ⇒ Boolean
- #fcall_named?(name) ⇒ Boolean
- #hash? ⇒ Boolean
- #hash_from_body(body) ⇒ Object
-
#initialize(type, arr, opts = {}) ⇒ 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(type, arr, opts = {}) ⇒ Node
Returns a new instance of Node.
10 11 12 13 |
# File 'lib/actionview_precompiler/ast_parser/ripper.rb', line 10 def initialize(type, arr, opts = {}) @type = type super(arr) end |
Instance Attribute Details
#type ⇒ Object (readonly)
Returns the value of attribute type.
8 9 10 |
# File 'lib/actionview_precompiler/ast_parser/ripper.rb', line 8 def type @type end |
Instance Method Details
#argument_nodes ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/actionview_precompiler/ast_parser/ripper.rb', line 34 def argument_nodes raise unless fcall? return [] if self[1].nil? if self[1].last == false || self[1].last.type == :vcall self[1][0...-1] else self[1][0..-1] end end |
#call? ⇒ Boolean
56 57 58 |
# File 'lib/actionview_precompiler/ast_parser/ripper.rb', line 56 def call? type == :call end |
#call_method_name ⇒ Object
64 65 66 |
# File 'lib/actionview_precompiler/ast_parser/ripper.rb', line 64 def call_method_name self.last.first end |
#children ⇒ Object
15 16 17 |
# File 'lib/actionview_precompiler/ast_parser/ripper.rb', line 15 def children to_a end |
#fcall? ⇒ Boolean
24 25 26 |
# File 'lib/actionview_precompiler/ast_parser/ripper.rb', line 24 def fcall? type == :command || type == :fcall end |
#fcall_named?(name) ⇒ Boolean
28 29 30 31 32 |
# File 'lib/actionview_precompiler/ast_parser/ripper.rb', line 28 def fcall_named?(name) fcall? && self[0].type == :@ident && self[0][0] == name end |
#hash? ⇒ Boolean
75 76 77 |
# File 'lib/actionview_precompiler/ast_parser/ripper.rb', line 75 def hash? type == :bare_assoc_hash || type == :hash end |
#hash_from_body(body) ⇒ Object
91 92 93 94 95 96 97 |
# File 'lib/actionview_precompiler/ast_parser/ripper.rb', line 91 def hash_from_body(body) body.map do |hash_node| return nil if hash_node.type != :assoc_new [hash_node[0], hash_node[1]] end.to_h end |
#inspect ⇒ Object
19 20 21 22 |
# File 'lib/actionview_precompiler/ast_parser/ripper.rb', line 19 def inspect typeinfo = type && type != :list ? ':' + type.to_s + ', ' : '' 's(' + typeinfo + map(&:inspect).join(", ") + ')' end |
#string? ⇒ Boolean
44 45 46 |
# File 'lib/actionview_precompiler/ast_parser/ripper.rb', line 44 def string? type == :string_literal end |
#symbol? ⇒ Boolean
99 100 101 |
# File 'lib/actionview_precompiler/ast_parser/ripper.rb', line 99 def symbol? type == :@label || type == :symbol_literal end |
#to_hash ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/actionview_precompiler/ast_parser/ripper.rb', line 79 def to_hash if type == :bare_assoc_hash hash_from_body(self[0]) elsif type == :hash && self[0] == nil {} elsif type == :hash && self[0].type == :assoclist_from_args hash_from_body(self[0][0]) else raise "not a hash? #{inspect}" end end |
#to_string ⇒ Object
68 69 70 71 72 73 |
# File 'lib/actionview_precompiler/ast_parser/ripper.rb', line 68 def to_string raise unless string? raise "fixme" unless self[0].type == :string_content raise "fixme" unless self[0][0].type == :@tstring_content self[0][0][0] end |
#to_symbol ⇒ Object
103 104 105 106 107 108 109 110 111 |
# File 'lib/actionview_precompiler/ast_parser/ripper.rb', line 103 def to_symbol if type == :@label && self[0] =~ /\A(.+):\z/ $1.to_sym elsif type == :symbol_literal && self[0].type == :symbol && self[0][0].type == :@ident self[0][0][0].to_sym else raise "not a symbol?: #{self.inspect}" end end |
#variable_name ⇒ Object
60 61 62 |
# File 'lib/actionview_precompiler/ast_parser/ripper.rb', line 60 def variable_name self[0][0] end |
#variable_reference? ⇒ Boolean
48 49 50 |
# File 'lib/actionview_precompiler/ast_parser/ripper.rb', line 48 def variable_reference? type == :var_ref end |
#vcall? ⇒ Boolean
52 53 54 |
# File 'lib/actionview_precompiler/ast_parser/ripper.rb', line 52 def vcall? type == :vcall end |