Module: LunaPark::Extensions::DataMapper

Included in:
Repository
Defined in:
lib/luna_park/extensions/data_mapper.rb

Overview

Examples:

class ProductRepository
  include LunaPark::Extensions::DataMapper

  entity Product
  mapper ProductMapper

  def find(id)
    read_one products.where(id: id)
  end

  def all
    read_all products
  end

  def save(input)
    entity = wrap(input)
    row    = to_row(entity)
    new_row   = products.where(id: entity.id).update(row)
    new_attrs = from_row(new_row)
    entity.set_attributes(new_attrs)
    entity
  end

  private

  # Common dataset method is usefull for extensions
  def dataset
    SEQUEL_CONNECTION[:products]
  end

  alias products dataset
end

Defined Under Namespace

Modules: ClassMethods, InstanceMethods

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object



39
40
41
42
# File 'lib/luna_park/extensions/data_mapper.rb', line 39

def self.included(base)
  base.extend ClassMethods
  base.include InstanceMethods
end