Sha256: 1d0d5de654702d100f549bbdcf78c6907112f810f34fdfe6dca88125b964f2bf

Contents?: true

Size: 1.08 KB

Versions: 1

Compression:

Stored size: 1.08 KB

Contents

# Model: Setting
# A setting.
#
# ## Description
# You don't need to use this model directly. Just use:
#
#  * {Aura.set}
#  * {Aura.get}
#
class Setting < Sequel::Model
  plugin :serialization, :yaml, :value

  def self.seed(type=nil, &blk)
    super
    Aura.default :'site.name', "My Site"
  end

  # Class method: get (Setting)
  # Returns the value of a certain key.
  #
  # The get, set, default and delete methods are accessible from the
  # Aura class.
  #
  def self.get(key)
    find(:key => key.to_s).try(:value)
  end

  # Class method: del (Setting)
  # Deletes a key.
  #
  def self.del(key)
    s = find(:key => key.to_s)
    return  if s.nil?

    value = s.value
    s.delete
    value
  end

  # Class method: set (Setting)
  # Sets the value of a key.
  #
  def self.set(key, value)
    s = find(:key => key.to_s) || new
    s.key   = key
    s.value = value
    s.save
    value
  end

  # Class method: default (Setting)
  # Sets the default value of a key.
  #
  def self.default(key, value)
    s = find(:key => key.to_s)
    return set(key, value)  if s.nil?
    get key
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
aura-0.0.1.pre10 app/models/settings.rb