Class: ActiveData::Model::Attributes::Reflections::Represents
- Inherits:
-
Attribute
- Object
- Base
- Attribute
- ActiveData::Model::Attributes::Reflections::Represents
show all
- Defined in:
- lib/active_data/model/attributes/reflections/represents.rb
Instance Attribute Summary
Attributes inherited from Base
#name, #options
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Attribute
#defaultizer, #enumerizer, generate_methods, #normalizers
Methods inherited from Base
attribute_class, #build_attribute, generate_methods, #readonly, #typecaster
Constructor Details
#initialize(name, options) ⇒ Represents
Returns a new instance of Represents.
19
20
21
22
|
# File 'lib/active_data/model/attributes/reflections/represents.rb', line 19
def initialize name, options
super
raise ArgumentError, "Undefined reference for `#{name}`" if reference.blank?
end
|
Class Method Details
.build(target, generated_methods, name, *args, &block) ⇒ Object
6
7
8
9
10
11
12
13
14
15
16
17
|
# File 'lib/active_data/model/attributes/reflections/represents.rb', line 6
def self.build target, generated_methods, name, *args, &block
options = args.
reference = target.reflect_on_association(options[:of]) if target.respond_to?(:reflect_on_association)
reference ||= target.reflect_on_attribute(options[:of]) if target.respond_to?(:reflect_on_attribute)
if reference
options[:of] = reference.name
target.validates_nested options[:of]
end
super(target, generated_methods, name, *args, options, &block)
end
|
Instance Method Details
#column ⇒ Object
32
33
34
|
# File 'lib/active_data/model/attributes/reflections/represents.rb', line 32
def column
@column ||= options[:column].presence.try(:to_s) || name
end
|
#inspect_reflection ⇒ Object
48
49
50
|
# File 'lib/active_data/model/attributes/reflections/represents.rb', line 48
def inspect_reflection
"#{name}: (represents)"
end
|
#reader ⇒ Object
36
37
38
|
# File 'lib/active_data/model/attributes/reflections/represents.rb', line 36
def reader
@reader ||= options[:reader].presence.try(:to_s) || column
end
|
#reader_before_type_cast ⇒ Object
40
41
42
|
# File 'lib/active_data/model/attributes/reflections/represents.rb', line 40
def reader_before_type_cast
@reader_before_type_cast ||= "#{reader}_before_type_cast"
end
|
#reference ⇒ Object
28
29
30
|
# File 'lib/active_data/model/attributes/reflections/represents.rb', line 28
def reference
@reference ||= options[:of].to_s
end
|
#type ⇒ Object
24
25
26
|
# File 'lib/active_data/model/attributes/reflections/represents.rb', line 24
def type
Object
end
|
#writer ⇒ Object
44
45
46
|
# File 'lib/active_data/model/attributes/reflections/represents.rb', line 44
def writer
@writer ||= "#{options[:writer].presence || column}="
end
|