No commit activity in last 3 years
No release in over 3 years
Simple null objects in Active Record
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0
>= 3.0.0

Runtime

>= 4.2.0.rc3
>= 4.2.0.rc3
 Project Readme

Active Null Object

Gem Version Build Status Code Climate Test Coverage

Instead of returning nil when an association is not found, return a Null Object.

Associations

# Automatically searches for the Null Object based on the association name (NullUser)...
belongs_to :user, null_object: true

# ...or pass explicit class name.
belongs_to :user, null_object: 'NullAdmin'

Finder

# Use a specialized finder if you want a Null Object if the record is not found.
User.find_or_null_object(1)

# ...or pass explicit class name.
User.find_or_null_object(1, null_object: 'NullAdmin')