lib/enumerated.rb
# Creates the methods required to read the defaults.
# If your defaults are a hash, the method name will use the value of the method_name key. If that's missing, it will use the
# value of the enumerated field.
# If your defaults are an array, it will use the name of the enumerated field.
# The method name (unless you specified it in a hash) will be underscored (as one should expect).
Creates the methods required to read the defaults.
If your defaults are a hash, the method name will use the value of the method_name key. If that's missing, it will use the
value of the enumerated field.
If your defaults are an array, it will use the name of the enumerated field.
The method name (unless you specified it in a hash) will be underscored (as one should expect).
Creates the methods required to read the defaults . If your defaults are a hash the method name will use the value of the method_name key . If that ' s missing it will use the value of the enumerated field . If your defaults are an array it will use the name of the enumerated field . The method name ( unless you specified it in a hash ) will be underscored ( as one should expect ) .
def add_enumerated_methods
      enumerations.each do |name, value|
        classvar = "@@#{name}".to_sym
        if @enum_translated && @enum_translated_class.send(:attribute_names).include?(@enum_field.to_s)
          define_singleton_method(name) do
            return class_variable_get(classvar) if class_variable_defined?(classvar) && class_variable_get(classvar)
            class_variable_set(classvar, cached_find_translated(@enum_field, value))
          end
        else
          define_singleton_method(name) do
            return class_variable_get(classvar) if class_variable_defined?(classvar) && class_variable_get(classvar)
            class_variable_set(classvar, cached_find(@enum_field, value))
          end
        end
      end
      @enum_methods_created = true
    end
def add_enumerated_methods enumerations . each do | name , value | classvar = "@@#{name}" . to_sym if @enum_translated && @enum_translated_class . send ( :attribute_names ) . include? ( @enum_field . to_s ) define_singleton_method ( name ) do return class_variable_get ( classvar ) if class_variable_defined? ( classvar ) && class_variable_get ( classvar ) class_variable_set ( classvar , cached_find_translated ( @enum_field , value ) ) end else define_singleton_method ( name ) do return class_variable_get ( classvar ) if class_variable_defined? ( classvar ) && class_variable_get ( classvar ) class_variable_set ( classvar , cached_find ( @enum_field , value ) ) end end end @enum_methods_created = true end
Creates the methods required to read the defaults.
Creates the methods required to read the defaults .
# ANNOYING: puts "** WARNING: named default method #{name} already exists, re-defined." if respond_to?(name) # NOTE - nothing is cached if it's nil... # NOTE - nothing is cached if it's nil...