0.0
No commit activity in last 3 years
No release in over 3 years
Simple Object-to-Object mapper
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 2.0
~> 0.12
~> 10.0
~> 3.0

Runtime

~> 1.1
 Project Readme

WIP: Mimi::Struct

Object to Object mapper.

Allows you to map a PORO, Struct, OpenStruct or a Hash into a simple Ruby object with predefined schema and transformation rules.

Usage

require "mimi/struct"

class Customer < Mimi::Struct
  attribute :id
  attribute :type, using: -> (o) { o.type.to_s.upcase }

  group if: -> (o) { o.type == :person } do
    attribute :first_name, from: :firstName
    attribute :last_name, from: :lastName
  end

  group if: -> (o) { o.type == :company } do
    attribute :company_name
  end

  attribute :created_at, default: -> { Time.now.utc }
  attribute :updated_at, default: -> { Time.now.utc }
end

customer = Customer << { id: "person1", type: :person, firstName: "John", lastName: "Smith" }

puts customer.to_h
# {
#   :id=>"person1", :type=>"PERSON", :first_name=>"John", :last_name=>"Smith",
#   :created_at=>2019-06-23 16:07:30 UTC, :updated_at=>2019-06-23 16:07:30 UTC
# }

Defining your Mimi::Struct schema

:from

:using

:default

:if

:optional

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/kukushkin/mimi-struct. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the Mimi::Struct project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.