Class: HammerCLIForeman::AddAssociatedCommand

Inherits:
AssociatedCommand show all
Defined in:
lib/hammer_cli_foreman/commands.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from AssociatedCommand

associated_resource, #associated_resource, #association_name, create_option_builder, default_message, #get_associated_identifier, #get_associated_identifiers, #get_current_ids, #request_params

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



663
664
665
666
# File 'lib/hammer_cli_foreman/commands.rb', line 663

def self.command_name(name=nil)
  name = super(name) || (associated_resource ? "add-"+associated_resource.singular_name : nil)
  name.respond_to?(:gsub) ? name.gsub('_', '-') : name
end

.desc(desc = nil) ⇒ Object



668
669
670
671
# File 'lib/hammer_cli_foreman/commands.rb', line 668

def self.desc(desc=nil)
  description = super(desc) || ''
  description.strip.empty? ? _("Associate a resource") : description
end

.failure_message(msg = nil) ⇒ Object



673
674
675
# File 'lib/hammer_cli_foreman/commands.rb', line 673

def self.failure_message(msg = nil)
  super(msg) || default_message(_('Could not associate the %{resource_name}.'))
end

.success_message(msg = nil) ⇒ Object



677
678
679
# File 'lib/hammer_cli_foreman/commands.rb', line 677

def self.success_message(msg = nil)
  super(msg) || default_message(_('The %{resource_name} has been associated.'))
end

Instance Method Details

#get_new_idsObject



681
682
683
684
685
686
687
688
689
690
691
692
# File 'lib/hammer_cli_foreman/commands.rb', line 681

def get_new_ids
  ids = get_current_ids.map(&:to_s)

  associated_identifiers = get_associated_identifiers
  associated_identifier = get_associated_identifier

  required_ids = associated_identifiers.nil? ? [] : associated_identifiers.map(&:to_s)
  required_ids << associated_identifier.to_s unless associated_identifier.nil?

  ids += required_ids
  ids.uniq
end