Class: Apia::LookupArgumentSet

Inherits:
ArgumentSet show all
Defined in:
lib/apia/lookup_argument_set.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ArgumentSet

#[], create_from_request, #dig, #empty?, #has?, #initialize, #to_hash

Methods included from Defineable

#create, #inspect, #method_missing, #name, #respond_to_missing?

Constructor Details

This class inherits a constructor from Apia::ArgumentSet

Class Method Details

.collate_objects(set) ⇒ void

This method returns an undefined value.

Finds all objects referenced by this argument set and add them to the provided set.

Parameters:



24
25
26
27
28
29
30
# File 'lib/apia/lookup_argument_set.rb', line 24

def collate_objects(set)
  super

  definition.potential_errors.each do |error|
    set.add_object(error)
  end
end

.definitionApia::Definitions::ArgumentSet

Return the definition for this argument set



15
16
17
# File 'lib/apia/lookup_argument_set.rb', line 15

def definition
  @definition ||= Definitions::LookupArgumentSet.new(Helpers.class_name_to_id(name))
end

Instance Method Details

#environmentObject



40
41
42
# File 'lib/apia/lookup_argument_set.rb', line 40

def environment
  @environment ||= LookupEnvironment.new(self)
end

#resolve(*args) ⇒ Object



34
35
36
37
38
# File 'lib/apia/lookup_argument_set.rb', line 34

def resolve(*args)
  return if self.class.definition.resolver.nil?

  environment.call(@request, *args, &self.class.definition.resolver)
end

#validate(argument, index: nil) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
# File 'lib/apia/lookup_argument_set.rb', line 44

def validate(argument, index: nil)
  if @source.empty?
    raise InvalidArgumentError.new(argument, issue: :missing_lookup_value, index: index, path: @path)
  end

  if @source.values.compact.size > 1
    raise InvalidArgumentError.new(argument, issue: :ambiguous_lookup_values, index: index, path: @path)
  end

  true
end