Class: ActionviewPrecompiler::JRubyASTParser::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/actionview_precompiler/ast_parser/jruby.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/jruby.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/jruby.rb', line 4

def self.wrap(node)
  if org::jruby::ast::Node === node
    new(node)
  else
    node
  end
end

Instance Method Details

#argument_nodesObject



50
51
52
53
54
# File 'lib/actionview_precompiler/ast_parser/jruby.rb', line 50

def argument_nodes
  @node.args_node.children.to_a[0...@node.args_node.size].map do |arg|
    self.class.wrap(arg)
  end
end

#array?Boolean

Returns:

  • (Boolean)


22
# File 'lib/actionview_precompiler/ast_parser/jruby.rb', line 22

def array?;  org::jruby::ast::ArrayNode  === @node; end

#call?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/actionview_precompiler/ast_parser/jruby.rb', line 38

def call?
  org::jruby::ast::CallNode === @node;
end

#call_method_nameObject



46
47
48
# File 'lib/actionview_precompiler/ast_parser/jruby.rb', line 46

def call_method_name
  self.last.first
end

#childrenObject



16
17
18
19
20
# File 'lib/actionview_precompiler/ast_parser/jruby.rb', line 16

def children
  @children ||= @node.child_nodes.map do |child|
    self.class.wrap(child)
  end
end

#fcall?Boolean

Returns:

  • (Boolean)


23
# File 'lib/actionview_precompiler/ast_parser/jruby.rb', line 23

def fcall?;  org::jruby::ast::FCallNode  === @node; end

#fcall_named?(name) ⇒ Boolean

Returns:

  • (Boolean)


79
80
81
82
83
84
# File 'lib/actionview_precompiler/ast_parser/jruby.rb', line 79

def fcall_named?(name)
  fcall? &&
    @node.name == name &&
    @node.args_node &&
    org::jruby::ast::ArrayNode === @node.args_node
end

#hash?Boolean

Returns:

  • (Boolean)


24
# File 'lib/actionview_precompiler/ast_parser/jruby.rb', line 24

def hash?;   org::jruby::ast::HashNode   === @node; end

#string?Boolean

Returns:

  • (Boolean)


25
# File 'lib/actionview_precompiler/ast_parser/jruby.rb', line 25

def string?; org::jruby::ast::StrNode    === @node; end

#symbol?Boolean

Returns:

  • (Boolean)


26
# File 'lib/actionview_precompiler/ast_parser/jruby.rb', line 26

def symbol?; org::jruby::ast::SymbolNode === @node; end

#to_hashObject



56
57
58
59
60
61
# File 'lib/actionview_precompiler/ast_parser/jruby.rb', line 56

def to_hash
  @node.pairs.each_with_object({}) do |pair, object|
    return nil if pair.key == nil
    object[self.class.wrap(pair.key)] = self.class.wrap(pair.value)
  end
end

#to_stringObject



63
64
65
# File 'lib/actionview_precompiler/ast_parser/jruby.rb', line 63

def to_string
  @node.value
end

#to_symbolObject



75
76
77
# File 'lib/actionview_precompiler/ast_parser/jruby.rb', line 75

def to_symbol
  @node.name
end

#variable_nameObject



42
43
44
# File 'lib/actionview_precompiler/ast_parser/jruby.rb', line 42

def variable_name
  self[0][0]
end

#variable_reference?Boolean

Returns:

  • (Boolean)


28
29
30
31
32
# File 'lib/actionview_precompiler/ast_parser/jruby.rb', line 28

def variable_reference?
  org::jruby::ast::InstVarNode === @node ||
    org::jruby::ast::GlobalVarNode === @node ||
    org::jruby::ast::ClassVarNode === @node
end

#vcall?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/actionview_precompiler/ast_parser/jruby.rb', line 34

def vcall?
  org::jruby::ast::VCallNode === @node;
end