= active_finite == What is active_finite? The goal of active_finite is to provide a simple way to define database enumerations with ActiveRecord. There are many[https://github.com/ikspres/enum_fu] existing[https://github.com/adzap/active_enum] projects[https://github.com/jeffp/enumerated_attribute] that bring some enum support to ActiveRecord. However, these projects tend to define the enums in code, instead of in the migration itself. == Hello, active_finite! Let's start by defining a simple migration: require 'active_finite' require 'active_record' require 'active_support/core_ext' class Hellos < ActiveRecord::Migration self.up add_finites in_table: :hellos, values: ['oy', 'que tal', 'hi'] end self.down delete_finites in_table: :hellos, values: ['oy', 'que tal', 'hi'] end end Now that we some hellos in our Hello model, we can access them using: hellos = get_table :hellos The variable hellos now holds a class derived from ActiveRecord named Hello, so all of the normal ActiveRecord methods can be used. We can also a collection of all of the active record classes defined by active_finite by using: all_finite_tables Using get_table and all_finite_tables implicitly bring the associated classes into scope, so a single call to all_finite_tables is sufficent to define all of the models. == Other options If the column name must be different than the default, the column_name option can be used. Also, a json file can be used instead of explicitly listing the possible values in the migration. For example: require 'active_finite' require 'active_record' require 'active_support/core_ext' class HellosWithCustomColumn < ActiveRecord::Migration self.up add_finites in_table: :hellos, values: ['oy', 'que tal', 'hi'] column_name: :custom from_file: 'hellos.json' end self.down delete_finites in_table: :hellos, values: all end end If both values and from_file are defined, active_finite will pull entries from both. Another option to be aware of is that values do not have to be explicitly listed upon deletion, using the all option is sufficent. == Other ideas Combine active_finite with foreigner[https://github.com/matthuhiggins/foreigner] to put foreign key constraints on users of defined enums. == Contributing to active_finite * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it * Fork the project * Start a feature/bugfix branch * Commit and push until you are happy with your contribution * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally. * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it. == Contact me@stuffivemade.com == Copyright Copyright (c) 2011 me. See LICENSE.txt for further details.