Module: Candy::Collection::ClassMethods
- Includes:
- Candy::Crunch::ClassMethods
- Defined in:
- lib/candy/collection.rb
Instance Attribute Summary collapse
-
#_candy_piece ⇒ Object
readonly
Returns the value of attribute _candy_piece.
Instance Method Summary collapse
- #all(options = {}) ⇒ Object
-
#collects(collection, piece = nil) ⇒ Object
Sets the collection that all queries run against.
- #method_missing(name, *args, &block) ⇒ Object
Methods included from Candy::Crunch::ClassMethods
#collection, #collection=, #connection, #connection=, #db, #db=, #index, #password, #password=, #username, #username=
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
34 35 36 37 |
# File 'lib/candy/collection.rb', line 34 def method_missing(name, *args, &block) coll = self.new coll.send(name, *args, &block) end |
Instance Attribute Details
#_candy_piece ⇒ Object (readonly)
Returns the value of attribute _candy_piece.
17 18 19 |
# File 'lib/candy/collection.rb', line 17 def _candy_piece @_candy_piece end |
Instance Method Details
#all(options = {}) ⇒ Object
30 31 32 |
# File 'lib/candy/collection.rb', line 30 def all(={}) self.new() end |
#collects(collection, piece = nil) ⇒ Object
Sets the collection that all queries run against. You can also specify a class that includes Candy::Piece that will be instantiated for all found records. Otherwise the collection name is used as a default, and CandyHash is a fallback.
23 24 25 26 27 28 |
# File 'lib/candy/collection.rb', line 23 def collects(collection, piece = nil) collectible = camelcase(collection) piecemeal = namespace + (piece ? camelcase(piece) : collectible) self.collection = collectible @_candy_piece = Kernel.qualified_const_get(piecemeal) || CandyHash end |