Method: Megam::FlavorsCollection#insert

Defined in:
lib/megam/core/flavors_collection.rb

#insert(flavors) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/megam/core/flavors_collection.rb', line 38

def insert(flavors)
    is_megam_flavors(flavors)
    if @insert_after_idx
        # in the middle of executing a run, so any nodes inserted now should
        # be placed after the most recent addition done by the currently executing
        # node
        @flavors.insert(@insert_after_idx + 1, flavors)
        # update name -> location mappings and register new node
        @flavors_by_name.each_key do |key|
            @flavors_by_name[key] += 1 if @flavors_by_name[key] > @insert_after_idx
        end
        @flavors_by_name[flavors.] = @insert_after_idx + 1
        @insert_after_idx += 1
    else
        @flavors << flavors
        @flavors_by_name[flavors.] = @flavors.length - 1
    end
end