Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Define read_attribute and write_attribute methods

Change-Id: I811d4a7b88c831b5b960afe8edcf90cd7c1a4998
Reviewed-on: http://review.couchbase.org/21777
Tested-by: Sergey Avseyev <sergey.avseyev@gmail.com>
Reviewed-by: Matt Ingenthron <matt@couchbase.com>
  • Loading branch information...
commit 4b55eabf172cfa59b7f93f21bd687e94b2303910 1 parent 17d2bb3
@avsej authored
Showing with 12 additions and 4 deletions.
  1. +12 −4 lib/couchbase/model.rb
View
16 lib/couchbase/model.rb
@@ -285,6 +285,14 @@ def self.uuid_algorithm(algorithm)
self.thread_storage[:uuid_algorithm] = algorithm
end
+ def read_attribute(attr_name)
+ @_attributes[attr_name]
+ end
+
+ def write_attribute(attr_name, value)
+ @_attributes[attr_name] = value
+ end
+
# Defines an attribute for the model
#
# @since 0.0.1
@@ -311,10 +319,10 @@ def self.attribute(*names)
attributes[name] = options[:default]
next if self.instance_methods.include?(name)
define_method(name) do
- @_attributes[name]
+ read_attribute(name)
end
define_method(:"#{name}=") do |value|
- @_attributes[name] = value
+ write_attribute(name, value)
end
end
end
@@ -715,7 +723,7 @@ def inspect
attrs << ["key", @key.inspect] unless @key.nil?
attrs << ["value", @value.inspect] unless @value.nil?
model.attributes.map do |attr, default|
- val = @_attributes[attr]
+ val = read_attribute(attr)
attrs << [attr.to_s, val.inspect] unless val.nil?
end
attrs.sort!
@@ -737,7 +745,7 @@ def self.inspect
def attributes_with_values
ret = {:type => model.design_document}
model.attributes.keys.each do |attr|
- ret[attr] = @_attributes[attr]
+ ret[attr] = read_attribute(attr)
end
ret
end
Please sign in to comment.
Something went wrong with that request. Please try again.