Class: HammerCLIForeman::IdResolver
- Inherits:
-
Object
- Object
- HammerCLIForeman::IdResolver
- Defined in:
- lib/hammer_cli_foreman/id_resolver.rb
Constant Summary collapse
- ALL_PER_PAGE =
1000
Instance Attribute Summary collapse
-
#api ⇒ Object
readonly
Returns the value of attribute api.
Instance Method Summary collapse
-
#initialize(api, searchables) ⇒ IdResolver
constructor
A new instance of IdResolver.
- #scoped_options(scope, options, mode = nil) ⇒ Object
- #searchables(resource) ⇒ Object
- #template_kind_id(options = {}) ⇒ Object
Constructor Details
#initialize(api, searchables) ⇒ IdResolver
Returns a new instance of IdResolver.
87 88 89 90 91 |
# File 'lib/hammer_cli_foreman/id_resolver.rb', line 87 def initialize(api, searchables) @api = api @searchables = searchables define_id_finders end |
Instance Attribute Details
#api ⇒ Object (readonly)
Returns the value of attribute api.
85 86 87 |
# File 'lib/hammer_cli_foreman/id_resolver.rb', line 85 def api @api end |
Instance Method Details
#scoped_options(scope, options, mode = nil) ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/hammer_cli_foreman/id_resolver.rb', line 94 def (scope, , mode = nil) = .dup resource = HammerCLIForeman.param_to_resource(scope) return unless resource option_names = [] if (mode.nil? || mode == :single) option_names += searchables(resource).map { |s| s.name } option_names << "id" unless option_names.include?("id") end if (mode.nil? || mode == :multi) option_names << "ids" option_names += searchables(resource).map { |s| s.plural_name } end option_names.each do |name| option = HammerCLI.option_accessor_name(name) scoped_option = HammerCLI.option_accessor_name("#{scope}_#{name}") # remove the scope # e.g. option_architecture_id -> option_id if [scoped_option] [option] = .delete(scoped_option) else .delete(option) end end end |
#searchables(resource) ⇒ Object
123 124 125 126 |
# File 'lib/hammer_cli_foreman/id_resolver.rb', line 123 def searchables(resource) resource = @api.resource(resource) if resource.is_a? Symbol @searchables.for(resource) end |
#template_kind_id(options = {}) ⇒ Object
128 129 130 131 132 |
# File 'lib/hammer_cli_foreman/id_resolver.rb', line 128 def template_kind_id( = {}) name = ['option_type'] == 'snippet' ? nil : ['option_type'] ['option_name'] = name get_id(:template_kinds, ) end |