<commit_before>= enum_field

* http://github.com/#{github_username}/#{project_name}

== DESCRIPTION:

Enables Active Record attributes to point to enum like objects, by saving in your database
only an integer ID.


== FEATURES:

* Allows creation of Classes with enum like behaviour.
* Allows any number of members and methods in the enum classes.
* Allows an integer id to be used in your database columns to link to the enum members (user.role_id)
* Enables higher abstraction interaction with AR attributes:
  * user.role = Role.admin
  * if user.role.can_edit?
* Saves in your AR tables, only an integer id pointing to the enumeration member.

== SYNOPSIS:

When in an Active Record class, you have an attribute like role, state or country you have
several options.

# You can create a roles, states or countries table, and dump there all possible values.
# You can use a string to identify, for instance, the role.
# You can use an id to identify the role.

If you are not confortable with any of this options, maybe +enum_field+ is an answer for you.

== BASIC USAGE:

  class Role
    define_enum do |builder|
      builder.member :admin
      builder.member :manager
      builder.member :employee
    end
  end

  class User < ActiveRecord::Base
    # in the database table there is a role_id integer column
    enumerated_attribute :role
  end


  link_to_if(current_user.role == Role.admin, edit_foo_path(@foo))

  user.role = Role.manager
  user.role_id == Role.manager.id  #will be true

  User.first.role.id == User.first.role_id  #will be true

Your enum classes can have all the methods you need:

  class PhoneType
    def initialize(name)
      @name = name
    end
    attr_reader :name

    define_enum do |b|
      b.member :home,       :object => PhoneType.new('home')
      b.member :commercial, :object => PhoneType.new('commercial')
      b.member :movile,     :object => PhoneType.new('movile')
    end
  end

  user.phone.type.name

You have some AR like methods in enum classes

  PhoneType.all == [PhoneType.home, PhoneType.commercial, PhoneType.movile]  # ordered all
  PhoneType.first == PhoneType.home
  PhoneType.last == PhoneType.movile

  PhoneType.find_by_id(PhoneType.home.id) == PhoneType.home
  PhoneType.find_by_id(123456) == nil
  PhoneType.find(2) == PhoneType.commercial
  PhoneType.find(123456)  # will raise

== REQUIREMENTS:

* activerecord
* hoe
* rubyforge
<commit_msg>improved readme<commit_after>= enum_field

* http://github.com/paraseba/enum_field

== DESCRIPTION:

Enables Active Record attributes to point to enum like objects, by saving in your database
only an integer ID.


== FEATURES:

* Allows creation of Classes with enum like behaviour.
* Allows any number of members and methods in the enum classes.
* Allows an integer id to be used in your database columns to link to the enum members (user.role_id)
* Enables higher abstraction interaction with +AR+ attributes:
  * <code>user.role = Role.admin</code>
  * <code>if user.role.can_edit?</code>
* Saves in your +AR+ tables, only an integer id pointing to the enumeration member.

== SYNOPSIS:

When in an Active Record class, you have an attribute like role, state or country you have
several options.

* You can create a roles, states or countries table, and dump there all possible values.
* You can use a string to identify, for instance, the role.
* You can use an id to identify the role.

If you are not confortable with any of this options, maybe +enum_field+ is an answer for you.

== BASIC USAGE:

  class Role
    define_enum do |builder|
      builder.member :admin
      builder.member :manager
      builder.member :employee
    end
  end

  class User < ActiveRecord::Base
    # in the database table there is a role_id integer column
    enumerated_attribute :role
  end


  link_to_if(current_user.role == Role.admin, edit_foo_path(@foo))

  user.role = Role.manager
  user.role_id == Role.manager.id  #will be true

  User.first.role.id == User.first.role_id  #will be true

Your enum classes can have all the methods you need:

  class PhoneType
    def initialize(name)
      @name = name
    end
    attr_reader :name

    define_enum do |b|
      b.member :home,       :object => PhoneType.new('home')
      b.member :commercial, :object => PhoneType.new('commercial')
      b.member :movile,     :object => PhoneType.new('movile')
    end
  end

  user.phone.type.name

You have some +AR+ like methods in enum classes

  PhoneType.all == [PhoneType.home, PhoneType.commercial, PhoneType.movile]  # ordered all
  PhoneType.first == PhoneType.home
  PhoneType.last == PhoneType.movile

  PhoneType.find_by_id(PhoneType.home.id) == PhoneType.home
  PhoneType.find_by_id(123456) == nil
  PhoneType.find(2) == PhoneType.commercial
  PhoneType.find(123456)  # will raise

== REQUIREMENTS:

* activerecord
* hoe
* rubyforge

{'fraction_non_alphanumeric': 0.08489594065526479, 'fraction_numerical': 0.00535751081805069, 'mean_word_length': 3.579245283018868, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4456393', 'n_tokens_mistral': 1530, 'n_tokens_neox': 1453, 'n_words': 547}