Class: Gamifier::Collection
- Inherits:
-
Object
- Object
- Gamifier::Collection
- Includes:
- Model::FinderMethods
- Defined in:
- lib/gamifier/collection.rb
Instance Attribute Summary collapse
-
#engine ⇒ Object
Returns the value of attribute engine.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
Instance Method Summary collapse
- #build(entry) ⇒ Object
-
#initialize(engine, model) ⇒ Collection
constructor
A new instance of Collection.
- #path ⇒ Object
- #reset!(params = {}) ⇒ Object
Methods included from Model::FinderMethods
#all, #find, #find_by, #find_by_label, #find_by_name, #find_or_create
Constructor Details
#initialize(engine, model) ⇒ Collection
Returns a new instance of Collection.
14 15 16 17 18 |
# File 'lib/gamifier/collection.rb', line 14 def initialize(engine, model) @engine = engine @model = model self.extend model::FinderMethods end |
Instance Attribute Details
#engine ⇒ Object
Returns the value of attribute engine.
7 8 9 |
# File 'lib/gamifier/collection.rb', line 7 def engine @engine end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
8 9 10 |
# File 'lib/gamifier/collection.rb', line 8 def model @model end |
Instance Method Details
#build(entry) ⇒ Object
20 21 22 23 24 |
# File 'lib/gamifier/collection.rb', line 20 def build(entry) instance = model.new(entry) instance.engine = engine instance end |
#path ⇒ Object
10 11 12 |
# File 'lib/gamifier/collection.rb', line 10 def path model.path end |
#reset!(params = {}) ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/gamifier/collection.rb', line 26 def reset!(params = {}) unless params.has_key?(:site) raise ArgumentError, "A :site parameter is required. Pass nil if you really want to delete all the objects of this kind, on all the sites." end all(params) do |entry| entry.destroy end end |