ActiveEntity
To make an entity with ease according to ActiveModel way.
Installation
Add this line to your application's Gemfile:
gem 'active_entity'
And then execute:
$ bundle
Or install it yourself as:
$ gem install active_entity
Synopsis
class Message
include ActiveModel::Model
include ActiveEntity::Attribute
include ActiveEntity::Identity
attribute :title
attribute :body
identity_attribute :title
validates :title, presence: true, length: { maximum: 255 }
validates :body, presence: true
end
= Message.new(title: 'A README of ActiveEntity')
expect(.valid?).to be_falsy
expect(.errors).to be_a(ActiveModel::Errors)
= Message.new(title: 'A README of ActiveEntity', body: 'No contents!')
expect(.valid?).to be_truthy
expect(.attributes).to eq({ "title" => "A README of ActiveEntity", "body" => "No contents!" })
another_messsage = Message.new(title: 'A README of ActiveEntity', body: '')
expect().to eq(another_messsage)
Contributing
- Fork it ( https://github.com/taiki45/active_entity/fork )
- 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 a new Pull Request