Class: Cinch::Storage
- Inherits:
-
Object
- Object
- Cinch::Storage
- Defined in:
- lib/cinch/storage.rb,
lib/cinch/storage/version.rb
Overview
versioning info
Constant Summary collapse
- VERSION =
'1.2.1'
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
-
#filename ⇒ Object
Returns the value of attribute filename.
Instance Method Summary collapse
-
#initialize(file, init = {}) ⇒ Storage
constructor
A new instance of Storage.
- #save ⇒ Object
- #synced_save(bot = @bot) ⇒ Object
Constructor Details
#initialize(file, init = {}) ⇒ Storage
Returns a new instance of Storage.
10 11 12 13 14 |
# File 'lib/cinch/storage.rb', line 10 def initialize(file, init = {}) @filename = file @data = Psych.load(File.open(@filename)) if File.exist?(@filename) @data ||= init end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
8 9 10 |
# File 'lib/cinch/storage.rb', line 8 def data @data end |
#filename ⇒ Object
Returns the value of attribute filename.
8 9 10 |
# File 'lib/cinch/storage.rb', line 8 def filename @filename end |
Instance Method Details
#save ⇒ Object
16 17 18 19 20 |
# File 'lib/cinch/storage.rb', line 16 def save File.open(@filename, 'w') do |file| Psych.dump(@data, file) end end |
#synced_save(bot = @bot) ⇒ Object
22 23 24 25 26 |
# File 'lib/cinch/storage.rb', line 22 def synced_save(bot = @bot) bot.synchronize(@filename) do save end end |