Class: ActionView::RenderParser::RipperRenderParser::Node
- Inherits:
-
Array
- Object
- Array
- ActionView::RenderParser::RipperRenderParser::Node
- Defined in:
- lib/action_view/render_parser/ripper_render_parser.rb
Overview
:nodoc:
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.
9 10 11 12 |
# File 'lib/action_view/render_parser/ripper_render_parser.rb', line 9 def initialize(type, arr, opts = {}) @type = type super(arr) end |
Instance Attribute Details
#type ⇒ Object (readonly)
Returns the value of attribute type.
7 8 9 |
# File 'lib/action_view/render_parser/ripper_render_parser.rb', line 7 def type @type end |
Instance Method Details
#argument_nodes ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'lib/action_view/render_parser/ripper_render_parser.rb', line 33 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
55 56 57 |
# File 'lib/action_view/render_parser/ripper_render_parser.rb', line 55 def call? type == :call end |
#call_method_name ⇒ Object
63 64 65 |
# File 'lib/action_view/render_parser/ripper_render_parser.rb', line 63 def call_method_name self[2].first end |
#children ⇒ Object
14 15 16 |
# File 'lib/action_view/render_parser/ripper_render_parser.rb', line 14 def children to_a end |
#fcall? ⇒ Boolean
23 24 25 |
# File 'lib/action_view/render_parser/ripper_render_parser.rb', line 23 def fcall? type == :command || type == :fcall end |
#fcall_named?(name) ⇒ Boolean
27 28 29 30 31 |
# File 'lib/action_view/render_parser/ripper_render_parser.rb', line 27 def fcall_named?(name) fcall? && self[0].type == :@ident && self[0][0] == name end |
#hash? ⇒ Boolean
81 82 83 |
# File 'lib/action_view/render_parser/ripper_render_parser.rb', line 81 def hash? type == :bare_assoc_hash || type == :hash end |
#hash_from_body(body) ⇒ Object
95 96 97 98 99 100 101 |
# File 'lib/action_view/render_parser/ripper_render_parser.rb', line 95 def hash_from_body(body) body.to_h do |hash_node| return nil if hash_node.type != :assoc_new [hash_node[0], hash_node[1]] end end |
#inspect ⇒ Object
18 19 20 21 |
# File 'lib/action_view/render_parser/ripper_render_parser.rb', line 18 def inspect typeinfo = type && type != :list ? ":" + type.to_s + ", " : "" "s(" + typeinfo + map(&:inspect).join(", ") + ")" end |
#string? ⇒ Boolean
43 44 45 |
# File 'lib/action_view/render_parser/ripper_render_parser.rb', line 43 def string? type == :string_literal end |
#symbol? ⇒ Boolean
103 104 105 |
# File 'lib/action_view/render_parser/ripper_render_parser.rb', line 103 def symbol? type == :@label || type == :symbol_literal end |
#to_hash ⇒ Object
85 86 87 88 89 90 91 92 93 |
# File 'lib/action_view/render_parser/ripper_render_parser.rb', line 85 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]) end end |
#to_string ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/action_view/render_parser/ripper_render_parser.rb', line 67 def to_string raise unless string? # s(:string_literal, s(:string_content, map)) self[0].map do |node| case node.type when :@tstring_content node[0] when :string_embexpr "*" end end.join("") end |
#to_symbol ⇒ Object
107 108 109 110 111 112 113 114 115 |
# File 'lib/action_view/render_parser/ripper_render_parser.rb', line 107 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
59 60 61 |
# File 'lib/action_view/render_parser/ripper_render_parser.rb', line 59 def variable_name self[0][0] end |
#variable_reference? ⇒ Boolean
47 48 49 |
# File 'lib/action_view/render_parser/ripper_render_parser.rb', line 47 def variable_reference? type == :var_ref end |
#vcall? ⇒ Boolean
51 52 53 |
# File 'lib/action_view/render_parser/ripper_render_parser.rb', line 51 def vcall? type == :vcall end |