Popularity
0.8
Stable
Activity
0.0
Declining
11
4
0

Description

Stores and retrieves delegatable data through attributes on a ActiveRecord class, with support for translatable attributes.

Monthly Downloads: 455
Programming language: Ruby
License: MIT License
Tags: Attributes     Rails     Active Record    
Latest version: v1.0.8

ActiveDelegate alternatives and similar gems

Based on the "Attributes" category.
Alternatively, view ActiveDelegate alternatives based on common mentions on social networks and blogs.

Do you think we are missing an alternative of ActiveDelegate or a related project?

Add another 'Attributes' Gem

README

ActiveDelegate

Stores and retrieves delegatable data through attributes on a ActiveRecord class, with support for translatable attributes.

Gem Version Build Status Code Climate

Installation

Add this line to your application's Gemfile:

gem 'active_delegate'

And then execute:

$ bundle

Or install it yourself as:

$ gem install active_delegate

Usage

class Address < ActiveRecord::Base
  # columns: :city, :district
end

class Person < ActiveRecord::Base
  # columns: :name, email, :phone, :address_id

  include ActiveDelegate

  belongs_to :address
  has_one    :user
  has_many   :books

  delegate_attributes to: :address, prefix: true, localized: true
end

params = {
  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_id

  include ActiveDelegate

  belongs_to :person, autosave: true

  delegate_associations to: :person
  delegate_attributes   to: :person
end

params = {
  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.


*Note that all licence references and agreements mentioned in the ActiveDelegate README section above are relevant to that project's source code only.