0.0
No commit activity in last 3 years
No release in over 3 years
This rubygem does not have a description or summary.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Development

 Project Readme

Spine::Mappings

Gem Version Dependency Status Test Coverage Code Climate security Inline docs Codeship Status for rspine/mappings

Maps object to hashes using DSL. You can give different namespaces for mappings by extending module or class with Spine::Mappings::Repository.

Installation

To install it, add the gem to your Gemfile:

gem 'spine-mappings'

Then run bundle. If you're not using Bundler, just gem install spine-mappings.

Usage

Spine::Mappings.define :tag do
  integer :id, from: identity
  string :name
end

Spine::Mappings.define :product do
  integer :id, from: :identity
  string :name
  decimal :price
  boolean :is_available, { |source| source.available? }
  date :available_from
  date :available_until
  tag :tags, nullable: true
end

Spine::Mapings.define :timestamps do
  timestamp :created_at
  timestamp :updated_at
end

Spine::Mappings.find(:product, :timestamps).map(product)

Spine::Mappings.find(:product, :timestamps).map_all(products)

You can provide also compact or strict strategy for mapping. First adds value only when it is not nil, second adds everything what was defined. Default is strict.

Spine::Mappings.find(:product, :timestamps).map(product, strategy: :compact)