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
29
30
31
|
# File 'lib/active_data/model/collectionizable.rb', line 29
def method_missing method, *args, &block
current_scope.send(method, *args, &block) if collection_class.superclass.method_defined?(method)
end
|
Instance Method Details
#collection(source = nil) ⇒ Object
33
34
35
|
# File 'lib/active_data/model/collectionizable.rb', line 33
def collection source = nil
collection_class.new source
end
|
#collection_class ⇒ Object
37
38
39
|
# File 'lib/active_data/model/collectionizable.rb', line 37
def collection_class
@collection_class ||= const_get(:Collection)
end
|
#collectionize(collection_superclass = nil) ⇒ Object
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/active_data/model/collectionizable.rb', line 14
def collectionize collection_superclass = nil
collection_superclass ||= Array
collection = Class.new(collection_superclass) do
include ActiveData::Model::Collectionizable::Proxy
end
collection.collectible = self
remove_const :Collection if const_defined? :Collection
const_set :Collection, collection
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?(method) ⇒ Boolean
25
26
27
|
# File 'lib/active_data/model/collectionizable.rb', line 25
def respond_to? method
super || collection_class.superclass.method_defined?(method)
end
|