Undo

Build Status Gemnasium Build Status Coverage Status Gem Version

ActiveModel serializer for Undo gem.

Designed to be used with gem "active_model_serializers", but does not depends on it.

Contents

  1. Installation
  2. Requirements
  3. Contacts
  4. Compatibility
  5. Contributing
  6. Copyright

Installation

Add this line to your application's Gemfile:

gem 'undo-serializer-active_model'

And then execute:

$ bundle

Or install it yourself as:

$ gem install undo-serializer-active_model

Requirements

  1. Ruby >= 1.9
  2. activesupport (active_model_serializers depends on it)

Usage

Gem is designed to be used with Undo gem.
Add it in global config:

Undo.configure do |config|
  config.serializer = Undo::Serializer::ActiveModel.new
end

Custom serializer could be provided to the adapter:

Undo.configure do |config|
  config.serializer = 
    Undo::Serializer::ActiveModel.new serializer: ->(object) { "#{object.class.name}UndoSerializer".constantize.new(object) }
end

Or it may be initialized by serializer instance:

Undo.configure do |config|
  config.serializer = 
    Undo::Serializer::ActiveModel.new CustomSerializer.new
end

As usual any Undo configuration may be set in place on wrap and restore:

Undo.wrap user, serializer: Undo::Serializer::ActiveModel.new
Undo.restore uuid, serializer: Undo::Serializer::ActiveModel.new

In place using the specific serializer from gem "active_model_serializers":

Undo.wrap user, serializer: Undo::Serializer::ActiveModel.new(UserSerializer.new(user))

Associations

It is required to set somethig___association_class_name as key in active_model_serializer:

class UserSerializer < ActiveModel::Serializer
  attributes *User.attribute_names.map(&:to_sym)
  has_many :roles, key: :has_many___roles
end

Contacts

Have questions or recommendations? Contact me via [email protected]

Found a bug or have enhancement request? You are welcome at Github bugtracker

Compatibility

tested with Ruby

  • 2.1
  • 2.0
  • 1.9.3
  • ruby-head
  • rbx-2
  • jruby-19mode
  • jruby-head

See build history

Contributing

  1. Fork repository ( http://github.com/AlexParamonov/undo-serializer-active_model/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Copyright © 2014 Alexander Paramonov.
Released under the MIT License. See the LICENSE file for further details.