lib/virtus/instance_methods.rb in virtus-0.1.0 vs lib/virtus/instance_methods.rb in virtus-0.2.0

- old
+ new

@@ -33,11 +33,11 @@ # @return [Object] # a value of an attribute # # @api public def [](name) - __send__(name) + get_attribute(name) end # Sets a value of the attribute with the given name # # @example @@ -60,11 +60,11 @@ # @return [Object] # the value set on an object # # @api public def []=(name, value) - __send__("#{name}=", value) + set_attribute(name, value) end # Returns a hash of all publicly accessible attributes # # @example @@ -163,10 +163,44 @@ # # @return [Hash] # # @api private def set_attributes(attribute_values) - attribute_values.each { |name, value| self[name] = value } + attribute_values.each { |pair| set_attribute(*pair) } + end + + # Get values of all attributes defined for this class, ignoring privacy + # + # @return [Hash] + # + # @api private + def get_attributes + self.class.attributes.each_with_object({}) do |attribute, attributes| + attribute_name = attribute.name + attributes[attribute_name] = get_attribute(attribute_name) + end + end + + # Returns a value of the attribute with the given name + # + # @see Virtus::InstanceMethods#[] + # + # @return [Object] + # + # @api private + def get_attribute(name) + __send__(name) + end + + # Sets a value of the attribute with the given name + # + # @see Virtus::InstanceMethods#[]= + # + # @return [Object] + # + # @api private + def set_attribute(name, value) + __send__("#{name}=", value) end end # module InstanceMethods end # module Virtus