rails_config 0.0.7 → 0.1.0
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/Rakefile +2 -1
- data/TODO +7 -3
- data/VERSION +1 -1
- data/lib/generators/rails_config_generator.rb +11 -0
- data/lib/generators/templates/rails_config.rb +3 -0
- data/lib/rails_config.rb +11 -0
- data/lib/rails_config/railtie.rb +9 -1
- data/spec/rails_config_spec.rb +10 -0
- metadata +25 -5
data/Rakefile
CHANGED
@@ -8,9 +8,10 @@ begin
|
|
8
8
|
s.email = "railsjedi@gmail.com"
|
9
9
|
s.homepage = "http://github.com/railsjedi/rails_config"
|
10
10
|
s.description = "Provides an easy to use Application Configuration object"
|
11
|
-
s.authors = ["Jacques Crocker"]
|
11
|
+
s.authors = ["Jacques Crocker", "Fred Wu"]
|
12
12
|
s.files = FileList["[A-Z]*", "{bin,generators,lib,spec}/**/*"]
|
13
13
|
|
14
|
+
s.add_dependency 'active_support', ">=3.0.0.rc"
|
14
15
|
s.add_development_dependency 'rspec', ">=2.0.0.beta.19"
|
15
16
|
|
16
17
|
end
|
data/TODO
CHANGED
@@ -1,10 +1,14 @@
|
|
1
|
-
-
|
2
|
-
|
1
|
+
- Remove OStruct and use ActiveSupport::OrderedOptions instead (adds dependency to active_support 3.0)
|
2
|
+
|
3
3
|
- Add generator `rails_config:install` to create the default setting files
|
4
4
|
- config/settings.yml
|
5
5
|
- config/settings/development.yml
|
6
6
|
- config/settings/test.yml
|
7
7
|
- config/settings/production.yml
|
8
8
|
|
9
|
-
-
|
9
|
+
- Add generator `rails_config:override` that creates an config/rails_config.rb initializer and disables the default initialzer
|
10
10
|
|
11
|
+
|
12
|
+
DONE:
|
13
|
+
- Add a Rails before_filter that triggers Settings.reload! for each development request
|
14
|
+
- Allow user to customize the name of the global setting object (Settings)
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0
|
1
|
+
0.1.0
|
@@ -0,0 +1,11 @@
|
|
1
|
+
class RailsConfigGenerator < Rails::Generators::Base
|
2
|
+
desc "Generates a custom Rails Config initializer file."
|
3
|
+
|
4
|
+
def self.source_root
|
5
|
+
@_rails_config_source_root ||= File.expand_path("../templates", __FILE__)
|
6
|
+
end
|
7
|
+
|
8
|
+
def copy_initializer
|
9
|
+
template "rails_config.rb", "config/initializers/rails_config.rb"
|
10
|
+
end
|
11
|
+
end
|
data/lib/rails_config.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'active_support/core_ext/module/attribute_accessors'
|
1
2
|
require 'pathname'
|
2
3
|
require 'ostruct'
|
3
4
|
require 'yaml'
|
@@ -6,6 +7,16 @@ require 'erb'
|
|
6
7
|
require 'rails_config/vendor/deep_merge' unless defined?(DeepMerge)
|
7
8
|
|
8
9
|
module RailsConfig
|
10
|
+
# ensures the setup only gets run once
|
11
|
+
@@_ran_once = false
|
12
|
+
|
13
|
+
mattr_accessor :const_name
|
14
|
+
@@const_name = "Settings"
|
15
|
+
|
16
|
+
def self.setup
|
17
|
+
yield self if @@_ran_once == false
|
18
|
+
@@_ran_once = true
|
19
|
+
end
|
9
20
|
|
10
21
|
@@load_paths = []
|
11
22
|
def self.load_paths
|
data/lib/rails_config/railtie.rb
CHANGED
@@ -2,13 +2,21 @@ if defined?(Rails::Railtie)
|
|
2
2
|
module RailsConfig
|
3
3
|
class Railtie < Rails::Railtie
|
4
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
|
+
|
5
11
|
# Parse the settings before any of the initializers
|
6
12
|
ActiveSupport.on_load :before_initialize, :yield => true do
|
7
|
-
|
13
|
+
settings = RailsConfig.load_files(
|
8
14
|
Rails.root.join("config", "settings.yml").to_s,
|
9
15
|
Rails.root.join("config", "settings", "#{Rails.env}.yml").to_s,
|
10
16
|
Rails.root.join("config", "environments", "#{Rails.env}.yml").to_s
|
11
17
|
)
|
18
|
+
|
19
|
+
Kernel.const_set(RailsConfig.const_name, settings)
|
12
20
|
end
|
13
21
|
|
14
22
|
# Rails Dev environment should reload the Settings on every request
|
data/spec/rails_config_spec.rb
CHANGED
@@ -103,5 +103,15 @@ describe RailsConfig do
|
|
103
103
|
end
|
104
104
|
end
|
105
105
|
|
106
|
+
context "Custom Configuration" do
|
107
|
+
it "should have the default settings constant as 'Settings'" do
|
108
|
+
RailsConfig.const_name.should == "Settings"
|
109
|
+
end
|
110
|
+
|
111
|
+
it "should be able to assign a different settings constant" do
|
112
|
+
RailsConfig.setup{ |config| config.const_name = "Settings2" }
|
113
|
+
RailsConfig.const_name.should == "Settings2"
|
114
|
+
end
|
115
|
+
end
|
106
116
|
|
107
117
|
end
|
metadata
CHANGED
@@ -1,16 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_config
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
+
- 1
|
8
9
|
- 0
|
9
|
-
|
10
|
-
version: 0.0.7
|
10
|
+
version: 0.1.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Jacques Crocker
|
14
|
+
- Fred Wu
|
14
15
|
autorequire:
|
15
16
|
bindir: bin
|
16
17
|
cert_chain: []
|
@@ -19,9 +20,26 @@ date: 2010-08-10 00:00:00 -07:00
|
|
19
20
|
default_executable:
|
20
21
|
dependencies:
|
21
22
|
- !ruby/object:Gem::Dependency
|
22
|
-
name:
|
23
|
+
name: active_support
|
23
24
|
prerelease: false
|
24
25
|
requirement: &id001 !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ">="
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
hash: 7712042
|
31
|
+
segments:
|
32
|
+
- 3
|
33
|
+
- 0
|
34
|
+
- 0
|
35
|
+
- rc
|
36
|
+
version: 3.0.0.rc
|
37
|
+
type: :runtime
|
38
|
+
version_requirements: *id001
|
39
|
+
- !ruby/object:Gem::Dependency
|
40
|
+
name: rspec
|
41
|
+
prerelease: false
|
42
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
25
43
|
none: false
|
26
44
|
requirements:
|
27
45
|
- - ">="
|
@@ -35,7 +53,7 @@ dependencies:
|
|
35
53
|
- 19
|
36
54
|
version: 2.0.0.beta.19
|
37
55
|
type: :development
|
38
|
-
version_requirements: *
|
56
|
+
version_requirements: *id002
|
39
57
|
description: Provides an easy to use Application Configuration object
|
40
58
|
email: railsjedi@gmail.com
|
41
59
|
executables: []
|
@@ -54,6 +72,8 @@ files:
|
|
54
72
|
- Rakefile
|
55
73
|
- TODO
|
56
74
|
- VERSION
|
75
|
+
- lib/generators/rails_config_generator.rb
|
76
|
+
- lib/generators/templates/rails_config.rb
|
57
77
|
- lib/rails_config.rb
|
58
78
|
- lib/rails_config/railtie.rb
|
59
79
|
- lib/rails_config/vendor/deep_merge.rb
|