Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hardpixel/active-delegate
Delegate ActiveRecord model attributes and associations.
https://github.com/hardpixel/active-delegate
activerecord delegate rails ruby-gem
Last synced: 3 months ago
JSON representation
Delegate ActiveRecord model attributes and associations.
- Host: GitHub
- URL: https://github.com/hardpixel/active-delegate
- Owner: hardpixel
- License: mit
- Created: 2017-05-29T20:07:34.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2022-05-28T08:00:58.000Z (over 2 years ago)
- Last Synced: 2024-10-31T13:55:00.945Z (3 months ago)
- Topics: activerecord, delegate, rails, ruby-gem
- Language: Ruby
- Homepage:
- Size: 82 KB
- Stars: 11
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# ActiveDelegate
Stores and retrieves delegatable data through attributes on a ActiveRecord class, with support for translatable attributes.
[![Gem Version](https://badge.fury.io/rb/active_delegate.svg)](https://badge.fury.io/rb/active_delegate)
[![Build Status](https://travis-ci.org/hardpixel/active-delegate.svg?branch=master)](https://travis-ci.org/hardpixel/active-delegate)
[![Code Climate](https://codeclimate.com/github/hardpixel/active-delegate/badges/gpa.png)](https://codeclimate.com/github/hardpixel/active-delegate)## Installation
Add this line to your application's Gemfile:
```ruby
gem 'active_delegate'
```And then execute:
$ bundle
Or install it yourself as:
$ gem install active_delegate
## Usage
```ruby
class Address < ActiveRecord::Base
# columns: :city, :district
endclass Person < ActiveRecord::Base
# columns: :name, email, :phone, :address_idinclude ActiveDelegate
belongs_to :address
has_one :user
has_many :booksdelegate_attributes to: :address, prefix: true, localized: true
endparams = {
name: 'John',
email: '[email protected]',
address_city: 'Athens',
address_city_el: 'Αθήνα',
address_district: 'Attiki',
address_district_el: 'Αττική'
}person = Person.new(params)
person.name # 'John'
person.address_city # 'Athens'
person.address.city # 'Athens'
person.address_city_el # 'Αθήνα'
person.address.city_el # 'Αθήνα'
person.address_district # 'Attiki'
person.address.district # 'Attiki'
person.address_district_el # 'Αττική'
person.address.district_el # 'Αττική'class User < ActiveRecord::Base
# columns: :login, :password, :person_idinclude ActiveDelegate
belongs_to :person, autosave: true
delegate_associations to: :person
delegate_attributes to: :person
endparams = {
login: 'jonian',
password: 'passwd',
name: 'John',
email: '[email protected]'
}user = User.new(params)
user.name # 'John'
user.login # 'jonian'
user.user # @user
user.books # []user.email # '[email protected]'
user.email? # true
user.email_changed? # true
user.email_was # nil
```## Development
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment. To install this gem onto your local machine, run `bundle exec rake install`.
## Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/hardpixel/active-delegate.
## License
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).