Releases: octoopi/enumbler
Releases · octoopi/enumbler
Fix chicken before egg warning with pending migrations
0.9.1 Fix chicken before egg error with pending migrations 0.9.1
Check for conflicting method names when enabling a model
0.8.1 Add error when dynamic method naming conflict exists 0.8.1
Added .find_by_enumble method
0.8.0 Added .find_by_enumble 0.8.0
Allow database column :label to *not* be the enumbler's label
This change allows you to have a database column :label
that you do not want to use at the Enumble#label
.
Added additional attribute helpers for enumbled_to records
house = House.create!(color: Color.black)
house.color_label # => 'black'
house.color_enum # => :black
house.color_graphql_enum # => 'BLACK'
Adding .find_enumbles class methods
Still a work in progress on this concept but wanted a flexible way to extract the label
, enum
, id
, values from an enabled class.
# Get an Enumble object from an id, label, enum, or ActiveRecord model
Color.find_enumbles(:black, 'white') # => [Enumbler::Enumble<:black>, Enumbler::Enumble<:white>]
Color.find_enumbles(:black, 'does-not-exist') # => [Enumbler::Enumble<:black>, nil]
Color.find_enumble(:black) # => Enumbler::Enumble<:black>
# raises errors if none found
Color.find_enumbles!!(:black, 'does-no-exist') # => raises Enumbler::Error
Color.find_enumble!(:does_not_exist) # => raises Enumbler::Error
# Get ids flexibly, without raising an error if none found
Color.ids_from_enumbler(:black, 'white') # => [1, 2]
Color.ids_from_enumbler(:black, 'does-no-exist') # => [1, nil]
# Raise an error if none found
Color.ids_from_enumbler!(:black, 'does-no-exist') # => raises Enumbler::Error
Color.id_from_enumbler!(:does_not_exist) # => raises Enumbler::Error
Added additional singleton magic
Added ability to get an attribute of an Enumbled record.
Color.black(:id) # => 1
Color.black(:enum) # => :black
Color.black(:label) # => 'black'
Color.black(:graphql_enum) # => 'BLACK'
Added class method enumber_label_column_name
Used when your database has a column with a name other than label
.
Added .id_from_enumbler method
Added singular version of the .ids_from_enumbler
method.
Renamed ids_from_enumablable
Renamed .ids_from_enumablable
to .ids_from_enumbler
. Not sure what happened with the first attempt at naming that.