Module: ActiveData::Model::Collectionizable::ClassMethods
- Defined in:
- lib/active_data/model/collectionizable.rb
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
23
24
25
26
27
|
# File 'lib/active_data/model/collectionizable.rb', line 23
def method_missing method, *args, &block
collection_class.superclass.method_defined?(method) ?
current_scope.send(method, *args, &block) :
super
end
|
Instance Method Details
#collection(source = nil) ⇒ Object
29
30
31
|
# File 'lib/active_data/model/collectionizable.rb', line 29
def collection source = nil
collection_class.new source
end
|
#collection_class ⇒ Object
33
34
35
36
37
38
39
|
# File 'lib/active_data/model/collectionizable.rb', line 33
def collection_class
@collection_class ||= begin
Class.new(_collection_superclass) do
include ActiveData::Model::Collectionizable::Proxy
end.tap { |klass| klass.collectible = self }
end
end
|
#collectionize(collection_superclass = Array) ⇒ Object
15
16
17
|
# File 'lib/active_data/model/collectionizable.rb', line 15
def collectionize collection_superclass = Array
self._collection_superclass = collection_superclass
end
|
#current_scope ⇒ Object
Also known as:
scope
45
46
47
|
# File 'lib/active_data/model/collectionizable.rb', line 45
def current_scope
@current_scope ||= collection(load)
end
|
#current_scope=(value) ⇒ Object
41
42
43
|
# File 'lib/active_data/model/collectionizable.rb', line 41
def current_scope= value
@current_scope = value
end
|
#load ⇒ Object
50
|
# File 'lib/active_data/model/collectionizable.rb', line 50
def load; end
|
#respond_to_missing?(method, include_private) ⇒ Boolean
19
20
21
|
# File 'lib/active_data/model/collectionizable.rb', line 19
def respond_to_missing? method, include_private
super || collection_class.superclass.method_defined?(method)
end
|