Class: Rebundler::Visitor
- Inherits:
-
Prism::Visitor
- Object
- Prism::Visitor
- Rebundler::Visitor
- Defined in:
- lib/rebundler/visitor.rb
Instance Method Summary collapse
-
#initialize(parser) ⇒ Visitor
constructor
A new instance of Visitor.
- #visit_call_node(node) ⇒ Object
Constructor Details
#initialize(parser) ⇒ Visitor
Returns a new instance of Visitor.
5 6 7 8 9 |
# File 'lib/rebundler/visitor.rb', line 5 def initialize(parser) super() @parser = parser @current_set = @parser.gem_sets.find(&:default) end |
Instance Method Details
#visit_call_node(node) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/rebundler/visitor.rb', line 11 def visit_call_node(node) case node.name when :plugin @current_set.plugins << GemDeclaration.new(node:) when :gem @current_set.gems << GemDeclaration.new(node:) when :git_source # :git_source is a special case where it's a directive with a block that # we don't want to add it as a set, which would happen if it's parsed in # the condition for DIRECTIVE_AND_BLOCK_NODES below. @parser.directives << node when *DIRECTIVE_AND_BLOCK_NODES if node.block return unless node.block.body # Use the full block declaration (e.g., "group :development do") as the unique name name = node.location.slice.lines.first.strip previous_set = @current_set @current_set = find_or_build_set(name:, node:) node.block.body.accept(self) @current_set = previous_set else @parser.directives << node end end end |