Class: ApiResource::Finders::AbstractFinder

Inherits:
Object
  • Object
show all
Defined in:
lib/api_resource/finders/abstract_finder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(klass, condition) ⇒ AbstractFinder

Returns a new instance of AbstractFinder.



14
15
16
17
18
19
20
# File 'lib/api_resource/finders/abstract_finder.rb', line 14

def initialize(klass, condition)
  @klass = klass
  @condition = condition
  @found = false

  @klass.load_resource_definition
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object

proxy unknown methods to the internal_object



44
45
46
# File 'lib/api_resource/finders/abstract_finder.rb', line 44

def method_missing(method, *args, &block)
  self.internal_object.send(method, *args, &block)
end

Instance Attribute Details

#conditionObject

Returns the value of attribute condition.



8
9
10
# File 'lib/api_resource/finders/abstract_finder.rb', line 8

def condition
  @condition
end

#foundObject (readonly)

Returns the value of attribute found.



9
10
11
# File 'lib/api_resource/finders/abstract_finder.rb', line 9

def found
  @found
end

#internal_objectObject (readonly)

Returns the value of attribute internal_object.



9
10
11
# File 'lib/api_resource/finders/abstract_finder.rb', line 9

def internal_object
  @internal_object
end

#klassObject

Returns the value of attribute klass.



8
9
10
# File 'lib/api_resource/finders/abstract_finder.rb', line 8

def klass
  @klass
end

Instance Method Details

#all(*args) ⇒ Object



35
36
37
38
39
40
41
# File 'lib/api_resource/finders/abstract_finder.rb', line 35

def all(*args)
  if args.blank?
    self.internal_object
  else
    self.klass.send(:all, *args)
  end
end

#loadObject



22
23
24
# File 'lib/api_resource/finders/abstract_finder.rb', line 22

def load
  raise NotImplementedError("Must be defined in a subclass")
end