README.rdoc in enumerate_it-0.7.17 vs README.rdoc in enumerate_it-1.0.0

- old
+ new

@@ -37,10 +37,19 @@ And, more than this, referencing them in my code using magic numbers was terrible and meaningless: What does it mean when we say that someone or something is '2'? Enter EnumerateIt. +== Documentation + +http://rubydoc.info/gems/enumerate_it/1.0.0/frames + +== About versions compatibility + +Versions 1.x.x are NOT backwards compatible with 0.x.x versions. The biggest difference is that on 1.0.0 you need to `extend` the EnumerateIt +module inside classes that are going to have enumerated attributes, while in past versions you would use `include`. + == Creating enumerations Enumerations are created as models, but you can put then anywhere in your application. In Rails applications, you can put them inside models/. @@ -82,11 +91,11 @@ * You can iterate over the list of the enumeration's values: RelationshipStatus.each_value { |value| # ... } -* You can iterate over the list of the enumeration's translations: +* You can iterate over the list of the enumeration's translations: RelationshipStatus.each_translation { |translation| # ... } * You can ask for the enumeration's length: @@ -117,11 +126,11 @@ The cool part is that you can use these enumerations with any class, be it an ActiveRecord instance or not. class Person - include EnumerateIt + extend EnumerateIt attr_accessor :relationship_status has_enumeration_for :relationship_status, :with => RelationshipStatus end @@ -131,11 +140,11 @@ * A humanized description for the values of the enumerated attribute: p = Person.new p.relationship_status = RelationshipStatus::DIVORCED - p.relationsip_status_humanize # => 'Divorced' + p.relationship_status_humanize # => 'Divorced' * If you don't supply a humanized string to represent an option, EnumerateIt will use a 'humanized' version of the hash's key to humanize the attribute's value: class RelationshipStatus < EnumerateIt::Base associate_values( @@ -161,11 +170,11 @@ p = Person.new p.relationship_status = RelationshipStatus::MARRIED p.married? #=> true p.divorced? #=> false -* It's also possible to "namespace" the created helper methods, passing a hash to the :create_helpers option. +* It's also possible to "namespace" the created helper methods, passing a hash to the :create_helpers option. This can be useful when two or more of the enumerations used share the same constants. class Person < ActiveRecord::Base has_enumeration_for :relationship_status, :with => RelationshipStatus, :create_helpers => { :prefix => true } end @@ -192,11 +201,11 @@ has_enumeration_for :relationship_status, :with => RelationshipStatus, :create_scopes => true end Person.married.to_sql # => SELECT "people".* FROM "people" WHERE "people"."relationship_status" = 1 -NOTE: The :create_scopes option can only be used for Rails.version >= 3.0.0. +NOTE: The :create_scopes option can only be used for Rails.version >= 3.0.0. * If your class can manage validations and responds to :validates_inclusion_of, it will create this validation: class Person < ActiveRecord::Base has_enumeration_for :relationship_status, :with => RelationshipStatus @@ -259,11 +268,11 @@ == Using with Rails * Create an initializer with the following code: - ActiveRecord::Base.send :include, EnumerateIt + ActiveRecord::Base.extend EnumerateIt * Add the 'enumerate_it' gem as a dependency in your environment.rb (Rails 2.3.x) or Gemfile (if you're using Bundler) An interesting approach to use it in Rails apps is to create an app/enumerations folder and add it to your autoload path in config/application.rb: @@ -271,10 +280,10 @@ class Application < Rails::Application config.autoload_paths << "#{Rails.root}/app/enumerations" end end -There is also a Rails Generator that you can use to generate enumerations and their locale files. Take a look at how to use it running +There is also a Rails Generator that you can use to generate enumerations and their locale files. Take a look at how to use it running rails generate enumerate_it --help == Ruby 1.9