0.0
Repository is archived
No commit activity in last 3 years
No release in over 3 years
ActiveRecord plugin to load specified attributes lazyly
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

< 5, >= 3.2
 Project Readme

LazyAttributes

lazy_attributes is an ActiveRecord plugin. lazy_attributes loads lazily specified attributes.

Build Status Gem Version

This gem is heavily inspired by lazy_columns.

Supported versions

ActiveRecord 3.2, 4.0, and 4.1

Installation

Add this line to your application's Gemfile:

gem 'lazy_attributes'

And then execute:

$ bundle

Or install it yourself as:

$ gem install lazy_attributes

Usage

In Active Record model, specify attributes that are needed to be loaded lazyly with lazy_attributes:

class User < ActiveRecord::Base
  lazy_attributes :profile
  lazy_attributes :address, :bio
end

When model with lazyly-loaded attributes is associated with another model, you need specify scope for association with '.column_symbols_without_lazy'.

class Group < ActiveRecord::Base
  has_many :users, { select(User.column_symbols_without_lazy) }
end

For Rails 3.2, use select option.

class Group < ActiveRecord::Base
  has_many :users, select: User.column_symbols_without_lazy
end

Contributing

  1. Fork it ( https://github.com/[my-github-username]/lazy_attributes/fork )
  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 a new Pull Request