Class: EPC::Command::UpdatePluginCommand

Inherits:
UpdateCommand show all
Defined in:
lib/epc/command/plugin/update_plugin_command.rb

Constant Summary collapse

UPDATABLE_ATTRIBUTES =
["name", "plugin_version", "group", "inherited", "extensions", "executions", "configuration"]

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, required_options

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(plugin = nil, *args) ⇒ Object

Raises:



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
# File 'lib/epc/command/plugin/update_plugin_command.rb', line 5

def execute(plugin = nil, *args)

  plugin_id = retrieve_identifier_for("Plugin", plugin)

  args = args[1..3] rescue nil

  raise FatalError, "You need to specify at least one attribute to update" if args.size < 1
  params = {}

  args.each do |arg|
    key, val = arg.split("=")
    next if key.blank?
    params[key] = parse_plugin_opt(val)
  end

  params.each do |attr, val|
    unless UPDATABLE_ATTRIBUTES.include?(attr)
      params.delete(attr)
      say("Cannot update #{attr}. Updatable attributes are: [#{UPDATABLE_ATTRIBUTES.join(', ')}]")
      next
    end
  end

  raise InputError, "You need to specify at least one attribute to update" if params.blank?
  
  status, response, headers = client.put(EPC::Config::PLUGINS_PATH + "/#{plugin_id}", params)

  if status.successful?
    say("Plugin updated")
  else
    say("Request failed: [#{response[:message]}]")
  end

  return status

end