Module: Enumerize::Base

Defined in:
lib/enumerize/base.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object


5
6
7
8
9
10
11
12
# File 'lib/enumerize/base.rb', line 5

def self.included(base)
  base.extend ClassMethods
  base.singleton_class.prepend ClassMethods::Hook

  if base.respond_to?(:validate)
    base.validate :_validate_enumerized_attributes
  end
end

Instance Method Details

#initializeObject


52
53
54
55
# File 'lib/enumerize/base.rb', line 52

def initialize(*)
  super
  _set_default_value_for_enumerized_attributes
end

#read_attribute_for_validation(key) ⇒ Object


57
58
59
60
61
62
63
64
65
66
67
# File 'lib/enumerize/base.rb', line 57

def read_attribute_for_validation(key)
  key = key.to_s

  if _enumerized_values_for_validation.has_key?(key)
    _enumerized_values_for_validation[key]
  elsif defined?(super)
    super
  else
    send(key)
  end
end