Renamed helpers to correspond to renamed Controller classes.
[merb_radiant.git] / app / models / radiant / .svn / text-base / config.rb.svn-base
blob13f791d9d72b8dc3b5770250f8d3d816c1ef4e2d
1 module Radiant
2   #
3   # The Radiant::Config object emulates a hash with simple bracket methods
4   # which allow you to get and set values in the configuration table:
5   #
6   #   Radiant::Config['setting.name'] = 'value'
7   #   Radiant::Config['setting.name'] #=> "value"
8   #
9   # Currently, there is not a way to edit configuration through the admin
10   # system so it must be done manually. The console script is probably the
11   # easiest way to this:
12   #
13   #   % script/console production
14   #   Loading production environment.
15   #   >> Radiant::Config['setting.name'] = 'value'
16   #   => "value"
17   #   >> 
18   #
19   # Radiant currently uses the following settings:
20   #
21   # admin.title           :: the title of the admin system
22   # admin.subtitle        :: the subtitle of the admin system
23   # defaults.page.parts   :: a comma separated list of default page parts
24   # defaults.page.status  :: a string representation of the default page status
25   # dev.host              :: the hostname where draft pages are viewable
26   # local.timezone        :: the timezone offset (using a String or integer
27   #                          from http://api.rubyonrails.org/classes/TimeZone.html) 
28   #                          used to correct displayed times 
29   class Config < ActiveRecord::Base
30     set_table_name "config"
32     class << self
33       def [](key)
34         pair = find_by_key(key)
35         pair.value unless pair.nil?
36       end
38       def []=(key, value)
39         pair = find_by_key(key)
40         unless pair
41           pair = new
42           pair.key, pair.value = key, value
43           pair.save
44         else
45           pair.value = value
46           pair.save
47         end
48         value
49       end
51       def to_hash
52         Hash[ *find(:all).map { |pair| [pair.key, pair.value] }.flatten ]
53       end      
54     end
55     
56     def value=(param)
57       write_attribute :value, param.to_s
58     end
59     
60     def value
61       if key.ends_with? "?"
62         read_attribute(:value) == "true"
63       else
64         read_attribute(:value)
65       end
66     end
67   end
68 end