Class: Magellan::Cli::Resources::ClientVersion

Inherits:
Base
  • Object
show all
Defined in:
lib/magellan/cli/resources/client_version.rb

Constant Summary

Constants included from FileAccess

FileAccess::DEFAULT_SELECTION_FILENAME

Instance Method Summary collapse

Methods included from FileAccess

ensure_config_dir, load_selection, load_selections, remove_selection_file, selection_filename, update_selections

Methods inherited from Base

command_help, help, log_error, log_info, log_success, log_verbose, log_warning, puts_with_color, sorted_commands, sorted_printable_commands, update_common_help_message

Instance Method Details

#create(version) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/magellan/cli/resources/client_version.rb', line 20

def create(version)
  project = load_selection!(Project)
  stage = load_selection!(Stage)
  attrs = {
    "project_id" => project["id"],
    "stage_title_id" => stage["id"],
    "version" => version,
  }
  if d = options[:domain]
    attrs["domain"] = d
  end
  params = { parameter_name => attrs }
  post_json("/admin/#{resource_key}/new.json", params)
  # TODO implement select method
  # select(version)
end

#delete(version) ⇒ Object



63
64
65
66
67
68
# File 'lib/magellan/cli/resources/client_version.rb', line 63

def delete(version)
  q = build_query("version" => version).update(default_query)
  r = get_first_result!(self.class.resource_name, version, "/admin/#{resource_key}.json", q)
  super("/admin/#{resource_key}/#{r['id']}/delete.json")
  log_success("OK")
end

#select(name) ⇒ Object



71
72
73
# File 'lib/magellan/cli/resources/client_version.rb', line 71

def select(name)
  super
end

#update(attrs) ⇒ Object



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/magellan/cli/resources/client_version.rb', line 38

def update(attrs)
  if File.readable?(attrs)
    attrs = YAML.load_file(attrs)
  else
    attrs = JSON.parse(attrs)
  end
  stage_name = attrs.delete("stage")

  cv = load_selection!(self.class)
  self.class.hidden_fields.each do |f| attrs.delete(f) end
  self.class.field_associations.keys.each do |f| attrs.delete(f) end

  unless stage_name.blank?
    q = Stage.new.build_name_query(stage_name)
    r = get_first_result!(Stage.parameter_name, stage_name, "/admin/stage~title.json", q)
    attrs["stage_title_id"] = r["id"]
  end

  params = {
    parameter_name => attrs
  }
  put_json("/admin/#{resource_key}/#{cv["id"]}/edit.json", params)
end