Class: EPC::Command::UpdateLibrarysetCommand

Inherits:
BaseCommand show all
Defined in:
lib/epc/command/libraryset/update_libraryset_command.rb

Constant Summary

Constants inherited from BaseCommand

BaseCommand::GIVEUP_TICKS, BaseCommand::SLEEP_TIME, BaseCommand::TICKER_TICKS

Instance Attribute Summary

Attributes inherited from BaseCommand

#client, #klass_name, #object_id, #object_type, #options, #target_id, #target_type

Instance Method Summary collapse

Methods inherited from BaseCommand

#check_options, #context_params, #context_params=, #go, include_module, inherited, #initialize, required_options, #say_err

Methods included from PersistentAttributes

#auth_token, #caller_id, #target_url

Constructor Details

This class inherits a constructor from EPC::Command::BaseCommand

Instance Method Details

#execute(args) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/epc/command/libraryset/update_libraryset_command.rb', line 6

def execute(args)
  require_object

  set_id = object_id

  if @options[:add_library].present?
    lib = @options[:add_library]
    lib_id = extract_library_id(lib)

    status, response, headers = client.post(EPC::Config::LIBRARY_SETS_PATH + "/#{set_id}/attach_library/#{lib_id}")
    if status.successful?
      say("Library [#{lib}] added to set")
    else
      say_err("Request failed: [#{response[:message]}]")
    end
    return status
  end

  if @options[:remove_library].present?
    lib = @options[:remove_library]
    lib_id = extract_library_id(lib)

    status, response, headers = client.delete(EPC::Config::LIBRARY_SETS_PATH + "/#{set_id}/detach_library/#{lib_id}")
    if status.successful?
      say("Library [#{lib}] removed from set")
    else
      say_err("Request failed: [#{response[:message]}]")
    end
    return status
  end

  if @options[:file].present?
    libraries = EPC::Config.read_content_as_json(@options[:file]) 
    libraries = libraries.map{|h| {:name => h["name"], :version => h["library_version"], :group => h["group"]}}
    lib_ids = retrieve_libraries(libraries)
    
    failures = []
    lib_ids.each do |lib_id|
      status, response, headers = client.post(EPC::Config::LIBRARY_SETS_PATH + "/#{set_id}/attach_library/#{lib_id}")
      if status.successful?
        say("Library [#{lib_id}] added to set")
        failures << false
      else
        say_err("Failed to add [#{lib_id}]: [#{response[:message]}]")
        failures << true
      end
    end
    return failures.all? ? 1 : 0
  end

end