Module: Yogo::Collection::Base

Includes:
CollectionRepository::InstanceMethods, ModelConfiguration
Included in:
Data
Defined in:
lib/yogo/collection/base.rb,
lib/yogo/collection/base/model.rb,
lib/yogo/collection/base/model_configuration.rb,
lib/yogo/collection/base/collection_repository.rb,
lib/yogo/collection/base/model_collection_context.rb

Defined Under Namespace

Modules: CollectionRepository, Model, ModelCollectionContext, ModelConfiguration

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ModelConfiguration

#after_model_generate, #after_model_update, #before_model_generate, #before_model_update, #model_generate, #model_update

Methods included from CollectionRepository::InstanceMethods

#collection_repository, #collection_repository_name

Class Method Details

.included(base) ⇒ Object



10
11
12
# File 'lib/yogo/collection/base.rb', line 10

def self.included(base)
  base.extend(Base::CollectionRepository)
end

Instance Method Details

#as_json(options = {}) ⇒ Object



21
22
23
# File 'lib/yogo/collection/base.rb', line 21

def as_json(options={})
  self.attributes
end

#collection_storage_nameObject



17
18
19
# File 'lib/yogo/collection/base.rb', line 17

def collection_storage_name
  self.id.to_s
end

#data_modelObject



31
32
33
# File 'lib/yogo/collection/base.rb', line 31

def data_model
  @_data_model ||= generate_model
end

#items(*args) ⇒ Object



25
26
27
28
29
# File 'lib/yogo/collection/base.rb', line 25

def items(*args)
  scope do
    data_model.all(*args)
  end
end

#scopeObject



46
47
48
49
50
51
52
53
54
55
# File 'lib/yogo/collection/base.rb', line 46

def scope
  context = Yogo::Collection.context
  context << self
  
  begin
    yield self
  ensure
    context.pop
  end
end

#update_model(model = data_model) ⇒ Object



35
36
37
38
39
40
41
42
43
44
# File 'lib/yogo/collection/base.rb', line 35

def update_model(model=data_model)
  scope do
    before_model_update(model)
    model_update(model)
    if block_given?
      yield
    end
    after_model_update(model)
  end
end