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 49 |
# 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 # TODO better error raise ArgumentError, "You must configure a `lookup` proc" 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
51 52 53 |
# File 'lib/trail_guide/adapters/participants/redis.rb', line 51 def [](field) TrailGuide.redis.hget(storage_key, field.to_s) end |
#[]=(field, value) ⇒ Object
55 56 57 58 |
# File 'lib/trail_guide/adapters/participants/redis.rb', line 55 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
60 61 62 |
# File 'lib/trail_guide/adapters/participants/redis.rb', line 60 def delete(field) TrailGuide.redis.hdel(storage_key, field.to_s) end |
#destroy! ⇒ Object
64 65 66 |
# File 'lib/trail_guide/adapters/participants/redis.rb', line 64 def destroy! TrailGuide.redis.del(storage_key) end |
#key?(field) ⇒ Boolean
72 73 74 |
# File 'lib/trail_guide/adapters/participants/redis.rb', line 72 def key?(field) TrailGuide.redis.hexists(storage_key, field.to_s) end |
#keys ⇒ Object
68 69 70 |
# File 'lib/trail_guide/adapters/participants/redis.rb', line 68 def keys TrailGuide.redis.hkeys(storage_key) end |
#to_h ⇒ Object
76 77 78 |
# File 'lib/trail_guide/adapters/participants/redis.rb', line 76 def to_h TrailGuide.redis.hgetall(storage_key) end |