No commit activity in last 3 years
No release in over 3 years
An additional attr macro for default values.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Development

~> 1.5
>= 0
>= 0
 Project Readme

Circle CI Coverage Status Code Climate

AttrDefaultable

Easily add attributes with default values to your classes.

Installation

Add this line to your application's Gemfile:

gem 'attr_defaultable'

To optionally slip attr_defaultable into Module so it is available without extending:

gem 'attr_defaultable', require: 'extend_attr_defaultable'

And then execute:

$ bundle

Or install it yourself as:

$ gem install attr_defaultable

Usage

class Example
  extend AttrDefaultable
  attr_defaultable :foo, -> { 'bar' }
end

This will create a getter/setter pair for your variable foo. If the setter is not used before the getter the proc given will be called and it's result used to set the value of foo.

Very useful for creating dependency definitions with protected default values that are evaluated just in time.

Alternate Usage

By using the alternate gem declaration in your Gemfile or manually requiring extend_attr_defaultable early in your application, you can avoid the explicit extend in your class.

class Example
  attr_defaultable :foo, -> { 'bar' }
end

Contributing

  1. Fork it ( http://github.com/Originate/attr_defaultable/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 new Pull Request