Module: Authorize::Redis::Fixtures

Defined in:
lib/authorize/redis/fixtures.rb

Overview

Persist Ruby objects to Redis DB using natural type affinity

Class Method Summary collapse

Class Method Details

.create_fixtures(db, pathname, flush = true) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/authorize/redis/fixtures.rb', line 5

def create_fixtures(db, pathname, flush = true)
  db.flushdb if flush
  fixtures = YAML.load(ERB.new(pathname.read).result)
  fixtures.each do |node|
    node.each_pair do |key, value|
      case value
        when ::Hash then value.each_pair {|k, v| db.hset(key, k, v)}
        when ::Set then value.each {|v| db.sadd(key, v)}
        when ::Array then value.each {|v| db.rpush(key, v)}
        else db.set(key, value) # String, Fixnum, NilClass
      end
    end
  end
end