Class: ActiveData::Model::Attributes::Reflections::Attribute
- Inherits:
-
Base
- Object
- Base
- ActiveData::Model::Attributes::Reflections::Attribute
show all
- Defined in:
- lib/active_data/model/attributes/reflections/attribute.rb
Instance Attribute Summary
Attributes inherited from Base
#name, #options
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Base
attribute_class, #build_attribute, #initialize, #inspect_reflection, #readonly, #type, #typecaster
Class Method Details
.build(target, generated_methods, name, *args, &block) ⇒ Object
6
7
8
9
10
|
# File 'lib/active_data/model/attributes/reflections/attribute.rb', line 6
def self.build(target, generated_methods, name, *args, &block)
attribute = super(target, generated_methods, name, *args, &block)
generate_methods name, generated_methods
attribute
end
|
.generate_methods(name, target) ⇒ Object
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/active_data/model/attributes/reflections/attribute.rb', line 12
def self.generate_methods(name, target)
target.class_eval <<-RUBY, __FILE__, __LINE__ + 1
def #{name}
attribute('#{name}').read
end
def #{name}= value
attribute('#{name}').write(value)
end
def #{name}?
attribute('#{name}').query
end
def #{name}_before_type_cast
attribute('#{name}').read_before_type_cast
end
def #{name}_default
attribute('#{name}').default
end
def #{name}_values
attribute('#{name}').enum.to_a
end
RUBY
end
|
Instance Method Details
#defaultizer ⇒ Object
40
41
42
|
# File 'lib/active_data/model/attributes/reflections/attribute.rb', line 40
def defaultizer
@defaultizer ||= options[:default]
end
|
#enumerizer ⇒ Object
44
45
46
|
# File 'lib/active_data/model/attributes/reflections/attribute.rb', line 44
def enumerizer
@enumerizer ||= options[:enum] || options[:in]
end
|
#normalizers ⇒ Object
48
49
50
|
# File 'lib/active_data/model/attributes/reflections/attribute.rb', line 48
def normalizers
@normalizers ||= Array.wrap(options[:normalize] || options[:normalizer] || options[:normalizers])
end
|