Skip to content

Commit

Permalink
revert dynamic update
Browse files Browse the repository at this point in the history
  • Loading branch information
Giallombardo Nathan committed Aug 14, 2024
1 parent 0dc9ed4 commit 374aac5
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions lib/couchbase-orm/attributes/dynamic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 374aac5

Please sign in to comment.