Method: Megam::RequestCollection#insert

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

#insert(request) ⇒ Object



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

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