Class: EPC::Command::UpdateProjectCommand

Inherits:
BaseCommand show all
Defined in:
lib/epc/command/project/update_project_command.rb

Constant Summary collapse

UPDATABLE_ATTRIBUTES =
["project_name", "project_type"]

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(project = 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
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/epc/command/project/update_project_command.rb', line 5

def execute(project = nil, *args)
  path = "."
  path = File.expand_path(path)

  ids = project.split(":") rescue [nil, nil]

  if ids.size == 1
    project_name = ids[0]
    solution_name = nil
  elsif ids.size == 2
    solution_name, project_name = ids
  end

  solution_id, solution_name = infer_solution_context(solution_name, path, :get_solution_name => true)
  project_id, project_name = infer_project_context(project_name, path, solution_id, {:get_project_name => true})

  raise FatalError, "Project could not be inferred" if project_id.nil? || project_id == 0

  args_hash = {}
  args.each do |arg|
    key, val = arg.split("=")
    next if key.nil?
    args_hash[key] = val
  end

  unless @options[:file].nil?
    args_hash = EPC::Config.read_content_as_json(@options[:file]).merge(args_hash)
  end

  args_hash.each do |attr, val|
    unless UPDATABLE_ATTRIBUTES.include?(attr)
      args_hash.delete(attr)
      say("Cannot update #{attr}. Updatable attributes are: [#{UPDATABLE_ATTRIBUTES.join(', ')}]")
      next
    end
  end
  unless args_hash.empty?
    status, response, message = client.put(EPC::Config::PROJECTS_PATH + "/#{project_id}", args_hash)
    if status.failure?
      say("Update failed with: [#{response[:message]}]")
    else
      say("Update succesful")
    end
    return status
  else
    say(EPC::Help::COMMAND_USAGES[:update_project])
    return 1
  end
end