Class: TelegramMeetupBot::Storage
- Inherits:
-
Object
- Object
- TelegramMeetupBot::Storage
- Defined in:
- lib/telegram_meetup_bot/storage.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
- #delete_date(date) ⇒ Object
- #get_all_available_dates ⇒ Object
- #get_users_for_date(date) ⇒ Object
-
#initialize(args) ⇒ Storage
constructor
A new instance of Storage.
- #set_users_to_date(users, date) ⇒ Object
Constructor Details
#initialize(args) ⇒ Storage
Returns a new instance of Storage.
5 6 7 8 |
# File 'lib/telegram_meetup_bot/storage.rb', line 5 def initialize(args) @redis = args.fetch(:redis) @key = args.fetch(:redis_key) end |
Instance Attribute Details
#key ⇒ Object (readonly)
Returns the value of attribute key.
3 4 5 |
# File 'lib/telegram_meetup_bot/storage.rb', line 3 def key @key end |
#redis ⇒ Object (readonly)
Returns the value of attribute redis.
3 4 5 |
# File 'lib/telegram_meetup_bot/storage.rb', line 3 def redis @redis end |
Instance Method Details
#delete_date(date) ⇒ Object
23 24 25 |
# File 'lib/telegram_meetup_bot/storage.rb', line 23 def delete_date(date) redis.hdel(key, date) end |
#get_all_available_dates ⇒ Object
19 20 21 |
# File 'lib/telegram_meetup_bot/storage.rb', line 19 def get_all_available_dates dates = redis.hkeys(key) end |
#get_users_for_date(date) ⇒ Object
10 11 12 13 |
# File 'lib/telegram_meetup_bot/storage.rb', line 10 def get_users_for_date(date) users_yml = redis.hget(key, date) users_yml.nil? ? [] : YAML.load(users_yml) end |
#set_users_to_date(users, date) ⇒ Object
15 16 17 |
# File 'lib/telegram_meetup_bot/storage.rb', line 15 def set_users_to_date(users, date) redis.hset(key, date, users.to_yaml) end |