Module: Ritsu::TemplatePolicies::StrictBlockMatchingButLeaveUserTextBe

Included in:
SrcFiles::ProjectCmakeLists::Template
Defined in:
lib/ritsu/template_policies.rb

Instance Method Summary collapse

Instance Method Details

#update_block(block, options = {}) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/ritsu/template_policies.rb', line 5

def update_block(block, options={})
  child_blocks = block.child_blocks
  index = 0
  child_templates.each do |child_template|
    while index < child_blocks.length && child_blocks[index].id != child_template.id
      index += 1
    end
    if index >= child_blocks.length
      if child_blocks.select {|x| x.id == child_template.id}
        raise ArgumentError.new("block with id '#{child_template.id}' appears out of order")
      else
        raise ArgumentError.new("cannot find block with id '#{child_template.id}'")
      end
    end
    child_template.update_block(child_blocks[index])
    index += 1
  end
end