Sha256: ec037d46fe47fd58912e45c8278a843720e611156ea3223c72904a3d7c7170ee

Contents?: true

Size: 1.97 KB

Versions: 7

Compression:

Stored size: 1.97 KB

Contents

module Radiant
  #
  # The Radiant::Config object emulates a hash with simple bracket methods
  # which allow you to get and set values in the configuration table:
  #
  #   Radiant::Config['setting.name'] = 'value'
  #   Radiant::Config['setting.name'] #=> "value"
  #
  # Currently, there is not a way to edit configuration through the admin
  # system so it must be done manually. The console script is probably the
  # easiest way to this:
  #
  #   % script/console production
  #   Loading production environment.
  #   >> Radiant::Config['setting.name'] = 'value'
  #   => "value"
  #   >> 
  #
  # Radiant currently uses the following settings:
  #
  # admin.title           :: the title of the admin system
  # admin.subtitle        :: the subtitle of the admin system
  # defaults.page.parts   :: a comma separated list of default page parts
  # defaults.page.status  :: a string representation of the default page status
  # dev.host              :: the hostname where draft pages are viewable
  # local.timezone        :: the timezone offset (using a String or integer
  #                          from http://api.rubyonrails.org/classes/TimeZone.html) 
  #                          used to correct displayed times 
  class Config < ActiveRecord::Base
    set_table_name "config"

    class << self
      def [](key)
        pair = find_by_key(key)
        pair.value unless pair.nil?
      end

      def []=(key, value)
        pair = find_by_key(key)
        unless pair
          pair = new
          pair.key, pair.value = key, value
          pair.save
        else
          pair.value = value
          pair.save
        end
        value
      end

      def to_hash
        Hash[ *find(:all).map { |pair| [pair.key, pair.value] }.flatten ]
      end      
    end
    
    def value=(param)
      write_attribute :value, param.to_s
    end
    
    def value
      if key.ends_with? "?"
        read_attribute(:value) == "true"
      else
        read_attribute(:value)
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
radiant-0.6.4 app/models/radiant/config.rb
radiant-0.6.5.1 app/models/radiant/config.rb
radiant-0.6.5 app/models/radiant/config.rb
radiant-0.6.6 app/models/radiant/config.rb
radiant-0.6.7 app/models/radiant/config.rb
radiant-0.6.9 app/models/radiant/config.rb
radiant-0.6.8 app/models/radiant/config.rb