Extant
Sponsored by NCC Group Domain Services
Extant provides attribute management for Ruby objects. It is somewhat similar to
attr_accessor
, except it does many additional things like, type coercion,
change tracking (dirty attributes), and most importantly tracking of existence.
Installation
$ gem install extant
or in your Gemfile
gem 'extant'
Getting Started
class Widget
include Extant::Attributes
attribute :name, String
attribute :price, Integer
attribute :production_ready, Extant::Coercers::Boolean, default: false
end
Basic Usage
= Widget.new(
name: 'Doodad',
price: 100
)
.name # => 'Doodad'
.price # => 100
.production_ready # => false
.attributes # => { name: 'Doodad', price: 100, production_ready: false }
Coercion
= Widget.new(
price: 'not a number'
)
.extant_attributes[:price].coerced? # => false
.price # => nil
.extant_attributes[:price].pre_coerce_value # => 'not a number'
Existence
= Widget.new
.name # => nil
.extant_attributes[:name].set? # => false
= Widget.new(
name: nil
)
.name # => nil
.extant_attributes[:name].set? # => true
.extant_attributes[:name].coerced? # => true
Contributing
- Fork
- Make changes
- Pull request
- Celebrate