lib/granite/form/model/associations/reflections/embeds_one.rb in granite-form-0.3.0 vs lib/granite/form/model/associations/reflections/embeds_one.rb in granite-form-0.4.0

- old
+ new

@@ -5,12 +5,22 @@ module Reflections class EmbedsOne < EmbedsAny include Singular def self.build(target, generated_methods, name, options = {}, &block) - target.add_attribute(Granite::Form::Model::Attributes::Reflections::Base, name) if target < Granite::Form::Model::Attributes + target.add_attribute(Granite::Form::Model::Attributes::Reflections::Base, name, type: Object) if target < Granite::Form::Model::Attributes options[:validate] = true unless options.key?(:validate) super + end + + def self.generate_methods(name, target) + super + + target.class_eval <<-RUBY, __FILE__, __LINE__ + 1 + def build_#{name} attributes = {} + association(:#{name}).build(attributes) + end + RUBY end end end end end