Class: HammerCLIForeman::AssociatedCommand
- Inherits:
-
Command
- Object
- HammerCLI::Apipie::Command
- Command
- HammerCLIForeman::AssociatedCommand
show all
- Defined in:
- lib/hammer_cli_foreman/commands.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Command
alias_name_for_resource, build_options, connection_name, #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
Class Method Details
.associated_resource(name = nil) ⇒ Object
609
610
611
612
613
|
# File 'lib/hammer_cli_foreman/commands.rb', line 609
def self.associated_resource(name=nil)
@associated_api_resource = HammerCLIForeman.foreman_resource!(name) unless name.nil?
return @associated_api_resource if @associated_api_resource
return superclass.associated_resource if superclass.respond_to? :associated_resource
end
|
.create_option_builder ⇒ Object
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
|
# File 'lib/hammer_cli_foreman/commands.rb', line 587
def self.create_option_builder
builder = ForemanOptionBuilder.new(searchables)
builder.builders = [
SearchablesOptionBuilder.new(resource, searchables),
DependentSearchablesOptionBuilder.new(associated_resource, searchables)
]
resources = []
resources += dependency_resolver.resource_dependencies(resource, :only_required => true, :recursive => true)
resources += dependency_resolver.resource_dependencies(associated_resource, :only_required => true, :recursive => true)
resources.each do |r|
builder.builders << DependentSearchablesOptionBuilder.new(r, searchables)
end
builder.builders << IdOptionBuilder.new(resource)
builder
end
|
.default_message(format) ⇒ Object
615
616
617
618
|
# File 'lib/hammer_cli_foreman/commands.rb', line 615
def self.default_message(format)
name = associated_resource ? associated_resource.singular_name.to_s : nil
format % { :resource_name => name.gsub(/_|-/, ' ') } unless name.nil?
end
|
Instance Method Details
#associated_resource ⇒ Object
605
606
607
|
# File 'lib/hammer_cli_foreman/commands.rb', line 605
def associated_resource
self.class.associated_resource
end
|
#association_name(plural = false) ⇒ Object
652
653
654
|
# File 'lib/hammer_cli_foreman/commands.rb', line 652
def association_name(plural = false)
plural ? associated_resource.name.to_s : associated_resource.singular_name.to_s
end
|
#get_associated_identifier ⇒ Object
620
621
622
|
# File 'lib/hammer_cli_foreman/commands.rb', line 620
def get_associated_identifier
get_resource_id(associated_resource, :scoped => true)
end
|
#get_associated_identifiers ⇒ Object
624
625
626
|
# File 'lib/hammer_cli_foreman/commands.rb', line 624
def get_associated_identifiers
get_resource_ids(associated_resource, :scoped => true)
end
|
#get_current_ids ⇒ Object
632
633
634
635
636
637
638
639
|
# File 'lib/hammer_cli_foreman/commands.rb', line 632
def get_current_ids
item = HammerCLIForeman.record_to_common_format(resource.call(:show, {:id => get_identifier}))
if item.has_key?(association_name(true))
item[association_name(true)].map { |assoc| assoc['id'] }
else
item[association_name+'_ids'] || []
end
end
|
#get_new_ids ⇒ Object
628
629
630
|
# File 'lib/hammer_cli_foreman/commands.rb', line 628
def get_new_ids
[]
end
|
#request_params ⇒ Object
641
642
643
644
645
646
647
648
649
650
|
# File 'lib/hammer_cli_foreman/commands.rb', line 641
def request_params
params = super
if params.key?(resource.singular_name)
params[resource.singular_name] = {"#{association_name}_ids" => get_new_ids }
else
params["#{association_name}_ids"] = get_new_ids
end
params['id'] = get_identifier
params
end
|