README.rdoc in enumerate_it-1.1.1 vs README.rdoc in enumerate_it-1.2.0

- old
+ new

@@ -81,11 +81,11 @@ RelationshipStatus.value_for("MARRIED") # 2 * You can retrieve the symbol used to declare a specific enumeration value: - RelationshipStatus.key_for(RelationshioStatus::MARRIED) # :married + RelationshipStatus.key_for(RelationshipStatus::MARRIED) # :married * You can iterate over the list of the enumeration's values: RelationshipStatus.each_value { |value| # ... } @@ -194,9 +194,47 @@ p = Person.new p.relationship_status = RelationshipStatus::MARRIED p.relationship_status_married? #=> true p.relationship_status_divoced? #=> false + +* You can define polymorphic behavior for the enum values, so you can define a class for each of + them: + + class RelationshipStatus < EnumerateIt::Base + associate_values :married, :single + + class Married + def saturday_night + "At home with the kids" + end + end + + class Single + def saturday_night + "Party Hard!" + end + end + end + + class Person < ActiveRecord::Base + has_enumeration_for :relationship_status, :with => RelationshipStatus, :create_helpers => { :polymorphic => true } + end + + p = Person.new + p.relationship_status = RelationshipStatus::MARRIED + p.relationship_status_object.saturday_night # => "At home with the kids" + + p.relationship_status = RelationshipStatus::SINGLE + p.relationship_status_object.saturday_night # => "Party Hard!" + + You can also change the suffix '_object', using the :suffix option: + + class Person < ActiveRecord::Base + has_enumeration_for :relationship_status, :with => RelationshipStatus, :create_helpers => { :polymorphic => { :suffix => "_mode" } } + end + + p.relationship_status_mode.saturday_night * The :create_helpers also creates some mutator helper methods, that can be used to change the attribute's value. class Person < ActiveRecord::Base has_enumeration_for :relationship_status, :with => RelationshipStatus, :create_helpers => true