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

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

def execute(args)

  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_err("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 + "/#{object_id}", params)

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

  return status

end