Module: HammerCLIForeman::AssociatingCommands::CommandExtension

Included in:
Architecture, ComputeResource, Domain, Hostgroup, Location, Medium, OperatingSystem, Organization, PartitionTable, ProvisioningTemplate, Role, SmartProxy, Subnet, User, Usergroup
Defined in:
lib/hammer_cli_foreman/associating_commands.rb

Instance Method Summary collapse

Instance Method Details

#base_name(cls) ⇒ Object



31
32
33
# File 'lib/hammer_cli_foreman/associating_commands.rb', line 31

def base_name(cls)
  cls.name.split("::")[-1]
end

#extend_command(base_command) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/hammer_cli_foreman/associating_commands.rb', line 6

def extend_command(base_command)
  commands = self.constants.map {|c| self.const_get(c)}.select {|c| c < HammerCLI::AbstractCommand }

  commands.each do |cmd|
    plug_command(cmd, base_command)
  end
end

#plug_command(command, base_command) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/hammer_cli_foreman/associating_commands.rb', line 14

def plug_command(command, base_command)
  cmd_name = base_name(command)
  base_name = base_name(base_command)

  name = base_name + cmd_name

  cmd_cls = Class.new(command)
  base_command.const_set(name, cmd_cls)

  cmd_cls.resource(base_command.resource.name)
  cmd_cls.desc(command.desc)
  #TODO: update messages to inherit from parents
  cmd_cls.success_message(command.success_message)
  cmd_cls.failure_message(command.failure_message)
  cmd_cls.build_options
end