An ActiveModel implementation that make easier to handle model which will be serialized in a real model.
support attribute:
- all types that
ActiveModel::Type
support - typed array
- enum
- embeds one
class Person < OptionsModel::Base
attribute :name, :string
attribute :age, :integer
validates :name, presence: true
end
class Book < OptionsModel::Base
embeds_one :author, class_name: 'Person'
attribute :title, :string
attribute :tags, :string, array: true
attribute :price, :decimal, default: 0
attribute :bought_at, :datetime, default: -> { Time.new }
validates :title, presence: true
end
Add this line to your application's Gemfile:
gem 'options_model'
And then execute:
$ bundle
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request
Please write unit test with your code if necessary.
The gem is available as open source under the terms of the MIT License.