Class: EPC::Command::UpdateConfigCommand

Inherits:
BaseCommand show all
Defined in:
lib/epc/command/update_config_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(*args) ⇒ Object



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

def execute(*args)
  if args.empty?
    say("You have to specify a key and its value.")
    return 1
  end

  path = "."
  path = File.expand_path(path)

  @options[:required] = false if @options[:required].nil?

  config_type, config_id = extract_configuration_level(path, @options)
  request_path = EPC::Config::CONFIGURATIONS_PATH+"/#{config_type}/#{config_id}"

  if ["solution", "project"].include?(config_type.downcase) && !@options[:stage].nil?
    request_path += "/#{@options[:stage]}"
  end

  status, response, headers = client.get(request_path)

  if status.failure? 
    say("Configuration retrieval failed with [#{response[:message]}]")
    return status
  end

  keys = response

  args.each do |arg|
    name, value = arg.split("=")

    key_id = keys.detect{|k| k[:name] == name}[:id] rescue nil
    
    if key_id.nil?
      say("Key does not exist.") 
      return 1
    end

    params = {
      :name => name,
    }
    params[:value] = value unless value.nil?
    params[:required] = @options[:required]
    params[:no_override] = @options[:no_override] unless @options[:no_override].nil?

    status, response, headers = client.put(EPC::Config::CONFIGURATIONS_PATH + "/#{key_id}", params)

    if status.successful?
      unless response[:id].nil?
        say("#{name} saved.")
      end
    else
      say("Request failed with message [#{response[:message]}]")
    end
    return status
  end
end