Class: EPC::Command::UpdateLibrarysetCommand

Inherits:
BaseCommand show all
Defined in:
lib/epc/command/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, #options

Instance Method Summary collapse

Methods inherited from BaseCommand

#go, inherited, #initialize, #method_missing, required_arguments_count, required_options, #respond_to?

Methods included from PersistentAttributes

#auth_token, #caller_id, #target_url

Constructor Details

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

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class EPC::Command::BaseCommand

Instance Method Details

#execute(set = nil) ⇒ Object



4
5
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
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/epc/command/update_libraryset_command.rb', line 4

def execute(set = nil)
  if set.nil?
    say("You must specify the library-set")
    say(EPC::Help::COMMAND_USAGES[:update_libraryset])
    return 1
  end 

  if numeric?(set)
    set_id = set.to_i
  else
    set_id = get_resource_id(EPC::Config::LIBRARY_SETS_PATH, :name, set, :case_sensitivity => false)
  end

  if set_id.nil?
    say("Set could not be determined")
    return 1
  end

  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("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.post(EPC::Config::LIBRARY_SETS_PATH + "/#{set_id}/detach_library/#{lib_id}")
    if status.successful?
      say("Library [#{lib}] removed from set")
    else
      say("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("Failed to add [#{lib_id}]: [#{response[:message]}]")
        failures << true
      end
    end
    return failures.all? ? 1 : 0
  end

end