From 374aac53680ec87a9843510e5994ee5df519eb19 Mon Sep 17 00:00:00 2001 From: Giallombardo Nathan Date: Wed, 14 Aug 2024 17:19:29 +0000 Subject: [PATCH] revert dynamic update --- lib/couchbase-orm/attributes/dynamic.rb | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/lib/couchbase-orm/attributes/dynamic.rb b/lib/couchbase-orm/attributes/dynamic.rb index b48f425a..cec07850 100644 --- a/lib/couchbase-orm/attributes/dynamic.rb +++ b/lib/couchbase-orm/attributes/dynamic.rb @@ -15,7 +15,7 @@ module AttributesDynamic # # @return [ true | false ] True if it does, false if not. def respond_to?(name, include_private = false) - super || attributes.key?(name.to_s.reader) + super || attributes&.key?(name.to_s.reader) end private @@ -27,10 +27,9 @@ def respond_to?(name, include_private = false) # # @return [ Object ] value of attribute def _assign_attribute(name, value) - setter = name.to_s.writer - responds = setter == 'id=' || respond_to?(setter) + responds = name.reader == 'id' || respond_to?(name.writer) if responds - public_send(setter, value) + public_send(name.writer, value) else type = define_attribute_type(value) type = if type == :array @@ -80,7 +79,7 @@ def define_dynamic_reader(name) instance_eval do define_singleton_method(name) do - @attributes[name].value + @attributes[getter].value end end end @@ -115,10 +114,9 @@ def define_dynamic_writer(name) # @return [ Object ] The result of the method call. def method_missing(name, *args) attr = name.to_s - getter = attr.reader - - return super unless getter == 'id' && attributes.key?(getter) + return super unless attr.reader != 'id' && attributes.key?(attr.reader) + getter = attr.reader if attr.writer? define_dynamic_writer(getter) @attributes.write_from_user(getter, args.first)