Class: Radiant::Config

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/radiant/config.rb

Overview

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

defaults.page.filter

the default filter to use on new page parts

defaults.page.fields

a comma separated list of the default page fields

dev.host

the hostname where draft pages are viewable

local.timezone

the timezone name (‘rake -D time` for full list) used to correct displayed times

page.edit.published_date?

when true, shows the datetime selector for published date on the page edit screen

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.[](key) ⇒ Object



37
38
39
40
41
42
43
44
45
46
# File 'app/models/radiant/config.rb', line 37

def [](key)
  if table_exists?
    unless Radiant::Config.cache_file_exists?
      Radiant::Config.ensure_cache_file
      Radiant::Config.initialize_cache
    end
    Radiant::Config.initialize_cache if Radiant::Config.stale_cache?
    Rails.cache.read('Radiant::Config')[key]
  end
end

.[]=(key, value) ⇒ Object



48
49
50
51
52
53
54
# File 'app/models/radiant/config.rb', line 48

def []=(key, value)
  if table_exists?
    pair = find_or_initialize_by_key(key)
    pair.update_attributes(:value => value)
    value
  end
end

.cache_fileObject



84
85
86
# File 'app/models/radiant/config.rb', line 84

def cache_file
  cache_file = File.join(cache_path,'radiant_config_cache.txt')
end

.cache_file_exists?Boolean

Returns:

  • (Boolean)


66
67
68
# File 'app/models/radiant/config.rb', line 66

def cache_file_exists?
  File.file?(cache_file)
end

.cache_pathObject



80
81
82
# File 'app/models/radiant/config.rb', line 80

def cache_path
  "#{Rails.root}/tmp"
end

.ensure_cache_fileObject



75
76
77
78
# File 'app/models/radiant/config.rb', line 75

def ensure_cache_file
  FileUtils.mkpath(cache_path)
  FileUtils.touch(cache_file)
end

.initialize_cacheObject



60
61
62
63
64
# File 'app/models/radiant/config.rb', line 60

def initialize_cache
  Radiant::Config.ensure_cache_file
  Rails.cache.write('Radiant::Config',Radiant::Config.to_hash)
  Rails.cache.write('Radiant.cache_mtime', File.mtime(cache_file))
end

.stale_cache?Boolean

Returns:

  • (Boolean)


70
71
72
73
# File 'app/models/radiant/config.rb', line 70

def stale_cache?
  return true unless Radiant::Config.cache_file_exists?
  Rails.cache.read('Radiant.cache_mtime') != File.mtime(cache_file)
end

.to_hashObject



56
57
58
# File 'app/models/radiant/config.rb', line 56

def to_hash
  Hash[ *find(:all).map { |pair| [pair.key, pair.value] }.flatten ]
end

Instance Method Details

#update_cacheObject



101
102
103
# File 'app/models/radiant/config.rb', line 101

def update_cache
  Radiant::Config.initialize_cache
end

#valueObject



93
94
95
96
97
98
99
# File 'app/models/radiant/config.rb', line 93

def value
  if key.ends_with? "?"
    self[:value] == "true"
  else
    self[:value]
  end
end

#value=(param) ⇒ Object



89
90
91
# File 'app/models/radiant/config.rb', line 89

def value=(param)
  self[:value] = param.to_s
end