forked from andreyvit/xdry
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Item patchers refactoring: merge execution paths by parsing inserted …
…lines
- Loading branch information
Showing
10 changed files
with
217 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
|
||
module XDry | ||
|
||
class InsertionPoint | ||
|
||
attr_reader :method, :node | ||
|
||
def initialize | ||
find! | ||
end | ||
|
||
def insert patcher, lines | ||
raise StandardError, "#{self.class.name} has not been found but trying to insert" unless found? | ||
patcher.send(@method, @node.pos, lines) | ||
end | ||
|
||
def found? | ||
not @method.nil? | ||
end | ||
|
||
protected | ||
|
||
def before node | ||
@method = :insert_before | ||
@node = node | ||
end | ||
|
||
def after node | ||
@method = :insert_after | ||
@node = node | ||
end | ||
|
||
def try insertion_point | ||
if insertion_point.found? | ||
@method, @node = insertion_point.method, insertion_point.node | ||
true | ||
else | ||
false | ||
end | ||
end | ||
|
||
def find! | ||
end | ||
|
||
end | ||
|
||
class ImplementationStartIP < InsertionPoint | ||
|
||
def initialize oclass | ||
@oclass = oclass | ||
super() | ||
end | ||
|
||
def find! | ||
after @oclass.main_implementation.start_node | ||
end | ||
|
||
end | ||
|
||
class MultiIP < InsertionPoint | ||
|
||
def initialize *insertion_points | ||
@insertion_points = insertion_points | ||
end | ||
|
||
def find! | ||
@insertion_points.detect { |ip| try ip } | ||
end | ||
|
||
end | ||
|
||
end |
Oops, something went wrong.