Class: HammerCLIForeman::SearchablesOptionBuilder
- Inherits:
-
SearchablesAbstractOptionBuilder
- Object
- HammerCLI::AbstractOptionBuilder
- SearchablesAbstractOptionBuilder
- HammerCLIForeman::SearchablesOptionBuilder
- Defined in:
- lib/hammer_cli_foreman/option_builders.rb
Instance Attribute Summary collapse
-
#resource ⇒ Object
readonly
Returns the value of attribute resource.
Instance Method Summary collapse
- #aliased_name(name, resource_name_map) ⇒ Object
- #build(builder_params = {}) ⇒ Object
-
#initialize(resource, searchables) ⇒ SearchablesOptionBuilder
constructor
A new instance of SearchablesOptionBuilder.
- #resource_name(param) ⇒ Object
Constructor Details
#initialize(resource, searchables) ⇒ SearchablesOptionBuilder
Returns a new instance of SearchablesOptionBuilder.
165 166 167 168 |
# File 'lib/hammer_cli_foreman/option_builders.rb', line 165 def initialize(resource, searchables) @resource = resource @searchables = searchables end |
Instance Attribute Details
#resource ⇒ Object (readonly)
Returns the value of attribute resource.
170 171 172 |
# File 'lib/hammer_cli_foreman/option_builders.rb', line 170 def resource @resource end |
Instance Method Details
#aliased_name(name, resource_name_map) ⇒ Object
185 186 187 188 189 |
# File 'lib/hammer_cli_foreman/option_builders.rb', line 185 def aliased_name(name, resource_name_map) return if name.nil? resource_name_map[name.to_s] || resource_name_map[name.to_sym] || name end |
#build(builder_params = {}) ⇒ Object
172 173 174 175 176 177 178 179 180 181 182 183 |
# File 'lib/hammer_cli_foreman/option_builders.rb', line 172 def build(builder_params={}) resource_name_map = builder_params[:resource_mapping] || {} @searchables.for(@resource).collect do |s| option( optionamize("--#{s.name}"), s.name.upcase, s.description, referenced_resource: @resource.singular_name, aliased_resource: aliased_name(resource_name(s.name), resource_name_map) ) end end |
#resource_name(param) ⇒ Object
191 192 193 194 195 196 197 198 199 |
# File 'lib/hammer_cli_foreman/option_builders.rb', line 191 def resource_name(param) if param =~ /^id[s]?$/ @resource.singular_name elsif param =~ /_id[s]?$/ param.gsub(/_id[s]?$/, '') else nil end end |