Class: Gamifier::Collection

Inherits:
Object
  • Object
show all
Includes:
Model::FinderMethods
Defined in:
lib/gamifier/collection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#engineObject

Returns the value of attribute engine.



7
8
9
# File 'lib/gamifier/collection.rb', line 7

def engine
  @engine
end

#modelObject (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

#pathObject



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