Class: ActionView::RenderParser::RipperRenderParser::Node

Inherits:
Array
  • Object
show all
Defined in:
lib/action_view/render_parser/ripper_render_parser.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#typeObject (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_nodesObject



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

Returns:

  • (Boolean)


55
56
57
# File 'lib/action_view/render_parser/ripper_render_parser.rb', line 55

def call?
  type == :call
end

#call_method_nameObject



63
64
65
# File 'lib/action_view/render_parser/ripper_render_parser.rb', line 63

def call_method_name
  self[2].first
end

#childrenObject



14
15
16
# File 'lib/action_view/render_parser/ripper_render_parser.rb', line 14

def children
  to_a
end

#fcall?Boolean

Returns:

  • (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

Returns:

  • (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

Returns:

  • (Boolean)


72
73
74
# File 'lib/action_view/render_parser/ripper_render_parser.rb', line 72

def hash?
  type == :bare_assoc_hash || type == :hash
end

#hash_from_body(body) ⇒ Object



86
87
88
89
90
91
92
# File 'lib/action_view/render_parser/ripper_render_parser.rb', line 86

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

#inspectObject



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

Returns:

  • (Boolean)


43
44
45
# File 'lib/action_view/render_parser/ripper_render_parser.rb', line 43

def string?
  type == :string_literal
end

#symbol?Boolean

Returns:

  • (Boolean)


94
95
96
# File 'lib/action_view/render_parser/ripper_render_parser.rb', line 94

def symbol?
  type == :@label || type == :symbol_literal
end

#to_hashObject



76
77
78
79
80
81
82
83
84
# File 'lib/action_view/render_parser/ripper_render_parser.rb', line 76

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_stringObject



67
68
69
70
# File 'lib/action_view/render_parser/ripper_render_parser.rb', line 67

def to_string
  raise unless string?
  self[0][0][0]
end

#to_symbolObject



98
99
100
101
102
103
104
105
106
# File 'lib/action_view/render_parser/ripper_render_parser.rb', line 98

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_nameObject



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

Returns:

  • (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

Returns:

  • (Boolean)


51
52
53
# File 'lib/action_view/render_parser/ripper_render_parser.rb', line 51

def vcall?
  type == :vcall
end