Class: HammerCLIForeman::IdResolver

Inherits:
Object
  • Object
show all
Defined in:
lib/hammer_cli_foreman/id_resolver.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api, searchables) ⇒ IdResolver

Returns a new instance of IdResolver.



71
72
73
74
75
# File 'lib/hammer_cli_foreman/id_resolver.rb', line 71

def initialize(api, searchables)
  @api = api
  @searchables = searchables
  define_id_finders
end

Instance Attribute Details

#apiObject (readonly)

Returns the value of attribute api.



69
70
71
# File 'lib/hammer_cli_foreman/id_resolver.rb', line 69

def api
  @api
end

Instance Method Details

#scoped_options(scope, options) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/hammer_cli_foreman/id_resolver.rb', line 77

def scoped_options(scope, options)
  scoped_options = options.dup

  resource = HammerCLIForeman.param_to_resource(scope)
  return scoped_options unless resource

  option_names = searchables(resource).map { |s| s.name }
  option_names << "id"

  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_options[scoped_option]
      scoped_options[option] = scoped_options.delete(scoped_option)
    else
      scoped_options.delete(option)
    end
  end
  scoped_options
end