Class: HammerCLIForeman::CommonParameter::SetCommand

Inherits:
HammerCLIForeman::Command show all
Defined in:
lib/hammer_cli_foreman/common_parameter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from HammerCLIForeman::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, resolver, #resolver, resource_alias_name_mapping, resource_config, resource_name_mapping, #searchables, searchables, #send_request, #transform_format

Instance Attribute Details

#actionObject (readonly)

Returns the value of attribute action.



35
36
37
# File 'lib/hammer_cli_foreman/common_parameter.rb', line 35

def action
  @action
end

Instance Method Details

#executeObject



37
38
39
40
# File 'lib/hammer_cli_foreman/common_parameter.rb', line 37

def execute
  @action ||= parameter_exist? ? :update : :create
  super
end

#parameter_exist?Boolean

Returns:

  • (Boolean)


46
47
48
49
50
# File 'lib/hammer_cli_foreman/common_parameter.rb', line 46

def parameter_exist?
  params = resource.call(:index)
  params = HammerCLIForeman.collection_to_common_format(params)
  params.find { |p| p["name"] == option_name }
end

#request_paramsObject



52
53
54
# File 'lib/hammer_cli_foreman/common_parameter.rb', line 52

def request_params
  super.update('id' => option_name)
end

#success_messageObject



42
43
44
# File 'lib/hammer_cli_foreman/common_parameter.rb', line 42

def success_message
  success_message_for(action)
end