Class: HammerCLIForeman::Parameter::SetCommand

Inherits:
AbstractParameterCommand show all
Defined in:
lib/hammer_cli_foreman/parameter.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from AbstractParameterCommand

#base_action_params, create_option_builder, #get_identifier, #get_parameter_identifier, #parameter_resource, parameter_resource

Methods inherited from Command

alias_name_for_resource, build_options, connection_name, create_option_builder, #customized_options, #dependency_resolver, dependency_resolver, #exception_handler_class, #get_identifier, #get_resource_id, #get_resource_ids, #request_params, resolver, #resolver, resource_alias_name_mapping, resource_config, resource_name_mapping, #searchables, searchables, #send_request, #transform_format

Class Method Details

.command_name(name = nil) ⇒ Object



58
59
60
# File 'lib/hammer_cli_foreman/parameter.rb', line 58

def self.command_name(name=nil)
  (super(name) || "set-parameter").gsub('_', '-')
end

Instance Method Details

#create_parameterObject



89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/hammer_cli_foreman/parameter.rb', line 89

def create_parameter
  params = {
    "parameter" => {
      "name" => option_name,
      "value" => option_value,
      "parameter_type" => option_parameter_type,
      "hidden_value" => option_hidden_value
    }
  }.merge(base_action_params)

  HammerCLIForeman.record_to_common_format(parameter_resource.call(:create, params))
end

#executeObject



62
63
64
65
66
67
68
69
70
71
# File 'lib/hammer_cli_foreman/parameter.rb', line 62

def execute
  if parameter_exist?
    response = update_parameter
    print_message(success_message_for(:update), response) if success_message_for(:update)
  else
    response = create_parameter
    print_message(success_message_for(:create), response) if success_message_for(:create)
  end
  HammerCLI::EX_OK
end

#parameter_exist?Boolean

Returns:

  • (Boolean)


73
74
75
# File 'lib/hammer_cli_foreman/parameter.rb', line 73

def parameter_exist?
  get_parameter_identifier rescue false
end

#update_parameterObject



77
78
79
80
81
82
83
84
85
86
87
# File 'lib/hammer_cli_foreman/parameter.rb', line 77

def update_parameter
  params = {
    "id" => get_parameter_identifier,
    "parameter" => {
      "value" => option_value,
      "parameter_type" => option_parameter_type,
      "hidden_value" => option_hidden_value
    }
  }.merge(base_action_params)
  HammerCLIForeman.record_to_common_format(parameter_resource.call(:update, params))
end