Module: EnumeratedAttribute::Integrations::Object

Defined in:
lib/enumerated_attribute/integrations/object.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object



5
6
7
# File 'lib/enumerated_attribute/integrations/object.rb', line 5

def self.included(klass)
	klass.extend(ClassMethods)
end

Instance Method Details

#read_enumerated_attribute(name) ⇒ Object



20
21
22
# File 'lib/enumerated_attribute/integrations/object.rb', line 20

def read_enumerated_attribute(name)
	instance_variable_get('@'+name.to_s)
end

#write_enumerated_attribute(name, val) ⇒ Object



9
10
11
12
13
14
15
16
17
18
# File 'lib/enumerated_attribute/integrations/object.rb', line 9

def write_enumerated_attribute(name, val)
	name = name.to_s
	val = nil if val == ''
	val = val.to_sym if val
	unless self.class.enumerated_attribute_allows_value?(name, val)
		raise(InvalidEnumeration, "nil is not allowed on '#{name}' attribute, set :nil=>true option", caller) unless val
		raise(InvalidEnumeration, ":#{val} is not a defined enumeration value for the '#{name}' attribute", caller) 
	end
	instance_variable_set('@'+name, val)
end