ActiveModelCoercions

Currently, it's just an experimental coercion proof of concept for ActiveModel objects. However if you see some areas of improvement or want to discuss some stuff - feel free to open an issue/pull request.

Installation

Add this line to your application's Gemfile:

gem 'active_model_coercions'

And then execute:

$ bundle

Or install it yourself as:

$ gem install active_model_coercions

Usage

class TestModel
  include ActiveModel::Model
  include ActiveModel::Coercions


  attr_accessor :number, :date, :state

  attribute :number, :integer
  attribute :state, :symbol

end
params = {number: '1', state: 'active'}
model = TestModel.new(params)

model.number # => 1
model.state # => :active
model.attributes # => {number: 1, state: :active}

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b feature-branch)
  3. Commit your changed (git commit -a -m 'Add some changes')
  4. Push feature branch to github (git push origin feature-branch)
  5. Create pull request

License

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