Module: Alchemist::Record
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
- #attr_names ⇒ Object
- #initialize(attrs = {}) ⇒ Object
- #read(attr) ⇒ Object
- #update(attr_changes) ⇒ Object
Class Method Details
.hamsterize(hash) ⇒ Object
23 24 25 26 27 28 |
# File 'lib/alchemist-server/record.rb', line 23 def self.hamsterize(hash) case hash when Hamster::Hash then hash else Hamster.hash hash end end |
.included(mod) ⇒ Object
3 4 5 |
# File 'lib/alchemist-server/record.rb', line 3 def self.included(mod) mod.extend ClassMethods end |
Instance Method Details
#attr_names ⇒ Object
19 20 21 |
# File 'lib/alchemist-server/record.rb', line 19 def attr_names self.class.attr_names end |
#initialize(attrs = {}) ⇒ Object
7 8 9 |
# File 'lib/alchemist-server/record.rb', line 7 def initialize(attrs = {}) @attrs = Record.hamsterize(attrs).slice(*attr_names) end |
#read(attr) ⇒ Object
15 16 17 |
# File 'lib/alchemist-server/record.rb', line 15 def read(attr) @attrs[attr] end |
#update(attr_changes) ⇒ Object
11 12 13 |
# File 'lib/alchemist-server/record.rb', line 11 def update(attr_changes) self.class.new @attrs.merge(Record.hamsterize(attr_changes)) end |