Class: EurekaBot::Session
- Inherits:
-
Object
- Object
- EurekaBot::Session
- Defined in:
- lib/eureka_bot/session.rb
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#redis ⇒ Object
readonly
Returns the value of attribute redis.
Instance Method Summary collapse
- #data ⇒ Object
- #data=(v) ⇒ Object
- #del ⇒ Object
- #get ⇒ Object
-
#initialize(key, redis: nil) ⇒ Session
constructor
A new instance of Session.
- #set ⇒ Object
- #update(**attributes) ⇒ Object
Constructor Details
#initialize(key, redis: nil) ⇒ Session
Returns a new instance of Session.
5 6 7 8 |
# File 'lib/eureka_bot/session.rb', line 5 def initialize(key, redis: nil) @key = key @redis = redis end |
Instance Attribute Details
#key ⇒ Object (readonly)
Returns the value of attribute key.
3 4 5 |
# File 'lib/eureka_bot/session.rb', line 3 def key @key end |
#redis ⇒ Object (readonly)
Returns the value of attribute redis.
3 4 5 |
# File 'lib/eureka_bot/session.rb', line 3 def redis @redis end |
Instance Method Details
#data ⇒ Object
14 15 16 |
# File 'lib/eureka_bot/session.rb', line 14 def data @data ||= get || {} end |
#data=(v) ⇒ Object
18 19 20 21 |
# File 'lib/eureka_bot/session.rb', line 18 def data=(v) @data = v set end |
#del ⇒ Object
32 33 34 |
# File 'lib/eureka_bot/session.rb', line 32 def del redis.del(key) end |
#get ⇒ Object
23 24 25 26 |
# File 'lib/eureka_bot/session.rb', line 23 def get got = redis.get(key) got.present? ? ActiveSupport::JSON.decode(got).deep_symbolize_keys : nil end |
#set ⇒ Object
28 29 30 |
# File 'lib/eureka_bot/session.rb', line 28 def set redis.set(key, data.to_json) == 'OK' end |
#update(**attributes) ⇒ Object
10 11 12 |
# File 'lib/eureka_bot/session.rb', line 10 def update(**attributes) self.data = data.merge(attributes.deep_symbolize_keys).compact end |