Class: HammerCLIForeman::CommandExtensions::Hosts::Help::ComputeResources

Inherits:
HammerCLI::CommandExtensions
  • Object
show all
Defined in:
lib/hammer_cli_foreman/command_extensions/hosts/help/compute_resources.rb

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ ComputeResources

Returns a new instance of ComputeResources.



78
79
80
81
# File 'lib/hammer_cli_foreman/command_extensions/hosts/help/compute_resources.rb', line 78

def initialize(options = {})
  super
  self.class.class_eval(&self.class.help_block) unless self.class.customized?
end

Class Attribute Details

.add_host_specific_attrs=(value) ⇒ Object (writeonly)

Sets the attribute add_host_specific_attrs

Parameters:

  • value

    the value to set the attribute add_host_specific_attrs to.



7
8
9
# File 'lib/hammer_cli_foreman/command_extensions/hosts/help/compute_resources.rb', line 7

def add_host_specific_attrs=(value)
  @add_host_specific_attrs = value
end

.attributesObject



20
21
22
23
# File 'lib/hammer_cli_foreman/command_extensions/hosts/help/compute_resources.rb', line 20

def attributes
  @attributes ||= :all
  @attributes
end

.current_providersObject



10
11
12
13
# File 'lib/hammer_cli_foreman/command_extensions/hosts/help/compute_resources.rb', line 10

def current_providers
  @current_providers ||= HammerCLIForeman.compute_resources.keys
  @current_providers
end

Class Method Details

.add_host_specific_attrs?Boolean

Returns:

  • (Boolean)


15
16
17
18
# File 'lib/hammer_cli_foreman/command_extensions/hosts/help/compute_resources.rb', line 15

def add_host_specific_attrs?
  @add_host_specific_attrs ||= false
  @add_host_specific_attrs
end

.custom(options = {}) ⇒ Object



33
34
35
36
37
38
39
40
41
# File 'lib/hammer_cli_foreman/command_extensions/hosts/help/compute_resources.rb', line 33

def custom(options = {})
  new_self = Class.new(ComputeResources)
  new_self.add_host_specific_attrs = options[:add_host_specific_attrs]
  new_self.attributes = options[:attributes]
  new_self.current_providers = options[:providers]
  new_self.class_eval(&help_block)
  new_self.customized = true
  new_self
end

.customized=(boolean) ⇒ Object



29
30
31
# File 'lib/hammer_cli_foreman/command_extensions/hosts/help/compute_resources.rb', line 29

def customized=(boolean)
  @customized ||= boolean
end

.customized?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/hammer_cli_foreman/command_extensions/hosts/help/compute_resources.rb', line 25

def customized?
  @customized
end

.help_blockObject



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/hammer_cli_foreman/command_extensions/hosts/help/compute_resources.rb', line 43

def help_block
  @help_block ||= Proc.new do
    help do |h|
      h.section(_('Provider specific options')) do |h|
        h.note(_('Bold attributes are required.'), richtext: true)
        HammerCLIForeman.compute_resources.each do |name, provider|
          next unless current_providers.include?(name)

          h.section(provider.name, id: name.to_sym) do |h|
            compute_attributes = provider.compute_attributes
            compute_attributes += provider.host_attributes if add_host_specific_attrs?
            if %i[all volume].include?(attributes)
              h.section('--volume') do |h|
                h.list(provider.volume_attributes)
              end
            end
            if %i[all interface].include?(attributes)
              h.section('--interface') do |h|
                h.list(provider.interface_attributes)
              end
            end
            if %i[all compute].include?(attributes)
              h.section('--compute-attributes', id: :s_compute_attributes) do |h|
                h.list(compute_attributes, id: :l_compute_attributes)
              end
            end
          end
          provider.extend_help(h) if provider.respond_to?(:extend_help)
        end
      end
    end
  end
end