Class: Astel::Rewriter::EditIndex
- Inherits:
-
Object
- Object
- Astel::Rewriter::EditIndex
- Includes:
- Enumerable
- Defined in:
- lib/astel/rewriter/edit_index.rb
Constant Summary collapse
- SPLIT_THRESHOLD =
256
Instance Method Summary collapse
- #add(edit) ⇒ Object
- #each ⇒ Object
- #find_conflict(edit) ⇒ Object
-
#initialize ⇒ EditIndex
constructor
A new instance of EditIndex.
Constructor Details
#initialize ⇒ EditIndex
Returns a new instance of EditIndex.
10 11 12 |
# File 'lib/astel/rewriter/edit_index.rb', line 10 def initialize @blocks = [] end |
Instance Method Details
#add(edit) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/astel/rewriter/edit_index.rb', line 14 def add(edit) if @blocks.empty? @blocks << [edit] return end block_index, block, edit_index = insertion_position(edit) conflict = conflict_at(block_index, block, edit_index) { |existing| yield existing } return conflict if conflict block.insert(edit_index, edit) split(block_index, block) if block.length > SPLIT_THRESHOLD nil end |
#each ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/astel/rewriter/edit_index.rb', line 36 def each return enum_for(__method__) unless block_given? @blocks.each do |block| block.each { |edit| yield edit } end end |
#find_conflict(edit) ⇒ Object
29 30 31 32 33 34 |
# File 'lib/astel/rewriter/edit_index.rb', line 29 def find_conflict(edit) return if @blocks.empty? block_index, block, edit_index = insertion_position(edit) conflict_at(block_index, block, edit_index) { |existing| yield existing } end |