https://github.com/jasl-lab/options_model
An ActiveModel implementation that make easier to handle model which will be serialized in a real model.
https://github.com/jasl-lab/options_model
Last synced: over 1 year ago
JSON representation
An ActiveModel implementation that make easier to handle model which will be serialized in a real model.
- Host: GitHub
- URL: https://github.com/jasl-lab/options_model
- Owner: jasl-lab
- License: mit
- Created: 2017-07-15T07:35:32.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2023-03-08T19:46:07.000Z (over 3 years ago)
- Last Synced: 2024-04-25T12:03:29.022Z (over 2 years ago)
- Language: Ruby
- Size: 104 KB
- Stars: 2
- Watchers: 2
- Forks: 2
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: MIT-LICENSE
Awesome Lists containing this project
README
# OptionsModel
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
## Usage
```ruby
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
```
## Installation
Add this line to your application's Gemfile:
```ruby
gem 'options_model'
```
And then execute:
```bash
$ bundle
```
## Contributing
1. Fork it
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
Please write unit test with your code if necessary.
## License
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).