Class: HammerCLIForeman::ForemanOptionBuilder
- Inherits:
-
HammerCLI::OptionBuilderContainer
- Object
- HammerCLI::OptionBuilderContainer
- HammerCLIForeman::ForemanOptionBuilder
- Defined in:
- lib/hammer_cli_foreman/option_builders.rb
Instance Method Summary collapse
- #build(builder_params = {}) ⇒ Object
- #default_dependent_resources ⇒ Object
- #dependent_searchable_builders ⇒ Object
-
#initialize(searchables) ⇒ ForemanOptionBuilder
constructor
A new instance of ForemanOptionBuilder.
Constructor Details
#initialize(searchables) ⇒ ForemanOptionBuilder
Returns a new instance of ForemanOptionBuilder.
98 99 100 |
# File 'lib/hammer_cli_foreman/option_builders.rb', line 98 def initialize(searchables) @searchables = searchables end |
Instance Method Details
#build(builder_params = {}) ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/hammer_cli_foreman/option_builders.rb', line 102 def build(builder_params={}) = builder_params[:expand] || {} allowed_resources = [:only] || default_dependent_resources allowed_resources -= [:except] || [] allowed_resources += [:including] || [] allowed_resources.uniq! primary_resource = [:primary] to_remove = default_dependent_resources - allowed_resources to_add = allowed_resources - default_dependent_resources builders.reject! do |b| b.class <= DependentSearchablesOptionBuilder && to_remove.include?(b.resource.name) end to_add.each do |resource_name| builders << DependentSearchablesOptionBuilder.new(HammerCLIForeman.foreman_resource(resource_name), @searchables) end if !primary_resource.nil? builders.reject! do |b| b.class <= SearchablesOptionBuilder end builders << SearchablesOptionBuilder.new(HammerCLIForeman.foreman_resource(primary_resource), @searchables) if primary_resource != false end super end |
#default_dependent_resources ⇒ Object
132 133 134 |
# File 'lib/hammer_cli_foreman/option_builders.rb', line 132 def default_dependent_resources dependent_searchable_builders.map(&:resource).map(&:name) end |
#dependent_searchable_builders ⇒ Object
136 137 138 |
# File 'lib/hammer_cli_foreman/option_builders.rb', line 136 def dependent_searchable_builders self.builders.select{|b| b.class <= DependentSearchablesOptionBuilder } end |