Class: WhatsAppNotifier::Session::Store
- Inherits:
-
Object
- Object
- WhatsAppNotifier::Session::Store
- Defined in:
- lib/whatsapp_notifier/session/store.rb
Instance Method Summary collapse
-
#initialize(path:) ⇒ Store
constructor
A new instance of Store.
- #load ⇒ Object
- #save(data) ⇒ Object
Constructor Details
#initialize(path:) ⇒ Store
Returns a new instance of Store.
7 8 9 |
# File 'lib/whatsapp_notifier/session/store.rb', line 7 def initialize(path:) @path = path end |
Instance Method Details
#load ⇒ Object
11 12 13 14 |
# File 'lib/whatsapp_notifier/session/store.rb', line 11 def load return {} unless File.exist?(@path) JSON.parse(File.read(@path), symbolize_names: true) end |
#save(data) ⇒ Object
16 17 18 19 |
# File 'lib/whatsapp_notifier/session/store.rb', line 16 def save(data) FileUtils.mkdir_p(File.dirname(@path)) File.write(@path, JSON.generate(data)) end |