No commit activity in last 3 years
No release in over 3 years
Calling a delegated method on a nil object with better_delegation won't just return nil, it will return the default column value as specified by object being delegated to.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

>= 1.0
 Project Readme

better_delegation¶ ↑

Better method delegation for ActiveRecord. Specifically when it comes to handling ‘nil’ objects.

While Rails does support method delegation to a nil object, it will always return ‘nil’ if the object delegated to is nil.

This gem will return whatever the object delegated to would return. It’s especially useful for example when you have a method that would typically return ‘false’ (because that’s what the database column default is set to). For example an ‘is_active` method might return false by default. When the delegating object calls `is_active` on a nil object, the nil object would return ’false’, not nil.

Note on Patches/Pull Requests¶ ↑

  • Fork the project.

  • Make your feature addition or bug fix.

  • Add tests for it. This is important so I don’t break it in a future version unintentionally.

  • Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but

    bump version in a commit by itself I can ignore when I pull)
  • Send me a pull request. Bonus points for topic branches.

Copyright © 2009 Josh N. Abbott. See LICENSE for details.