Module: Sphene::Attributes
- Defined in:
- lib/sphene/attributes.rb
Defined Under Namespace
Modules: ClassMethods
Constant Summary collapse
- Types =
Sphene::Types
Class Method Summary collapse
Instance Method Summary collapse
- #assign_attributes(attrs) ⇒ Object
- #attributes ⇒ Object
- #initialize(attrs = {}) ⇒ Object
- #read_attribute(name) ⇒ Object
- #write_attribute(name, value) ⇒ Object
Class Method Details
.included(base) ⇒ Object
15 16 17 |
# File 'lib/sphene/attributes.rb', line 15 def self.included(base) base.extend(ClassMethods) end |
Instance Method Details
#assign_attributes(attrs) ⇒ Object
31 32 33 34 35 |
# File 'lib/sphene/attributes.rb', line 31 def assign_attributes(attrs) attrs.each do |name, value| write_attribute(name, value) end end |
#attributes ⇒ Object
37 38 39 |
# File 'lib/sphene/attributes.rb', line 37 def attributes @attributes.to_hash end |
#initialize(attrs = {}) ⇒ Object
10 11 12 13 |
# File 'lib/sphene/attributes.rb', line 10 def initialize(attrs = {}) initialize_attributes assign_attributes(attrs) end |
#read_attribute(name) ⇒ Object
19 20 21 22 23 |
# File 'lib/sphene/attributes.rb', line 19 def read_attribute(name) ensure_attribute(name) do |attr| @attributes[attr].value end end |
#write_attribute(name, value) ⇒ Object
25 26 27 28 29 |
# File 'lib/sphene/attributes.rb', line 25 def write_attribute(name, value) ensure_attribute(name) do |attr| @attributes[attr].value = value end end |