Class: EPC::Command::UpdateProjecttypeCommand

Inherits:
UpdateCommand show all
Defined in:
lib/epc/command/projecttype/update_projecttype_command.rb

Constant Summary collapse

UPDATABLE_ATTRIBUTES =
["name", "runtime", "framework", "build_type", "build_packaging", "deployable", "runtime_env_types"]

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:



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
# File 'lib/epc/command/projecttype/update_projecttype_command.rb', line 6

def execute(args)
  require_object

  raise FatalError, "You need to specify at least one attribute to update.\nUpdatable attributes are: [#{UPDATABLE_ATTRIBUTES.join(', ')}]" if args.size < 1
  params = {}

  args.each do |arg|
    key, val = arg.split("=")
    next if key.blank?
    if key == :runtime_env_types
      begin
        params[:runtime_env_types] = []
        args[6].split(",").each do |rti|
          params[:runtime_env_types] << {:id => retrieve_identifier_for("RuntimeEnvType", rti)}
        end
      rescue Exception => ex
        say("Unable to parse runtime-env-types parameter")
        return 1
      end
    else
      params[key] = val
    end
  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.get(EPC::Config::PROJECT_TYPES_PATH + "/#{object_id}")

  unless status.successful?
    say_err("Request failed: [#{response[:message]}]")
    return 1
  end

  type_attrs = response.merge(params.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo})
   
  status, response, headers = client.put(EPC::Config::PROJECT_TYPES_PATH + "/#{object_id}", type_attrs)

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

  return status

end