Class: HammerCLIForeman::BuilderConfigurator

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

Instance Method Summary collapse

Constructor Details

#initialize(searchables, dependency_resolver) ⇒ BuilderConfigurator

Returns a new instance of BuilderConfigurator.



62
63
64
65
# File 'lib/hammer_cli_foreman/option_builders.rb', line 62

def initialize(searchables, dependency_resolver)
  @searchables = searchables
  @dependency_resolver = dependency_resolver
end

Instance Method Details

#builders_for(resource, action) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/hammer_cli_foreman/option_builders.rb', line 67

def builders_for(resource, action)
  builders = []

  dependent_resources = []

  if action.params.find{ |p| p.name == "id" }
    builders << SearchablesOptionBuilder.new(resource, @searchables)
    dependent_resources += @dependency_resolver.resource_dependencies(resource, :only_required => true, :recursive => true)
  end
  dependent_resources += @dependency_resolver.action_dependencies(action, :only_required => false, :recursive => false)
  dependent_resources += @dependency_resolver.action_dependencies(action, :only_required => true, :recursive => true)

  dependent_resources.uniq(&:name).each do |dep_resource|
    builders << DependentSearchablesOptionBuilder.new(
      dep_resource,
      @searchables,
      context: { action: action }
    )
  end

  IdArrayParamsFilter.new(:only_required => false).for_action(action).each do |p|
    resource = HammerCLIForeman.param_to_resource(p.name)
    builders << DependentSearchablesArrayOptionBuilder.new(resource, @searchables) unless resource.nil?
  end

  builders
end