Class: HammerCLIForeman::AssociatedCommand
- Inherits:
-
WriteCommand
- Object
- HammerCLI::Apipie::WriteCommand
- WriteCommand
- HammerCLIForeman::AssociatedCommand
show all
- Defined in:
- lib/hammer_cli_foreman/commands.rb
Class Method Summary
collapse
Instance Method Summary
collapse
#request_headers, #send_request
Class Method Details
.apipie_options(options = {}) ⇒ Object
200
201
202
203
|
# File 'lib/hammer_cli_foreman/commands.rb', line 200
def self.apipie_options(options={})
setup_associated_identifier_options
super
end
|
.associated_identifiers(*keys) ⇒ Object
224
225
226
|
# File 'lib/hammer_cli_foreman/commands.rb', line 224
def self.associated_identifiers(*keys)
@associated_identifiers = keys
end
|
.associated_resource(resource_class = nil) ⇒ Object
217
218
219
220
|
# File 'lib/hammer_cli_foreman/commands.rb', line 217
def self.associated_resource(resource_class=nil)
@associated_api_resource = HammerCLI::Apipie::ResourceDefinition.new(resource_class) unless resource_class.nil?
return @associated_api_resource
end
|
.declared_associated_identifiers ⇒ Object
228
229
230
231
232
233
234
235
236
|
# File 'lib/hammer_cli_foreman/commands.rb', line 228
def self.declared_associated_identifiers
if @associated_identifiers
return @associated_identifiers
elsif superclass.respond_to?(:declared_associated_identifiers, true)
superclass.declared_associated_identifiers
else
[]
end
end
|
.setup_associated_identifier_options ⇒ Object
205
206
207
208
209
210
|
# File 'lib/hammer_cli_foreman/commands.rb', line 205
def self.setup_associated_identifier_options
name = associated_resource.name.to_s
option_switch = "--"+name.gsub('_', '-')
option option_switch, name.upcase, " ", :attribute_name => :associated_name if declared_associated_identifiers.include? :name
option option_switch+"-id", name.upcase+"_ID", " ", :attribute_name => :associated_id if declared_associated_identifiers.include? :id
end
|
Instance Method Details
#associated_resource ⇒ Object
213
214
215
|
# File 'lib/hammer_cli_foreman/commands.rb', line 213
def associated_resource
HammerCLI::Apipie::ResourceInstance.from_definition(self.class.associated_resource, resource_config)
end
|
#get_current_ids ⇒ Object
244
245
246
247
|
# File 'lib/hammer_cli_foreman/commands.rb', line 244
def get_current_ids
item = HammerCLIForeman.record_to_common_format(resource.call('show', {'id' => get_identifier[0]})[0])
item[associated_resource.name+'_ids'] || []
end
|
#get_new_ids ⇒ Object
240
241
242
|
# File 'lib/hammer_cli_foreman/commands.rb', line 240
def get_new_ids
[]
end
|
#get_required_id ⇒ Object
249
250
251
252
|
# File 'lib/hammer_cli_foreman/commands.rb', line 249
def get_required_id
item = HammerCLIForeman.record_to_common_format(associated_resource.call('show', {'id' => associated_id || associated_name})[0])
item['id']
end
|
#request_params ⇒ Object
254
255
256
257
258
259
|
# File 'lib/hammer_cli_foreman/commands.rb', line 254
def request_params
params = method_options
params[resource.name][associated_resource.name+'_ids'] = get_new_ids
params['id'] = get_identifier[0]
params
end
|
#validate_options ⇒ Object
194
195
196
197
198
|
# File 'lib/hammer_cli_foreman/commands.rb', line 194
def validate_options
associated_ids = self.class.declared_associated_identifiers.collect {|id_name| "associated_#{id_name}" }
validator.any(*associated_ids).required
validator.any(*self.class.declared_identifiers.values).required
end
|