Class: MongoMapperSweatShop::SweatShop
- Inherits:
-
Object
- Object
- MongoMapperSweatShop::SweatShop
- Defined in:
- lib/mongomapper-sweatshop/sweatshop.rb
Defined Under Namespace
Classes: NoFixtureError
Constant Summary collapse
- @@models =
the model to fixture map
{}
Instance Attribute Summary collapse
-
#models ⇒ Hash
Hash of models to scopes and their lazily loaded attributes.
Class Method Summary collapse
-
.[](klass, name = :default, overrides = {}) ⇒ Mixed
Gets a fixture.
-
.[]=(klass, name = :default, proc) ⇒ Proc
Stores a fixture.
Instance Attribute Details
#models ⇒ Hash
Returns Hash of models to scopes and their lazily loaded attributes.
8 |
# File 'lib/mongomapper-sweatshop/sweatshop.rb', line 8 @@models = {} |
Class Method Details
.[](klass, name = :default, overrides = {}) ⇒ Mixed
Gets a fixture
28 29 30 31 32 33 34 |
# File 'lib/mongomapper-sweatshop/sweatshop.rb', line 28 def [] klass, name=:default, overrides={} overrides, name = name, :default if name.is_a? Hash @@models[klass][name].last.call.merge(overrides) rescue NoFixtureError puts "A fixture with that name has not been defined, using the default" @@models[klass][:default].last.call.merge(overrides) end |
.[]=(klass, name = :default, proc) ⇒ Proc
Stores a fixture
19 20 21 |
# File 'lib/mongomapper-sweatshop/sweatshop.rb', line 19 def []= klass, name=:default, proc ((@@models[klass] ||= {})[name] ||= []) << proc end |