settler 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/README.rdoc +54 -53
  2. data/VERSION +1 -1
  3. data/settler.gemspec +62 -0
  4. metadata +3 -2
data/README.rdoc CHANGED
@@ -23,60 +23,62 @@ Or install as a plugin if you must. But gems are cooler.
23
23
  == Setup
24
24
 
25
25
  * You must create the table used by the Setting model and install an initial configuration file. Simply run this command:
26
- ruby script/generate settler
26
+
27
+ ruby script/generate settler
27
28
 
28
29
  * This will create a migration and will add a settler.yml configuration file in your config directory. Now just migrate the database:
29
- rake db:migrate
30
+
31
+ rake db:migrate
30
32
 
31
33
  * Next, you'll have to edit the settler.yml file, of which the details are described in the next section.
32
34
 
33
35
  * You can manually set the configuration file source and default namespace as follows:
34
- * Settler.source = '/path/to/my/settler.yml'
35
- * Settler.namespace = 'staging'
36
+ - Settler.source = '/path/to/my/settler.yml'
37
+ - Settler.namespace = 'staging'
36
38
 
37
39
  == Configuration
38
40
 
39
41
  The initial version of settler.yml contains example settings for every default Rails environment. A setting consists of at least a key and a value. Consider the following example:
40
42
 
41
- google_analytics_key:
42
- alt: Google analytics key
43
- value: 'UA-xxxxxx-x'
44
- editable: true
45
- deletable: false
46
- validations:
47
- presence: true
43
+ google_analytics_key:
44
+ alt: Google analytics key
45
+ value: 'UA-xxxxxx-x'
46
+ editable: true
47
+ deletable: false
48
+ validations:
49
+ presence: true
48
50
 
49
51
  In this case, 'google_analytics_key' is the key of the setting. Every nested property is either an attribute of the setting or a list of validations:
50
52
 
51
53
  * Alt, value, editable and deletable are attributes of the Setting model. If a Setting with a given key does not exist, it is created with the attributes found. Therefore, you can consider these attributes as the default values for the setting.
52
54
  * Validations are not part of every setting, but are loaded on validation of a Setting instance. They apply to the value of the setting. The following validations can be created:
53
- * 'presence', true/false.
54
- * 'inclusion', followed by a YAML array (e.g. ['a','b','c']). Accepts a comma separated string as well.
55
+ - 'presence', true/false.
56
+ - 'inclusion', followed by a YAML array (e.g. ['a','b','c']). Accepts a comma separated string as well.
55
57
 
56
- Note that you can use ERB in the configuration file if you need to. For example:
58
+ Note that you can use ERB in the configuration file if you need to. For example:
57
59
 
58
- google_analytics_key:
59
- value: '<%= GOOGLE_ANALYTICS_KEY %>'
60
+ google_analytics_key:
61
+ value: '<%= GOOGLE_ANALYTICS_KEY %>'
60
62
 
61
- will evaluate the GOOGLE_ANALYTICS_KEY constant.
63
+ will evaluate the GOOGLE_ANALYTICS_KEY constant.
62
64
 
63
65
  == Access settings
64
66
 
65
67
  * Accessors will be created for every defined setting, returning a Setting instance:
66
68
 
67
- > Settler.google_analytics_key
68
- Setting Load (0.7ms) SELECT * FROM "settings" WHERE ("settings"."key" = 'google_analytics_key') LIMIT 1
69
- +----+----------------------+----------------------+------------+----------+-----------+-------------------------+-------------------------+
70
- | id | key | alt | value | editable | deletable | created_at | updated_at |
71
- +----+----------------------+----------------------+------------+----------+-----------+-------------------------+-------------------------+
72
- | 6 | google_analytics_key | Google analytics key | UA-xxxxx-x | true | false | 2010-09-22 15:04:06 UTC | 2010-09-22 15:04:06 UTC |
73
- +----+----------------------+----------------------+------------+----------+-----------+-------------------------+-------------------------+
69
+ >> Settler.google_analytics_key
70
+ Setting Load (0.7ms) SELECT * FROM "settings" WHERE ("settings"."key" = 'google_analytics_key') LIMIT 1
71
+ +----+----------------------+----------------------+------------+----------+-----------+
72
+ | id | key | alt | value | editable | deletable |
73
+ +----+----------------------+----------------------+------------+----------+-----------+
74
+ | 6 | google_analytics_key | Google analytics key | UA-xxxxx-x | true | false |
75
+ +----+----------------------+----------------------+------------+----------+-----------+
74
76
 
75
77
  * You can access a setting's value quickly by using the index operator:
76
78
 
77
- > Settler[:google_analytics_key]
78
- Setting Load (0.7ms) SELECT * FROM "settings" WHERE ("settings"."key" = 'google_analytics_key') LIMIT 1
79
- => "UA-xxxxx-x"
79
+ >> Settler[:google_analytics_key]
80
+ Setting Load (0.7ms) SELECT * FROM "settings" WHERE ("settings"."key" = 'google_analytics_key') LIMIT 1
81
+ => "UA-xxxxx-x"
80
82
 
81
83
  == Changing / Destroying settings
82
84
 
@@ -84,52 +86,51 @@ will evaluate the GOOGLE_ANALYTICS_KEY constant.
84
86
 
85
87
  * By default, settings will only be editable or deletable iff the corresponding attribute is set to 'true'. This will be enforced before saving or destroying a record:
86
88
 
87
- > Settler.google_analytics_key.destroy
88
- Setting Load (0.7ms) SELECT * FROM "settings" WHERE ("settings"."key" = 'google_analytics_key') LIMIT 1
89
- => false
89
+ >> Settler.google_analytics_key.destroy
90
+ Setting Load (0.7ms) SELECT \* FROM "settings" WHERE ("settings"."key" = 'google_analytics_key') LIMIT 1
91
+ => false
90
92
 
91
- * The Setting model performs a soft delete when it is destroyed, meaning the record is not really destroyed, but just marked as deleted. The reason for doing this is because settings are reloaded from the configuration file when your application is (re)started, unless a setting is already available in the database. Therefore, it should know about all deleted settings, otherwise it would re-insert the
92
- deleted setting. If you want to enforce this behaviour, use Setting#delete instead.
93
+ * The Setting model performs a soft delete when it is destroyed, meaning the record is not really destroyed, but just marked as deleted. The reason for doing this is because settings are reloaded from the configuration file when your application is (re)started, unless a setting is already available in the database. Therefore, it should know about all deleted settings, otherwise it would re-insert the deleted setting. If you want to enforce this behaviour, use Setting#delete instead.
93
94
 
94
95
  == Advanced usage
95
96
 
96
97
  * When you define an inclusion validation on a setting, you can access these values for use in web forms by calling 'valid_values' on the setting:
97
98
 
98
- > Settler.search_algorithm.valid_values
99
- Setting Load (0.7ms) SELECT * FROM "settings" WHERE ("settings"."key" = 'search_algorithm') LIMIT 1
100
- => ["ferret", "sphinx"]
99
+ >> Settler.search_algorithm.valid_values
100
+ Setting Load (0.7ms) SELECT * FROM "settings" WHERE ("settings"."key" = 'search_algorithm') LIMIT 1
101
+ => ["ferret", "sphinx"]
101
102
 
102
- NB: This method returns nil when valid values cannot be found.
103
+ NB: This method returns nil when valid values cannot be found.
103
104
 
104
105
  * Overriding setting attributes in the configuration is not as easy as it seems, since YAML doesn't support nested node merges. When overriding specific setting attributes, you should therefore do something like this:
105
106
 
106
- settings: &settings
107
- google_analytics_key: &google
108
- alt: Google analytics key
109
- value: 'UA-xxxxxx-x'
110
-
111
- development:
112
- <<: *settings
113
- google_analytics_key:
114
- <<: *google
115
- alt: Development Google analytics key
116
- value: 'UA-xxxxxx-1'
107
+ settings: &settings
108
+ google_analytics_key: &google
109
+ alt: Google analytics key
110
+ value: 'UA-xxxxxx-x'
111
+
112
+ development:
113
+ <<: *settings
114
+ google_analytics_key:
115
+ <<: *google
116
+ alt: Development Google analytics key
117
+ value: 'UA-xxxxxx-1'
117
118
 
118
119
  * Report missing / raise missing
119
120
 
120
- * You can tell Settler to report missing attributes:
121
+ * You can tell Settler to report missing attributes:
121
122
 
122
- Settler.report_missing = true
123
+ Settler.report_missing = true
123
124
 
124
- This will output a warning to STDOUT and the Rails logger to notify you that a missing setting was requested.
125
+ This will output a warning to STDOUT and the Rails logger to notify you that a missing setting was requested.
125
126
 
126
- * It is also possible to raise an exception instead when requesting missing attributes:
127
+ * It is also possible to raise an exception instead when requesting missing attributes:
127
128
 
128
- Settler.raise_missing = true
129
+ Settler.raise_missing = true
129
130
 
130
131
  == To do
131
132
 
132
- - Add more validations, for now only 'presence' and 'inclusion' are supported.
133
+ * Add more validations, for now only 'presence' and 'inclusion' are supported.
133
134
 
134
135
  == Note on Patches/Pull Requests
135
136
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.0
1
+ 1.0.1
data/settler.gemspec ADDED
@@ -0,0 +1,62 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{settler}
8
+ s.version = "1.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Reinier de Lange"]
12
+ s.date = %q{2010-09-23}
13
+ s.description = %q{This gem is a combination of the Squeegy's rails-settings and Binarylogic's settingslogic gem, meaning it reads its configuration from a YAML file, but stores all settings in the database as well for on the fly changes.}
14
+ s.email = %q{r.j.delange@nedforce.nl}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ "LICENSE",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "generators/settler/settler_generator.rb",
27
+ "generators/settler/templates/migration.rb",
28
+ "generators/settler/templates/settler.yml",
29
+ "init.rb",
30
+ "lib/hash_extension.rb",
31
+ "lib/setting.rb",
32
+ "lib/settler.rb",
33
+ "settler.gemspec",
34
+ "test/database.yml",
35
+ "test/debug.log",
36
+ "test/helper.rb",
37
+ "test/schema.rb",
38
+ "test/settler.yml",
39
+ "test/test_settler.rb"
40
+ ]
41
+ s.homepage = %q{http://github.com/moiristo/settler}
42
+ s.rdoc_options = ["--charset=UTF-8"]
43
+ s.require_paths = ["lib"]
44
+ s.rubygems_version = %q{1.3.6}
45
+ s.summary = %q{Settler manages global application settings in Rails}
46
+ s.test_files = [
47
+ "test/helper.rb",
48
+ "test/schema.rb",
49
+ "test/test_settler.rb"
50
+ ]
51
+
52
+ if s.respond_to? :specification_version then
53
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
54
+ s.specification_version = 3
55
+
56
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
57
+ else
58
+ end
59
+ else
60
+ end
61
+ end
62
+
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 1
7
7
  - 0
8
- - 0
9
- version: 1.0.0
8
+ - 1
9
+ version: 1.0.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Reinier de Lange
@@ -41,6 +41,7 @@ files:
41
41
  - lib/hash_extension.rb
42
42
  - lib/setting.rb
43
43
  - lib/settler.rb
44
+ - settler.gemspec
44
45
  - test/database.yml
45
46
  - test/debug.log
46
47
  - test/helper.rb