search for: define_enum

Displaying 2 results from an estimated 2 matches for "define_enum".

Did you mean: define_enums
2005 Aug 16
1
Defining model classes for enumerations
...e the same content: id, name, position. I''d like to avoid the tedious work of defining a class for each one explicitly. Not least, in order to avoid clutter in the model directory. Here''s what I''ve come up with: class EnumRecord < ActiveRecord::Base def self.define_enums(*enums) enums.each do |spec| if spec.kind_of?(Hash) class_name = spec[:class_name].to_s raise ArgumentError, ''An enum specification must contain a :class_name'' if class_name.empty? order = spec[:order] || ''position''...
2005 Aug 19
13
Enumerations (again): Comments please
...ine enumerations; in particular it should not be necessary to define a model class in a separate file for each enumeration. - It should be possible to store each enumeration in its own table or all enumerations in a single table. The resulting syntax looks like this: BoilerPlate::Enumerations::define_enums( ''FirstEnum'', {:class_name => ''AnotherEnum, :table_name => ''second_enum'' } ) Further options are :position for ordering and :conditions which can be used to map records from the same table to different enumeration classes. Include a code s...