Class: Authorize::Redis::Factory
- Inherits:
-
Object
- Object
- Authorize::Redis::Factory
- Defined in:
- lib/authorize/redis/factory.rb
Overview
A Factory is designed to help build relevant test fixtures in the context of a test. In order to preserve a high signal-to-noise ratio in the test, a factory needs to concisely build fixtures even at the expense of supporting cool features. As a result, index management and references to other values are the responsibility of the programmer.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#db ⇒ Object
readonly
Returns the value of attribute db.
Class Method Summary collapse
Instance Method Summary collapse
- #array(name, value = []) ⇒ Object
- #hash(name, value = {}) ⇒ Object
-
#initialize(db = Base.db) ⇒ Factory
constructor
A new instance of Factory.
- #namespace(name, &block) ⇒ Object
- #set(name, value = ::Set[]) ⇒ Object
- #string(name, value = "") ⇒ Object
Constructor Details
Instance Attribute Details
#db ⇒ Object (readonly)
Returns the value of attribute db.
7 8 9 |
# File 'lib/authorize/redis/factory.rb', line 7 def db @db end |
Class Method Details
.build(ns = nil, &block) ⇒ Object
9 10 11 12 13 |
# File 'lib/authorize/redis/factory.rb', line 9 def self.build(ns = nil, &block) self.new.tap do |f| f.namespace(ns, &block) if ns end end |
Instance Method Details
#array(name, value = []) ⇒ Object
51 52 53 54 55 56 |
# File 'lib/authorize/redis/factory.rb', line 51 def array(name, value = []) key = subordinate_key(name) value.each {|v| db.rpush(key, v)} namespace(name){yield} if block_given? Redis::Array.load(key) end |
#hash(name, value = {}) ⇒ Object
37 38 39 40 41 42 |
# File 'lib/authorize/redis/factory.rb', line 37 def hash(name, value = {}) key = subordinate_key(name) value.each {|k, v| db.hset(key, k, v)} namespace(name){yield} if block_given? Redis::Hash.load(key) end |
#namespace(name, &block) ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/authorize/redis/factory.rb', line 20 def namespace(name, &block) @old_namespace, @namespace = @namespace, subordinate_key(name) if block_given? self.instance_eval(&block) @namespace = @old_namespace else self end end |