Module: Alchemist::Record

Included in:
Avatar, Element, Outcome, World
Defined in:
lib/alchemist-server/record.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

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_namesObject



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