Method: Megam::SshKeyCollection#insert

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

#insert(sshkeys) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/megam/core/sshkey_collection.rb', line 53

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