Sha256: 764f9389009a4d9c26b5f01bac568a0ed1fd46ceb5dd41a5429a884083f9c5b9
Contents?: true
Size: 1.16 KB
Versions: 6
Compression:
Stored size: 1.16 KB
Contents
module StorageRoom # Module that contains attributes methods shared between StorageRoom::Base and StorageRoom::Embedded module Attributes # Optionally pass attributes to set up the object def initialize(attributes={}) self.attributes = attributes end # Set the attributes of an object with a hash from the API def set_from_api(attributes) reset! self.attributes = attributes end # Shortcut to get an attribute. def [](name) self.attributes[name] end # Shortcut to set an attribute def []=(name, value) self.attributes[name] = value end # Return all of the objects attributes def attributes @attributes ||= Hash.new.with_indifferent_access end # Set the objects attributes with a hash. Only attributes passed in the hash are changed, existing ones are not overridden. def attributes=(hash = {}) hash.each do |k, v| self.attributes[k] = v end end # Reset an object to its initial state with all attributes unset def reset! @attributes = Hash.new.with_indifferent_access end end end
Version data entries
6 entries across 6 versions & 1 rubygems