Class: ActiveNode::Associations::Builder::SingularAssociation

Inherits:
Association
  • Object
show all
Defined in:
lib/active_node/associations/builder/singular_association.rb

Overview

:nodoc:

Direct Known Subclasses

HasOne

Instance Attribute Summary

Attributes inherited from Association

#model, #name, #options, #reflection

Instance Method Summary collapse

Methods inherited from Association

build, #build, #define_accessors, #initialize, #macro, #mixin, #valid_options, #validate_options

Constructor Details

This class inherits a constructor from ActiveNode::Associations::Builder::Association

Instance Method Details

#define_constructorsObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/active_node/associations/builder/singular_association.rb', line 3

def define_constructors
  mixin.class_eval "    def build_\#{name}(*args, &block)\n      association(:\#{name}).build(*args, &block)\n    end\n\n    def create_\#{name}(*args, &block)\n      association(:\#{name}).create(*args, &block)\n    end\n\n    def create_\#{name}!(*args, &block)\n      association(:\#{name}).create!(*args, &block)\n    end\n  CODE\nend\n", __FILE__, __LINE__ + 1

#define_readersObject



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/active_node/associations/builder/singular_association.rb', line 19

def define_readers
  super

  mixin.class_eval "    def \#{name}_id\n      association(:\#{name}).id_reader\n    end\n\n    def \#{name}_rel\n      association(:\#{name}).rel_reader\n    end\n  CODE\nend\n", __FILE__, __LINE__ + 1

#define_writersObject



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/active_node/associations/builder/singular_association.rb', line 33

def define_writers
  super

  mixin.class_eval "    def \#{name}_id=(value)\n      association(:\#{name}).id_writer(value)\n    end\n\n    def \#{name}_rel=(value)\n      association(:\#{name}).rel_writer(value)\n    end\n  CODE\nend\n", __FILE__, __LINE__ + 1