Module: ActionviewPrecompiler::Ruby26ASTParser
- Extended by:
- Ruby26ASTParser
- Included in:
- Ruby26ASTParser
- Defined in:
- lib/actionview_precompiler/ast_parser/ruby26.rb
Defined Under Namespace
Classes: Node
Constant Summary collapse
- METHODS_TO_PARSE =
%i(render render_to_string layout)
Instance Method Summary collapse
- #extract_render_nodes(root) ⇒ Object
- #fcall?(node, name) ⇒ Boolean
- #node?(node) ⇒ Boolean
- #parse(code) ⇒ Object
- #parse_render_nodes(code) ⇒ Object
- #render_call?(node) ⇒ Boolean
Instance Method Details
#extract_render_nodes(root) ⇒ Object
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/actionview_precompiler/ast_parser/ruby26.rb', line 137 def extract_render_nodes(root) renders = [] queue = [root] while node = queue.shift node.children.each do |child| queue << child if node?(child) end method_name = render_call?(node) renders << [method_name, node] if method_name end renders end |
#fcall?(node, name) ⇒ Boolean
133 134 135 |
# File 'lib/actionview_precompiler/ast_parser/ruby26.rb', line 133 def fcall?(node, name) node.fcall_named?(name) end |
#node?(node) ⇒ Boolean
129 130 131 |
# File 'lib/actionview_precompiler/ast_parser/ruby26.rb', line 129 def node?(node) Node === node end |
#parse(code) ⇒ Object
125 126 127 |
# File 'lib/actionview_precompiler/ast_parser/ruby26.rb', line 125 def parse(code) Node.wrap(RubyVM::AbstractSyntaxTree.parse(code)) end |
#parse_render_nodes(code) ⇒ Object
117 118 119 120 121 122 123 |
# File 'lib/actionview_precompiler/ast_parser/ruby26.rb', line 117 def parse_render_nodes(code) renders = extract_render_nodes(parse(code)) renders.group_by(&:first).collect do |method, nodes| [ method, nodes.collect { |v| v[1] } ] end.to_h end |
#render_call?(node) ⇒ Boolean
153 154 155 |
# File 'lib/actionview_precompiler/ast_parser/ruby26.rb', line 153 def render_call?(node) METHODS_TO_PARSE.detect { |m| fcall?(node, m) } end |