class QuickML::GroupConfig

Constants

DefaultConfig
KEYS

Public Class Methods

new(db) click to toggle source
# File vendor/qwik/lib/qwik/group-config.rb, line 52
def initialize(db)
  @db = db
  @default = nil
  @group_config = {}
  @group_config.update(DefaultConfig)
  @content = nil
  read
end

Private Class Methods

generate(config) click to toggle source
# File vendor/qwik/lib/qwik/group-config.rb, line 147
def self.generate(config)
  return KEYS.map {|k|
    ":#{k}:#{config[k]}\n"
  }.join
end
get_group_config(config) click to toggle source
# File vendor/qwik/lib/qwik/group-config.rb, line 153
def self.get_group_config(config)
  return {
    :auto_unsubscribe_count        => config[:auto_unsubscribe_count],
    :max_mail_length       => config[:max_ml_mail_length] ||
                               config[:max_mail_length],
    :max_members           => config[:max_members],
    :ml_alert_time         => config[:ml_alert_time],
    :ml_life_time          => config[:ml_life_time],
  }
end
parse_hash(str) click to toggle source
# File vendor/qwik/lib/qwik/group-config.rb, line 116
def self.parse_hash(str)
  config = {}
  return config if str.nil?
  str.each {|line|
    k = v = nil
    line.chomp!
    if /\A\s+:([a-z_]+) => (\d+),\z/ =~ line
      k = $1.intern
      v = $2.to_i
      config[k] = v
    elsif /\A:([a-z_]+):(\d+)\z/ =~ line
      k = $1.intern
      v = $2.to_i
      config[k] = v
    elsif /\A:([a-z_]+):([a-z]+)\z/ =~ line
      k = $1.intern
      v = $2
      v = true  if v == 'true'
      v = false if v == 'false'
      config[k] = v
    end
  }
  return config
end
set_default(default, group_config) click to toggle source
# File vendor/qwik/lib/qwik/group-config.rb, line 141
def self.set_default(default, group_config)
  default.each {|k, v|
    group_config[k] ||= v
  }
end

Public Instance Methods

[](key) click to toggle source
# File vendor/qwik/lib/qwik/group-config.rb, line 73
def [](key)
  read
  return @group_config[key]
end
check_exist() click to toggle source
# File vendor/qwik/lib/qwik/group-config.rb, line 65
def check_exist
  write if ! exist?
end
exist?() click to toggle source
# File vendor/qwik/lib/qwik/group-config.rb, line 69
def exist?
  return @db.exist?(:Config)
end
forward?() click to toggle source
# File vendor/qwik/lib/qwik/group-config.rb, line 78
def forward?
  return true if @db.exist?(:Forward)
  return true if self[:forward]
  return false
end
permanent?() click to toggle source
# File vendor/qwik/lib/qwik/group-config.rb, line 84
def permanent?
  return true if @db.exist?(:Permanent)
  return true if self[:permanent]
  return false
end
set_default(default) click to toggle source
# File vendor/qwik/lib/qwik/group-config.rb, line 61
def set_default(default)
  @default = default
end
unlimited?() click to toggle source
# File vendor/qwik/lib/qwik/group-config.rb, line 90
def unlimited?
  return true if @db.exist?(:Unlimited)
  return true if self[:unlimited]
  return false
end
write() click to toggle source
# File vendor/qwik/lib/qwik/group-config.rb, line 96
def write
  raise 'must have default' if @default.nil?
  GroupConfig.set_default(@default, @group_config)
  content = GroupConfig.generate(@group_config)
  return if content == @content     # Do nothing.
  @db.put(:Config, content)
  @content = content
end

Private Instance Methods

read() click to toggle source
# File vendor/qwik/lib/qwik/group-config.rb, line 107
def read
  content = @db.get(:Config)
  return if content && content == @content  # Do nothing.
  @content = content
  config = GroupConfig.parse_hash(@content)
  @group_config.update(config)
  return
end