lib/embedson/model/method_builder.rb in embedson-1.0.2 vs lib/embedson/model/method_builder.rb in embedson-1.0.3

- old
+ new

@@ -24,11 +24,11 @@ def column_name @column_name ||= options.fetch(:column_name, nil) || field_name end def related_klass_name - @related_klass_name ||= (options.fetch(:class_name, nil) || field_name).to_s.classify + @related_klass_name ||= (options.fetch(:class_name, nil) || field_name).to_s.camelize end def instance_var_name @instance_var_name ||= "@#{field_name}" end @@ -43,39 +43,24 @@ private def generate_common methods_for_both.each do |meth| - klass.class_exec self, &send(meth) + klass.class_exec self, &self.method(meth) end end def methods_for_both - [:send_self_to_related, :verify_arg_klass] + [:verify_arg_klass] end - def verify_arg_klass - proc do |builder| - private - - define_method('verify_arg_klass') do |arg| - unless arg.nil? || arg.is_a?(builder.related_klass_name.constantize) - raise ClassTypeError.new(arg.class.name, builder.related_klass_name) - end + def verify_arg_klass(builder) + klass.send(:define_method, "#{field_name}_verify_arg_klass") do |arg| + unless arg.nil? || arg.is_a?(builder.related_klass_name.constantize) + raise ClassTypeError.new(arg.class.name, builder.related_klass_name) end end - end - - def send_self_to_related - proc do |builder| - private - - define_method('send_self_to_related') do |arg| - if arg.respond_to?(builder.inverse_set) && arg.public_send(builder.inverse_get) != self - arg.public_send(builder.inverse_set, self) - end - end - end + klass.send(:private, "#{field_name}_verify_arg_klass") end end end end