Sha256: 0aa141b2cb05bf584cdcd67a9e67ce3a7820de53e9634005f61c95c8362dee4f

Contents?: true

Size: 931 Bytes

Versions: 6

Compression:

Stored size: 931 Bytes

Contents

= EnumField

Macro to emulate a MySQL enum_field type thing.

== Usage

This plugin encapsulates a validates_inclusion_of and automatically gives you a 
few more goodies automatically. That's it!

    class Computer < ActiveRecord:Base
      enum_field :status, ['on', 'off', 'standby', 'sleep', 'out of this world']

      # Optionally with a message to replace the default one
      # enum_field :status, ['on', 'off', 'standby', 'sleep', 'out of this world'], :message => "incorrect status"

      #...
    end

This will give you a few things:

- add a validates_inclusion_of with a simple error message ("invalid #{field}") or your custom message
- define the following query methods, in the name of expressive code:
  - on?
  - off?
  - standby?
  - sleep?
  - out_of_this_world?
- define the STATUSES constant, which contains the acceptable values

= License

Copyright (c) 2008 James Golick, released under the MIT license

Version data entries

6 entries across 6 versions & 3 rubygems

Version Path
daeltar-enum_field-0.2.0 README.rdoc
giraffesoft-enum_field-0.1.1 README.rdoc
giraffesoft-enum_field-0.2.0 README.rdoc
markcatley-enum_field-0.1.1.0.1 README.rdoc
markcatley-enum_field-0.2.0.1 README.rdoc
daeltar-enum_field-0.2.1 README.rdoc