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 <<-CODE, __FILE__, __LINE__ + 1
    def build_#{name}(*args, &block)
      association(:#{name}).build(*args, &block)
    end

    def create_#{name}(*args, &block)
      association(:#{name}).create(*args, &block)
    end

    def create_#{name}!(*args, &block)
      association(:#{name}).create!(*args, &block)
    end
  CODE
end

#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 <<-CODE, __FILE__, __LINE__ + 1
    def #{name}_id
      association(:#{name}).id_reader
    end

    def #{name}_rel
      association(:#{name}).rel_reader
    end
  CODE
end

#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 <<-CODE, __FILE__, __LINE__ + 1
    def #{name}_id=(value)
      association(:#{name}).id_writer(value)
    end

    def #{name}_rel=(value)
      association(:#{name}).rel_writer(value)
    end
  CODE
end