Readme.md in enumify-0.0.7 vs Readme.md in enumify-0.1.0

- old
+ new

@@ -10,18 +10,31 @@ gem 'enumify' ``` ## How to use -Just call the enum function in any ActiveRecord object, the function accepts the field name as the first variable and the possible values as an array +Just call the `enum` function in any ActiveRecord object, the function accepts the field name as the first variable and the possible values as an array ```ruby class Event < ActiveRecord::Base enum :status, [:available, :canceled, :completed] end ``` +## Rails 4.1+ + +You can also instantiate a _Enumify_ enum by calling the `enumify` method instead of `enum`. +This is especially helpful when your app is running Rail 4.1 or better which has it's own built in enum (although not as good) + +```ruby +class Event < ActiveRecord::Base + enumify :status, [:available, :canceled, :completed] +end +``` + +## Usage + After that you get several autogenerated commands to use with the enum ```ruby # Access through field name @@ -49,9 +62,23 @@ end Event.create! # Is valid and does not throw an exception. ``` +#### :prefix +By default all enum values are available as scopes, bang and query methods based on the value. +You can add a prefix for the enum values in order to differentiate different enums on the same object. + +```ruby +class Event < ActiveRecord::Base + enum :status, [:available, :canceled, :completed], :prefix => true + enum :subtype, [:company, :personal], :prefix => 'type' +end + +event.available? # Not available anymore +event.status_available? # when prefix true +event.type_company? # you can set a specific name for your prefix +``` ## Callbacks Another cool feature of enumify is the option to add a callback function that will be called each time the value of the field changes This is cool to do stuff like log stuff or create behaviour on state changes