rails_config 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile.lock +2 -3
- data/README.md +30 -0
- data/lib/rails_config.rb +9 -2
- data/lib/rails_config/integration/rails.rb +34 -0
- data/lib/rails_config/integration/sinatra.rb +29 -0
- data/lib/rails_config/rack/reloader.rb +15 -0
- data/lib/rails_config/version.rb +1 -1
- metadata +7 -30
- data/lib/rails_config/railtie.rb +0 -31
data/Gemfile.lock
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
rails_config (0.2.
|
4
|
+
rails_config (0.2.2)
|
5
5
|
activesupport (~> 3.0)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: http://rubygems.org/
|
9
9
|
specs:
|
10
|
-
activesupport (3.0.
|
10
|
+
activesupport (3.0.6)
|
11
11
|
archive-tar-minitar (0.5.2)
|
12
12
|
autotest (4.4.3)
|
13
13
|
columnize (0.3.2)
|
@@ -44,7 +44,6 @@ PLATFORMS
|
|
44
44
|
ruby
|
45
45
|
|
46
46
|
DEPENDENCIES
|
47
|
-
activesupport (~> 3.0)
|
48
47
|
autotest
|
49
48
|
growl-glue
|
50
49
|
rails_config!
|
data/README.md
CHANGED
@@ -14,6 +14,8 @@ RailsConfig helps you easily manage environment specific Rails settings in an ea
|
|
14
14
|
## Compatibility
|
15
15
|
|
16
16
|
* Rails 3.0
|
17
|
+
* Padrino
|
18
|
+
* Sinatra
|
17
19
|
|
18
20
|
For older versions of Rails and other Ruby apps, use [AppConfig](http://github.com/fredwu/app_config).
|
19
21
|
|
@@ -23,6 +25,34 @@ Add this to your `Gemfile`:
|
|
23
25
|
|
24
26
|
gem "rails_config"
|
25
27
|
|
28
|
+
|
29
|
+
## Installing on Padrino
|
30
|
+
|
31
|
+
Add this to your `Gemfile`:
|
32
|
+
|
33
|
+
gem "rails_config"
|
34
|
+
|
35
|
+
in your app.rb, you'll also need to register RailsConfig
|
36
|
+
|
37
|
+
register RailsConfig
|
38
|
+
|
39
|
+
|
40
|
+
## Installing on Sinatra
|
41
|
+
|
42
|
+
Add this to your `Gemfile`:
|
43
|
+
|
44
|
+
gem "rails_config"
|
45
|
+
|
46
|
+
in your app, you'll need to register RailsConfig. You'll also need to give it a root so it can find the config files.
|
47
|
+
|
48
|
+
set :root, File.dirname(__FILE__)
|
49
|
+
register RailsConfig
|
50
|
+
|
51
|
+
It's also possible to initialize it manually within your configure block if you want to just give it some yml paths to load from.
|
52
|
+
|
53
|
+
RailsConfig.load_and_set_settings("/path/to/yaml1", "/path/to/yaml2", ...)
|
54
|
+
|
55
|
+
|
26
56
|
## Customizing RailsConfig
|
27
57
|
|
28
58
|
You may customize the behavior of RailsConfig by generating an initializer file:
|
data/lib/rails_config.rb
CHANGED
@@ -36,7 +36,14 @@ module RailsConfig
|
|
36
36
|
Kernel.send(:remove_const, RailsConfig.const_name) if Kernel.const_defined?(RailsConfig.const_name)
|
37
37
|
Kernel.const_set(RailsConfig.const_name, RailsConfig.load_files(files))
|
38
38
|
end
|
39
|
+
|
40
|
+
def self.reload!
|
41
|
+
Kernel.const_get(RailsConfig.const_name).reload!
|
42
|
+
end
|
39
43
|
end
|
40
44
|
|
41
|
-
# add
|
42
|
-
require
|
45
|
+
# add rails integration
|
46
|
+
require('rails_config/integration/rails') if defined?(::Rails)
|
47
|
+
|
48
|
+
# add sinatra integration
|
49
|
+
require('rails_config/integration/sinatra') if defined?(::Sinatra)
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module RailsConfig
|
2
|
+
module Integration
|
3
|
+
module Rails3
|
4
|
+
if defined?(Rails::Railtie)
|
5
|
+
class Railtie < Rails::Railtie
|
6
|
+
|
7
|
+
# manually load the custom initializer before everything else
|
8
|
+
initializer :load_custom_rails_config, :before => :bootstrap_hook do
|
9
|
+
initializer = Rails.root.join("config", "initializers", "rails_config")
|
10
|
+
require initializer if File.exist?(initializer)
|
11
|
+
end
|
12
|
+
|
13
|
+
# Parse the settings before any of the initializers
|
14
|
+
ActiveSupport.on_load :before_configuration, :yield => true do
|
15
|
+
RailsConfig.load_and_set_settings(
|
16
|
+
Rails.root.join("config", "settings.yml").to_s,
|
17
|
+
Rails.root.join("config", "settings", "#{Rails.env}.yml").to_s,
|
18
|
+
Rails.root.join("config", "environments", "#{Rails.env}.yml").to_s
|
19
|
+
)
|
20
|
+
end
|
21
|
+
|
22
|
+
# Rails Dev environment should reload the Settings on every request
|
23
|
+
if Rails.env.development?
|
24
|
+
initializer :rails_config_reload_on_development do
|
25
|
+
ActionController::Base.class_eval do
|
26
|
+
prepend_before_filter { ::RailsConfig.const_name.constantize.reload! }
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module RailsConfig
|
2
|
+
# provide helper to register within your Sinatra app
|
3
|
+
#
|
4
|
+
# set :root, File.dirname(__FILE__)
|
5
|
+
# register RailsConfig
|
6
|
+
#
|
7
|
+
def self.registered(app)
|
8
|
+
app.configure do |inner_app|
|
9
|
+
|
10
|
+
env = inner_app.environment || ENV["RACK_ENV"]
|
11
|
+
root = inner_app.root
|
12
|
+
|
13
|
+
# use Padrino settings if applicable
|
14
|
+
if defined?(Padrino)
|
15
|
+
env = Padrino.env
|
16
|
+
root = Padrino.root
|
17
|
+
end
|
18
|
+
|
19
|
+
RailsConfig.load_and_set_settings(
|
20
|
+
File.join(root.to_s, "config", "settings.yml").to_s,
|
21
|
+
File.join(root.to_s, "config", "settings", "#{env}.yml").to_s,
|
22
|
+
File.join(root.to_s, "config", "environments", "#{env}.yml").to_s
|
23
|
+
)
|
24
|
+
|
25
|
+
inner_app.use(Rack::Reloader) if inner_app.development?
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module RailsConfig
|
2
|
+
module Rack
|
3
|
+
# Rack middleware the reloads RailsConfig on every request (only use in dev mode)
|
4
|
+
class Reloader
|
5
|
+
def initialize(app)
|
6
|
+
@app = app
|
7
|
+
end
|
8
|
+
|
9
|
+
def call(env)
|
10
|
+
RailsConfig.reload!
|
11
|
+
@app.call(env)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/rails_config/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_config
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 2
|
9
|
-
- 1
|
10
|
-
version: 0.2.1
|
4
|
+
prerelease:
|
5
|
+
version: 0.2.2
|
11
6
|
platform: ruby
|
12
7
|
authors:
|
13
8
|
- Jacques Crocker
|
@@ -16,7 +11,7 @@ autorequire:
|
|
16
11
|
bindir: bin
|
17
12
|
cert_chain: []
|
18
13
|
|
19
|
-
date:
|
14
|
+
date: 2011-04-08 00:00:00 -07:00
|
20
15
|
default_executable:
|
21
16
|
dependencies:
|
22
17
|
- !ruby/object:Gem::Dependency
|
@@ -27,10 +22,6 @@ dependencies:
|
|
27
22
|
requirements:
|
28
23
|
- - ~>
|
29
24
|
- !ruby/object:Gem::Version
|
30
|
-
hash: 7
|
31
|
-
segments:
|
32
|
-
- 3
|
33
|
-
- 0
|
34
25
|
version: "3.0"
|
35
26
|
type: :runtime
|
36
27
|
version_requirements: *id001
|
@@ -42,10 +33,6 @@ dependencies:
|
|
42
33
|
requirements:
|
43
34
|
- - ~>
|
44
35
|
- !ruby/object:Gem::Version
|
45
|
-
hash: 3
|
46
|
-
segments:
|
47
|
-
- 2
|
48
|
-
- 0
|
49
36
|
version: "2.0"
|
50
37
|
type: :development
|
51
38
|
version_requirements: *id002
|
@@ -57,9 +44,6 @@ dependencies:
|
|
57
44
|
requirements:
|
58
45
|
- - ">="
|
59
46
|
- !ruby/object:Gem::Version
|
60
|
-
hash: 3
|
61
|
-
segments:
|
62
|
-
- 0
|
63
47
|
version: "0"
|
64
48
|
type: :development
|
65
49
|
version_requirements: *id003
|
@@ -71,9 +55,6 @@ dependencies:
|
|
71
55
|
requirements:
|
72
56
|
- - ">="
|
73
57
|
- !ruby/object:Gem::Version
|
74
|
-
hash: 3
|
75
|
-
segments:
|
76
|
-
- 0
|
77
58
|
version: "0"
|
78
59
|
type: :development
|
79
60
|
version_requirements: *id004
|
@@ -103,8 +84,10 @@ files:
|
|
103
84
|
- lib/generators/rails_config/templates/settings/production.yml
|
104
85
|
- lib/generators/rails_config/templates/settings/test.yml
|
105
86
|
- lib/rails_config.rb
|
87
|
+
- lib/rails_config/integration/rails.rb
|
88
|
+
- lib/rails_config/integration/sinatra.rb
|
106
89
|
- lib/rails_config/options.rb
|
107
|
-
- lib/rails_config/
|
90
|
+
- lib/rails_config/rack/reloader.rb
|
108
91
|
- lib/rails_config/sources/yaml_source.rb
|
109
92
|
- lib/rails_config/vendor/deep_merge.rb
|
110
93
|
- lib/rails_config/version.rb
|
@@ -139,23 +122,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
139
122
|
requirements:
|
140
123
|
- - ">="
|
141
124
|
- !ruby/object:Gem::Version
|
142
|
-
hash: 3
|
143
|
-
segments:
|
144
|
-
- 0
|
145
125
|
version: "0"
|
146
126
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
147
127
|
none: false
|
148
128
|
requirements:
|
149
129
|
- - ">="
|
150
130
|
- !ruby/object:Gem::Version
|
151
|
-
hash: 3
|
152
|
-
segments:
|
153
|
-
- 0
|
154
131
|
version: "0"
|
155
132
|
requirements: []
|
156
133
|
|
157
134
|
rubyforge_project:
|
158
|
-
rubygems_version: 1.
|
135
|
+
rubygems_version: 1.6.2
|
159
136
|
signing_key:
|
160
137
|
specification_version: 3
|
161
138
|
summary: Provides a Settings helper for rails3 that reads from config/settings.yml
|
data/lib/rails_config/railtie.rb
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
if defined?(Rails::Railtie)
|
2
|
-
module RailsConfig
|
3
|
-
class Railtie < Rails::Railtie
|
4
|
-
|
5
|
-
# manually load the custom initializer before everything else
|
6
|
-
initializer :load_custom_rails_config, :before => :bootstrap_hook do
|
7
|
-
initializer = Rails.root.join("config", "initializers", "rails_config")
|
8
|
-
require initializer if File.exist?(initializer)
|
9
|
-
end
|
10
|
-
|
11
|
-
# Parse the settings before any of the initializers
|
12
|
-
ActiveSupport.on_load :before_configuration, :yield => true do
|
13
|
-
RailsConfig.load_and_set_settings(
|
14
|
-
Rails.root.join("config", "settings.yml").to_s,
|
15
|
-
Rails.root.join("config", "settings", "#{Rails.env}.yml").to_s,
|
16
|
-
Rails.root.join("config", "environments", "#{Rails.env}.yml").to_s
|
17
|
-
)
|
18
|
-
end
|
19
|
-
|
20
|
-
# Rails Dev environment should reload the Settings on every request
|
21
|
-
if Rails.env.development?
|
22
|
-
initializer :rails_config_reload_on_development do
|
23
|
-
ActionController::Base.class_eval do
|
24
|
-
prepend_before_filter { ::RailsConfig.const_name.constantize.reload! }
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|