Class/Module Index [+]

Quicksearch

Cinch::Storage::YAML

A basic storage backed by YAML, using one file per plugin.

Public Class Methods

new(options, plugin) click to toggle source

(see Storage#initialize)

# File lib/cinch/storage/yaml.rb, line 9
def initialize(options, plugin)
  # We are a basic example, so we load everything into memory. yey.
  @file = options.basedir + plugin.class.plugin_name + ".yaml"
  if File.exist?(@file)
    @yaml = ::YAML.load_file(@file) || {}
  else
    @yaml = {}
  end
  @options = options

  @mutex = Mutex.new
end

Public Instance Methods

[](key) click to toggle source

(see Storage#[])

# File lib/cinch/storage/yaml.rb, line 23
def [](key)
  @yaml[key]
end
[]=(key, value) click to toggle source

(see Strage#[]=)

# File lib/cinch/storage/yaml.rb, line 28
def []=(key, value)
  @yaml[key] = value
end
delete(key) click to toggle source

(see Storage#delete)

# File lib/cinch/storage/yaml.rb, line 62
def delete(key)
  obj = @yaml.delete(key)

  obj
end
delete_if() click to toggle source

(see Storage#delete_if)

# File lib/cinch/storage/yaml.rb, line 69
def delete_if
  delete_keys = []
  each do |key, value|
    delete_keys << key if yield(key, value)
  end

  delete_keys.each do |key|
    delete(key)
  end

  self
end
each() click to toggle source

(see Storage#each)

# File lib/cinch/storage/yaml.rb, line 41
def each
  @yaml.each {|e| yield(e)}

  self
end
each_key() click to toggle source

(see Storage#each_key)

# File lib/cinch/storage/yaml.rb, line 48
def each_key
  @yaml.each_key {|e| yield(e)}

  self
end
each_value() click to toggle source

(see Storage#each_value)

# File lib/cinch/storage/yaml.rb, line 55
def each_value
  @yaml.each_value {|e| yield(e)}

  self
end
has_key?(key) click to toggle source

(see Storage#has_key?)

# File lib/cinch/storage/yaml.rb, line 33
def has_key?(key)
  @yaml.has_key?(key)
end
Also aliased as: include?, key?, member?
include?(key) click to toggle source
Alias for: has_key?
key?(key) click to toggle source
Alias for: has_key?
member?(key) click to toggle source
Alias for: has_key?
save() click to toggle source

(see Storage#save)

# File lib/cinch/storage/yaml.rb, line 83
def save
  @mutex.synchronize do
    File.open(@file, "w") do |f|
      f.write @yaml.to_yaml
    end
  end
end
unload() click to toggle source

(see Storage#unload)

# File lib/cinch/storage/yaml.rb, line 92
def unload
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.