Class: Cinch::Plugins::EnCinch::Storage

Inherits:
Object
  • Object
show all
Includes:
Cinch::Plugin
Defined in:
lib/cinch/plugins/encinch/storage.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(bot, data) ⇒ Storage

Returns a new instance of Storage.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# 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

Instance Attribute Details

#storageObject (readonly)

Returns the value of attribute storage.



9
10
11
# File 'lib/cinch/plugins/encinch/storage.rb', line 9

def storage
  @storage
end

Instance Method Details

#listen(m) ⇒ Object



44
45
46
47
48
49
# 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

#saveObject

save keys in yaml



54
55
56
57
58
# File 'lib/cinch/plugins/encinch/storage.rb', line 54

def save
  synchronize(:encinch_storage_save) do
    @storage.save
  end
end