Project

boxey

0.0
No commit activity in last 3 years
No release in over 3 years
Boxey provides the [] element reference operator to ActiveRecord classes. # Installation Add this line to your Gemfile: `gem 'boxey'` # Configuration With the boxey gem installed, all ActiveRecord classes gain the [] method, which fetches by the class's primary_key by default. You may specify additional fields, presumably fields that validate uniqueness, by calling the boxey method. class User < ActiveRecord::Base boxey :id, :login, :email validates :login, uniqueness: true validates :email, uniqueness: true end # Use Given the configuration above: `User[1]` returns the first User with an id (or login or email) of `1`. `User['me@example.com']` returns the first User with an email (or id or login) of `'me@example.com'`. `[]` returns `nil` if no match is found.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

 Project Readme

Boxey provides the [] element reference operator to ActiveRecord classes.

Installation

Add this line to your Gemfile:

gem 'boxey'

Configuration

With the boxey gem installed, all ActiveRecord classes gain the [] method.

By default, [] fetches by the class's primary_key and any other fields that are validated by uniqueness (unless the validation has if conditions).

Optionally, you may explicitly specify the fields to query and their relative priority by calling the boxey method.

class User < ActiveRecord::Base
  boxey :id, :login, :email
  validates :login, uniqueness: true
  validates :email, uniqueness: true
end

Use

Given the configuration above:

User[1] returns the User with an id of 1.

User['me@example.com'] returns the User with an email of 'me@example.com'.

[] returns nil if no match is found.