Module: ActiveData::Model::Associations::Reflections::Singular::ClassMethods

Defined in:
lib/active_data/model/associations/reflections/singular.rb

Instance Method Summary collapse

Instance Method Details

#generate_methods(name, target) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/active_data/model/associations/reflections/singular.rb', line 9

def generate_methods(name, target)
  super

  target.class_eval <<-RUBY, __FILE__, __LINE__ + 1
    def build_#{name} attributes = {}
      association(:#{name}).build(attributes)
    end

    def create_#{name} attributes = {}
      association(:#{name}).create(attributes)
    end

    def create_#{name}! attributes = {}
      association(:#{name}).create!(attributes)
    end
  RUBY
end