Class: TrailGuide::Adapters::Participants::Redis::Adapter
- Inherits:
-
Object
- Object
- TrailGuide::Adapters::Participants::Redis::Adapter
- Defined in:
- lib/trail_guide/adapters/participants/redis.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#storage_key ⇒ Object
readonly
Returns the value of attribute storage_key.
Instance Method Summary collapse
- #[](field) ⇒ Object
- #[]=(field, value) ⇒ Object
- #delete(field) ⇒ Object
- #destroy! ⇒ Object
-
#initialize(context, config, key: nil) ⇒ Adapter
constructor
A new instance of Adapter.
- #key?(field) ⇒ Boolean
- #keys ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(context, config, key: nil) ⇒ Adapter
Returns a new instance of Adapter.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/trail_guide/adapters/participants/redis.rb', line 32 def initialize(context, config, key: nil) @context = context @config = config if key @storage_key = "#{config.namespace}:#{key}" elsif config.lookup if config.lookup.respond_to?(:call) key = config.lookup.call(context) else key = context.send(config.lookup) end @storage_key = "#{config.namespace}:#{key}" else raise ArgumentError, "You must configure a `lookup` proc to use the redis adapter." end end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
30 31 32 |
# File 'lib/trail_guide/adapters/participants/redis.rb', line 30 def config @config end |
#context ⇒ Object (readonly)
Returns the value of attribute context.
30 31 32 |
# File 'lib/trail_guide/adapters/participants/redis.rb', line 30 def context @context end |
#storage_key ⇒ Object (readonly)
Returns the value of attribute storage_key.
30 31 32 |
# File 'lib/trail_guide/adapters/participants/redis.rb', line 30 def storage_key @storage_key end |
Instance Method Details
#[](field) ⇒ Object
50 51 52 |
# File 'lib/trail_guide/adapters/participants/redis.rb', line 50 def [](field) TrailGuide.redis.hget(storage_key, field.to_s) end |
#[]=(field, value) ⇒ Object
54 55 56 57 |
# File 'lib/trail_guide/adapters/participants/redis.rb', line 54 def []=(field, value) TrailGuide.redis.hset(storage_key, field.to_s, value) TrailGuide.redis.expire(storage_key, config.expiration) if config.expiration end |
#delete(field) ⇒ Object
59 60 61 |
# File 'lib/trail_guide/adapters/participants/redis.rb', line 59 def delete(field) TrailGuide.redis.hdel(storage_key, field.to_s) end |
#destroy! ⇒ Object
63 64 65 |
# File 'lib/trail_guide/adapters/participants/redis.rb', line 63 def destroy! TrailGuide.redis.del(storage_key) end |
#key?(field) ⇒ Boolean
71 72 73 |
# File 'lib/trail_guide/adapters/participants/redis.rb', line 71 def key?(field) TrailGuide.redis.hexists(storage_key, field.to_s) end |
#keys ⇒ Object
67 68 69 |
# File 'lib/trail_guide/adapters/participants/redis.rb', line 67 def keys TrailGuide.redis.hkeys(storage_key) end |
#to_h ⇒ Object
75 76 77 |
# File 'lib/trail_guide/adapters/participants/redis.rb', line 75 def to_h TrailGuide.redis.hgetall(storage_key) end |