class Cinch::Plugins::EnCinch::Storage

Attributes

storage[R]

Public Class Methods

new(bot, data) click to toggle source
Calls superclass method
# File lib/cinch/plugins/encinch/storage.rb, line 11
def initialize(bot, data)
  super(bot)

  file = data.delete(:key_file) || 'keys/encinch.yml'
  make_dirp(file)

  @storage = ::Cinch::Storage.new(file, data)

  @storage.data.merge!(data) do |key, x, y|
    case x
    when Hash
      x.merge!(y || {})
    when Array
      x.concat(y || []).uniq
    when NilClass
      y
    else
      if y.nil? || (y.respond_to?(:empty?) && y.empty?)
        x
      else
        y
      end
    end
  end

  @storage.data[:drop] ||= false

  save
end

Public Instance Methods

listen(m) click to toggle source
# File lib/cinch/plugins/encinch/storage.rb, line 44
def listen(m)
  if @storage.data[:encrypt][m.user.last_nick.downcase]
    @storage.data[:encrypt][m.user.nick.downcase] = @storage.data[:encrypt].delete(m.user.last_nick.downcase)
    save
  end
end
save() click to toggle source

save keys in yaml

# File lib/cinch/plugins/encinch/storage.rb, line 54
def save
  synchronize(:encinch_storage_save) do
    @storage.save
  end
end

Private Instance Methods

make_dirp(file) click to toggle source
# File lib/cinch/plugins/encinch/storage.rb, line 60
def make_dirp(file)
  path = File.expand_path(File.dirname(file))
  FileUtils.mkdir_p(path) unless Dir.exist?(path)
end