Changesets can be listed by changeset number.
The Git repository is here.
- Revision:
- 15
- Log:
Attempt to update Typo to a Typo SVN HEAD release from around the
time the prototype installation was set up on the RISC OS Open Limited
web site. Timestamps place this at 04-Jul so a revision from 05-Jul or
earlier was pulled and copied over the 2.6.0 tarball stable code.
- Author:
- adh
- Date:
- Sat Jul 22 23:27:35 +0100 2006
- Size:
- 1743 Bytes
1 | module ConfigManager |
2 | def self.append_features(base) |
3 | super |
4 | base.extend(ClassMethods) |
5 | end |
6 | |
7 | module ClassMethods |
8 | def fields |
9 | @fields ||= Hash.new { Item.new } |
10 | end |
11 | |
12 | def setting(name, type=:object, default=nil) |
13 | item = Item.new |
14 | item.name, item.ruby_type, item.default = name.to_s, type, default |
15 | fields[name.to_s] = item |
16 | add_setting_accessor(item) |
17 | end |
18 | |
19 | def default_for(key) |
20 | fields[key.to_s].default |
21 | end |
22 | |
23 | private |
24 | |
25 | def add_setting_accessor(item) |
26 | add_setting_reader(item) |
27 | add_setting_writer(item) |
28 | end |
29 | |
30 | def add_setting_reader(item) |
31 | self.send(:define_method, item.name) do |
32 | raw_value = settings[item.name] |
33 | raw_value.nil? ? item.default : raw_value |
34 | end |
35 | if item.ruby_type == :boolean |
36 | self.send(:define_method, item.name + "?") do |
37 | raw_value = settings[item.name] |
38 | raw_value.nil? ? item.default : raw_value |
39 | end |
40 | end |
41 | end |
42 | |
43 | def add_setting_writer(item) |
44 | self.send(:define_method, "#{item.name}=") do |newvalue| |
45 | retval = settings[item.name] = canonicalize(item.name, newvalue) |
46 | self.save! unless new_record? |
47 | retval |
48 | end |
49 | end |
50 | |
51 | end |
52 | |
53 | def canonicalize(key, value) |
54 | self.class.fields[key.to_s].canonicalize(value) |
55 | end |
56 | |
57 | class Item |
58 | attr_accessor :name, :ruby_type, :default |
59 | |
60 | def canonicalize(value) |
61 | case ruby_type |
62 | when :boolean |
63 | case value |
64 | when "0", 0, '', false, "false", "f", nil |
65 | false |
66 | else |
67 | true |
68 | end |
69 | when :integer |
70 | value.to_i |
71 | when :string |
72 | value.to_s |
73 | when :yaml |
74 | value.to_yaml |
75 | else |
76 | value |
77 | end |
78 | end |
79 | end |
80 | end |