Skip to content
Rails plugin for enum-esque ActiveRecord fields
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
lib
.gitignore
README.rdoc
init.rb

README.rdoc

FakeId

github.com/trliner/fake_id

Usage

Defining fake ids

class SecretAgentAlias < ActiveRecord::Base
  include FakeId

  attr_accessible :document_type_id

  fake_ids_for :document_type, {
    :drivers_license => 1,
    :passport => 2
  }
end

Generated instance methods

alias = SecretAgentAlias.new(:document_type_id = 1)
alias.document_type
=> :drivers_license

alias.document_type = :passport
alias.document_type
=> :passport

alias.passport?
alias.passport
=> true

alias.drivers_license?
alias.drivers_license
=> false

Generated class methods

SecretAgentAlias.document_types
=> [:drivers_license, :passport]

SecretAgentAlias.document_type_mappings
=> {1=>:drivers_license, 2=>:passport}

SecretAgentAlias.lookup_document_type(1)
=> :drivers_license

SecretAgentAlias.lookup_document_type(:passport)
=> 1

Generated named scopes

SecretAgentAlias.drivers_license
SecretAgentAlias.not_passport
SecretAgentAlias.document_type_is(:drivers_license)
SecretAgentAlias.document_type_is_not(:passport)
SecretAgentAlias.document_type_in(:drivers_license, :passport)
SecretAgentAlias.document_type_not_in(:drivers_license, :passport)
You can’t perform that action at this time.