Class: Ohm::Model

Inherits:
Object
  • Object
show all
Defined in:
lib/active_resource_test_helper/ohm/model.rb

Overview

Adds some convenience methods to Ohm::Model.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.countObject

Return the number of instances of this model saved into redis



23
24
25
# File 'lib/active_resource_test_helper/ohm/model.rb', line 23

def self.count
  self.all.size
end

.destroy_allObject

Destroy all instances of this model



16
17
18
19
20
# File 'lib/active_resource_test_helper/ohm/model.rb', line 16

def self.destroy_all
  self.all.each do |i|
    i.delete
  end
end

Instance Method Details

#to_hashObject

Convert the model to hash.



7
8
9
10
11
12
13
# File 'lib/active_resource_test_helper/ohm/model.rb', line 7

def to_hash
  hash = {:id => self.id.to_i}
  self.attributes.each do |attr|
    hash[attr] = self.send attr
  end
  hash
end