Class: Synvert::Rewriter::Instance
- Inherits:
-
Object
- Object
- Synvert::Rewriter::Instance
- Defined in:
- lib/synvert/rewriter/instances.rb
Instance Method Summary collapse
-
#initialize(file_pattern) ⇒ Instance
constructor
A new instance of Instance.
- #insert(code) ⇒ Object
- #process ⇒ Object
- #replace_with(code) ⇒ Object
- #unless_exist_node(options, &block) ⇒ Object
- #within_node(options, &block) ⇒ Object (also: #with_node)
Constructor Details
Instance Method Details
#insert(code) ⇒ Object
59 60 61 |
# File 'lib/synvert/rewriter/instances.rb', line 59 def insert(code) @action = Rewriter::InsertAction.new(code) end |
#process ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/synvert/rewriter/instances.rb', line 27 def process parser = Parser::CurrentRuby.new file_pattern = File.join(Configuration.instance.get(:path), @file_pattern) Dir.glob(file_pattern).each do |path| source = File.read(path) buffer = Parser::Source::Buffer.new path buffer.source = source parser.reset ast = parser.parse buffer scoped_nodes = @scopes.matching_nodes(ast) matching_nodes = @conditions.matching_nodes(scoped_nodes) matching_nodes.reverse.each do |node| source = @action.rewrite(source, node) end File.write path, source end end |
#replace_with(code) ⇒ Object
63 64 65 |
# File 'lib/synvert/rewriter/instances.rb', line 63 def replace_with(code) @action = Rewriter::ReplaceWithAction.new(code) end |
#unless_exist_node(options, &block) ⇒ Object
54 55 56 57 |
# File 'lib/synvert/rewriter/instances.rb', line 54 def unless_exist_node(, &block) @conditions.add(Rewriter::UnlessExistCondition.new()) instance_eval &block if block_given? end |
#within_node(options, &block) ⇒ Object Also known as: with_node
47 48 49 50 |
# File 'lib/synvert/rewriter/instances.rb', line 47 def within_node(, &block) @scopes.add() instance_eval &block if block_given? end |