public
Description: Simple Config is a plugin designed to make application-wide configuration settings easy to set and access in an object-oriented fashion.
Homepage: http://labs.reevoo.com/plugins/simple-config
Clone URL: git://github.com/lukeredpath/simpleconfig.git
Removed artifacts from mephisto article (filters and what not)
lukeredpath (author)
Thu Jul 03 12:29:41 -0700 2008
commit  977f9faccd1db85cbb80e387b3e8ad4b0bfd9fba
tree    596a8b2414c711f8c2791b224c27114c972041ab
parent  cf98a7de05eb7df5ed7e530f0931673644da30dc
...
18
19
20
21
 
22
23
24
...
27
28
29
30
 
31
32
33
...
39
40
41
42
 
43
44
45
46
 
47
48
49
50
 
51
52
53
54
55
56
 
57
58
59
...
67
68
69
70
 
71
72
73
 
74
75
76
77
 
78
79
80
 
81
82
83
...
87
88
89
90
 
91
92
93
94
 
95
96
97
98
 
99
100
101
102
103
104
 
105
106
107
108
 
109
110
111
112
113
 
114
115
116
...
18
19
20
 
21
22
23
24
...
27
28
29
 
30
31
32
33
...
39
40
41
 
42
43
44
45
 
46
47
48
49
 
50
51
52
53
54
55
 
56
57
58
59
...
67
68
69
 
70
71
72
 
73
74
75
76
 
77
78
79
 
80
81
82
83
...
87
88
89
 
90
91
92
93
 
94
95
96
97
 
98
99
100
101
102
103
 
104
105
106
107
 
108
109
110
111
112
 
113
114
115
116
0
@@ -18,7 +18,7 @@ This will create a config/settings folder and a blank settings file for each of
0
 
0
 Now, if you open up the configuration.rb initializer, you will see something like this:
0
 
0
-<filter:jscode lang="ruby">
0
+<pre><code class="ruby">
0
 SimpleConfig.for :application do
0
 
0
   # your app configuration here
0
@@ -27,7 +27,7 @@ SimpleConfig.for :application do
0
   load File.join(RAILS_ROOT, 'config', "settings", "local.rb"), :if_exists? => true
0
   
0
 end
0
-</filter:jscode>
0
+</code></pre>
0
 
0
 This is where you can set any configuration variables that are required across all Rails environments. The <code>load</code> method works just like Ruby's built-in load method, except the contents of the file it loads are evaluated within the context of the <code>SimpleConfig.for</code> block. The <code>:if_exists?</code> flag, when set to true, means that the file will only be loaded if it exists, otherwise it will simply be ignored.
0
 
0
@@ -39,21 +39,21 @@ h3. Setting variables
0
 
0
 Setting variables is simple and will be familiar to anybody who has used Capistrano. Whether in your main <code>SimpleConfig.for</code> block in configuration.rb, or one of your external settings files, use the <code>set</code> method:
0
 
0
-<filter:jscode lang="ruby">
0
+<pre><code class="ruby">
0
 SimpleConfig.for :application do
0
   set :my_variable, 'hello world'
0
 end
0
-</filter:jscode>
0
+</code></pre>
0
 
0
 SimpleConfig also supports a form of namespacing that allows you to group logical sets of variables together:
0
 
0
-<filter:jscode lang="ruby">
0
+<pre><code class="ruby">
0
 SimpleConfig.for :application do
0
   group :awesome_stuff do
0
     set :my_variable, 'hello world'
0
   end
0
 end
0
-</filter:jscode>
0
+</code></pre>
0
 
0
 Both the <code>set</code> and <code>load</code> methods are available within <code>group</code> blocks and files loaded inside groups will be evaluated in the context of that group.
0
 
0
@@ -67,17 +67,17 @@ It is worth pointing out that <code>SimpleConfig.for</code> provides an almost s
0
 
0
 Once you have a reference to your configuration object, you can access variables using method access. Given the above example, <code>:my_variable</code> would be accessed in the following way:
0
 
0
-<filter:jscode lang="ruby">
0
+<pre><code class="ruby">
0
 config = SimpleConfig.for(:application)
0
 config.my_variable # => "hello world"
0
-</filter:jscode>
0
+</code></pre>
0
 
0
 Accessing grouped variables works as you would expect:
0
 
0
-<filter:jscode lang="ruby">
0
+<pre><code class="ruby">
0
 config = SimpleConfig.for(:application)
0
 config.awesome_stuff.my_variable # => "hello world"
0
-</filter:jscode>
0
+</code></pre>
0
 
0
 h3. Using your configuration in your Rails app
0
 
0
@@ -87,29 +87,29 @@ Note - there is no direct way of accessing your configuration variables in your
0
 
0
 To use the mixin, simply include it in your ApplicationController:
0
 
0
-<filter:jscode lang="ruby">
0
+<pre><code class="ruby">
0
 class ApplicationController < ActionController::Base
0
   include SimpleConfig::ControllerMixin
0
 end
0
-</filter:jscode>
0
+</code></pre>
0
 
0
 Then in your controllers:
0
 
0
-<filter:jscode lang="ruby">
0
+<pre><code class="ruby">
0
 class MyController < ApplicationController
0
   def index
0
     render :text => config.my_config_variable
0
   end
0
 end
0
-</filter:jscode>
0
+</code></pre>
0
 
0
 fn1(footnote). SimpleConfig was designed with Rails 2.0 in mind but it has been tested with Rails 1.2. To use the Rails-style initializers that SimpleConfig takes advantage of in Rails 1.2, simply add this to the bottom of your environment.rb file:
0
 
0
-<filter:jscode lang="ruby">
0
+<pre><code class="ruby">
0
 # backported Rails 2.x initializer folder functionality
0
 Dir[File.join(RAILS_ROOT, 'config', 'initializers', '*.rb')].each do |initializer|
0
   load initializer
0
 end
0
-</filter:jscode>
0
+</code></pre>
0
 
0
 fn2(footnote). In fact, I recommend you make sure your version control system ignores this file otherwise you risk checking in a file that will override values in production! If you are using Subversion, simply add local.rb to the svn:ignore property for the config/settings folder.
0
\ No newline at end of file

Comments

    No one has commented yet.