Class: Cinch::Storage

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#dataObject

Returns the value of attribute data.



8
9
10
# File 'lib/cinch/storage.rb', line 8

def data
  @data
end

#filenameObject

Returns the value of attribute filename.



8
9
10
# File 'lib/cinch/storage.rb', line 8

def filename
  @filename
end

Instance Method Details

#saveObject



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