Class: ActiveData::Model::Associations::EmbedsOne
- Inherits:
-
Association
- Object
- Association
- ActiveData::Model::Associations::EmbedsOne
show all
- Defined in:
- lib/active_data/model/associations/embeds_one.rb
Instance Attribute Summary
Attributes inherited from Association
#klass, #name, #options
Instance Method Summary
collapse
Methods inherited from Association
#class_name, #define_accessor, #initialize
Instance Method Details
#collection? ⇒ Boolean
6
7
8
|
# File 'lib/active_data/model/associations/embeds_one.rb', line 6
def collection?
false
end
|
#define_reader(target) ⇒ Object
10
11
12
13
14
15
16
|
# File 'lib/active_data/model/associations/embeds_one.rb', line 10
def define_reader target
target.class_eval <<-EOS
def #{name}
@#{name}
end
EOS
end
|
#define_writer(target) ⇒ Object
18
19
20
21
22
23
24
25
|
# File 'lib/active_data/model/associations/embeds_one.rb', line 18
def define_writer target
target.class_eval <<-EOS
def #{name}= value
association = self.class.reflect_on_association('#{name}')
@#{name} = association.klass.instantiate(value) if value
end
EOS
end
|