Class: ActionviewPrecompiler::Ruby26ASTParser::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/actionview_precompiler/ast_parser/ruby26.rb

Class Method Summary collapse

Instance Method Summary collapse

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_nodesObject



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

Returns:

  • (Boolean)


36
37
38
# File 'lib/actionview_precompiler/ast_parser/ruby26.rb', line 36

def array?
  type == :ARRAY || type == :LIST
end

#block_pass?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/actionview_precompiler/ast_parser/ruby26.rb', line 48

def block_pass?
  type == :BLOCK_PASS
end

#call?Boolean

Returns:

  • (Boolean)


68
69
70
# File 'lib/actionview_precompiler/ast_parser/ruby26.rb', line 68

def call?
  type == :CALL
end

#call_method_nameObject



72
73
74
# File 'lib/actionview_precompiler/ast_parser/ruby26.rb', line 72

def call_method_name
  children[1].to_s
end

#childrenObject



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

Returns:

  • (Boolean)


40
41
42
# File 'lib/actionview_precompiler/ast_parser/ruby26.rb', line 40

def fcall?
  type == :FCALL
end

#fcall_named?(name) ⇒ Boolean

Returns:

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

Returns:

  • (Boolean)


44
45
46
# File 'lib/actionview_precompiler/ast_parser/ruby26.rb', line 44

def hash?
  type == :HASH
end

#inspectObject



22
23
24
# File 'lib/actionview_precompiler/ast_parser/ruby26.rb', line 22

def inspect
  "#<#{self.class} #{@node.inspect}>"
end

#string?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/actionview_precompiler/ast_parser/ruby26.rb', line 52

def string?
  type == :STR && String === children[0]
end

#symbol?Boolean

Returns:

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



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_stringObject



91
92
93
# File 'lib/actionview_precompiler/ast_parser/ruby26.rb', line 91

def to_string
  children[0]
end

#to_symbolObject



95
96
97
# File 'lib/actionview_precompiler/ast_parser/ruby26.rb', line 95

def to_symbol
  children[0]
end

#variable_nameObject



60
61
62
# File 'lib/actionview_precompiler/ast_parser/ruby26.rb', line 60

def variable_name
  children[0].to_s
end

#variable_reference?Boolean

Returns:

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

Returns:

  • (Boolean)


64
65
66
# File 'lib/actionview_precompiler/ast_parser/ruby26.rb', line 64

def vcall?
  type == :VCALL
end