module LunaPark::Extensions::DataMapper

@example

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

Public Class Methods

included(base) click to toggle source
# File lib/luna_park/extensions/data_mapper.rb, line 39
def self.included(base)
  base.extend ClassMethods
  base.include InstanceMethods
end