yappconfig 0.2.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/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +16 -0
- data/Gemfile.lock +111 -0
- data/LICENSE.txt +20 -0
- data/README.md +102 -0
- data/Rakefile +50 -0
- data/VERSION +1 -0
- data/lib/app-config/railtie.rb +15 -0
- data/lib/app-config.rb +98 -0
- data/lib/yappconfig.rb +1 -0
- data/spec/app-config/rails_spec.rb +35 -0
- data/spec/app-config_spec.rb +87 -0
- data/spec/config/config.yml +0 -0
- data/spec/config/reloader.yml +1 -0
- data/spec/config/single_stage.yml +1 -0
- data/spec/config/test.yml +6 -0
- data/spec/dummy/.gitignore +15 -0
- data/spec/dummy/Gemfile +38 -0
- data/spec/dummy/Gemfile.lock +111 -0
- data/spec/dummy/README.rdoc +261 -0
- data/spec/dummy/Rakefile +7 -0
- data/spec/dummy/app/assets/images/rails.png +0 -0
- data/spec/dummy/app/assets/javascripts/application.js +15 -0
- data/spec/dummy/app/assets/stylesheets/application.css +13 -0
- data/spec/dummy/app/controllers/application_controller.rb +3 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/mailers/.gitkeep +0 -0
- data/spec/dummy/app/models/.gitkeep +0 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/config/application.rb +59 -0
- data/spec/dummy/config/boot.rb +6 -0
- data/spec/dummy/config/config.yml +0 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +37 -0
- data/spec/dummy/config/environments/production.rb +67 -0
- data/spec/dummy/config/environments/test.rb +37 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/inflections.rb +15 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +7 -0
- data/spec/dummy/config/initializers/session_store.rb +8 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +5 -0
- data/spec/dummy/config/routes.rb +58 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/db/seeds.rb +7 -0
- data/spec/dummy/lib/assets/.gitkeep +0 -0
- data/spec/dummy/lib/tasks/.gitkeep +0 -0
- data/spec/dummy/log/.gitkeep +0 -0
- data/spec/dummy/public/404.html +26 -0
- data/spec/dummy/public/422.html +26 -0
- data/spec/dummy/public/500.html +25 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/public/index.html +241 -0
- data/spec/dummy/public/robots.txt +5 -0
- data/spec/dummy/script/rails +6 -0
- data/spec/dummy/test/fixtures/.gitkeep +0 -0
- data/spec/dummy/test/functional/.gitkeep +0 -0
- data/spec/dummy/test/integration/.gitkeep +0 -0
- data/spec/dummy/test/performance/browsing_test.rb +12 -0
- data/spec/dummy/test/test_helper.rb +13 -0
- data/spec/dummy/test/unit/.gitkeep +0 -0
- data/spec/dummy/vendor/assets/javascripts/.gitkeep +0 -0
- data/spec/dummy/vendor/assets/stylesheets/.gitkeep +0 -0
- data/spec/dummy/vendor/plugins/.gitkeep +0 -0
- data/spec/spec_helper.rb +21 -0
- data/yappconfig.gemspec +126 -0
- metadata +233 -0
data/.document
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
|
3
|
+
# Gems required for this gem
|
4
|
+
gem "hashie"
|
5
|
+
|
6
|
+
# Add dependencies to develop your gem here.
|
7
|
+
# Include everything needed to run rake, tests, features, etc.
|
8
|
+
group :development do
|
9
|
+
gem "rspec", "~> 2.8.0"
|
10
|
+
gem "rdoc", "~> 3.12"
|
11
|
+
gem "bundler"
|
12
|
+
gem "jeweler", "~> 1.8.3"
|
13
|
+
gem "simplecov"
|
14
|
+
|
15
|
+
gem "rails"
|
16
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
actionmailer (3.2.3)
|
5
|
+
actionpack (= 3.2.3)
|
6
|
+
mail (~> 2.4.4)
|
7
|
+
actionpack (3.2.3)
|
8
|
+
activemodel (= 3.2.3)
|
9
|
+
activesupport (= 3.2.3)
|
10
|
+
builder (~> 3.0.0)
|
11
|
+
erubis (~> 2.7.0)
|
12
|
+
journey (~> 1.0.1)
|
13
|
+
rack (~> 1.4.0)
|
14
|
+
rack-cache (~> 1.2)
|
15
|
+
rack-test (~> 0.6.1)
|
16
|
+
sprockets (~> 2.1.2)
|
17
|
+
activemodel (3.2.3)
|
18
|
+
activesupport (= 3.2.3)
|
19
|
+
builder (~> 3.0.0)
|
20
|
+
activerecord (3.2.3)
|
21
|
+
activemodel (= 3.2.3)
|
22
|
+
activesupport (= 3.2.3)
|
23
|
+
arel (~> 3.0.2)
|
24
|
+
tzinfo (~> 0.3.29)
|
25
|
+
activeresource (3.2.3)
|
26
|
+
activemodel (= 3.2.3)
|
27
|
+
activesupport (= 3.2.3)
|
28
|
+
activesupport (3.2.3)
|
29
|
+
i18n (~> 0.6)
|
30
|
+
multi_json (~> 1.0)
|
31
|
+
arel (3.0.2)
|
32
|
+
builder (3.0.0)
|
33
|
+
diff-lcs (1.1.3)
|
34
|
+
erubis (2.7.0)
|
35
|
+
git (1.2.5)
|
36
|
+
hashie (1.2.0)
|
37
|
+
hike (1.2.1)
|
38
|
+
i18n (0.6.0)
|
39
|
+
jeweler (1.8.3)
|
40
|
+
bundler (~> 1.0)
|
41
|
+
git (>= 1.2.5)
|
42
|
+
rake
|
43
|
+
rdoc
|
44
|
+
journey (1.0.3)
|
45
|
+
json (1.6.6)
|
46
|
+
mail (2.4.4)
|
47
|
+
i18n (>= 0.4.0)
|
48
|
+
mime-types (~> 1.16)
|
49
|
+
treetop (~> 1.4.8)
|
50
|
+
mime-types (1.18)
|
51
|
+
multi_json (1.2.0)
|
52
|
+
polyglot (0.3.3)
|
53
|
+
rack (1.4.1)
|
54
|
+
rack-cache (1.2)
|
55
|
+
rack (>= 0.4)
|
56
|
+
rack-ssl (1.3.2)
|
57
|
+
rack
|
58
|
+
rack-test (0.6.1)
|
59
|
+
rack (>= 1.0)
|
60
|
+
rails (3.2.3)
|
61
|
+
actionmailer (= 3.2.3)
|
62
|
+
actionpack (= 3.2.3)
|
63
|
+
activerecord (= 3.2.3)
|
64
|
+
activeresource (= 3.2.3)
|
65
|
+
activesupport (= 3.2.3)
|
66
|
+
bundler (~> 1.0)
|
67
|
+
railties (= 3.2.3)
|
68
|
+
railties (3.2.3)
|
69
|
+
actionpack (= 3.2.3)
|
70
|
+
activesupport (= 3.2.3)
|
71
|
+
rack-ssl (~> 1.3.2)
|
72
|
+
rake (>= 0.8.7)
|
73
|
+
rdoc (~> 3.4)
|
74
|
+
thor (~> 0.14.6)
|
75
|
+
rake (0.9.2.2)
|
76
|
+
rdoc (3.12)
|
77
|
+
json (~> 1.4)
|
78
|
+
rspec (2.8.0)
|
79
|
+
rspec-core (~> 2.8.0)
|
80
|
+
rspec-expectations (~> 2.8.0)
|
81
|
+
rspec-mocks (~> 2.8.0)
|
82
|
+
rspec-core (2.8.0)
|
83
|
+
rspec-expectations (2.8.0)
|
84
|
+
diff-lcs (~> 1.1.2)
|
85
|
+
rspec-mocks (2.8.0)
|
86
|
+
simplecov (0.6.1)
|
87
|
+
multi_json (~> 1.0)
|
88
|
+
simplecov-html (~> 0.5.3)
|
89
|
+
simplecov-html (0.5.3)
|
90
|
+
sprockets (2.1.2)
|
91
|
+
hike (~> 1.2)
|
92
|
+
rack (~> 1.0)
|
93
|
+
tilt (~> 1.1, != 1.3.0)
|
94
|
+
thor (0.14.6)
|
95
|
+
tilt (1.3.3)
|
96
|
+
treetop (1.4.10)
|
97
|
+
polyglot
|
98
|
+
polyglot (>= 0.3.1)
|
99
|
+
tzinfo (0.3.33)
|
100
|
+
|
101
|
+
PLATFORMS
|
102
|
+
ruby
|
103
|
+
|
104
|
+
DEPENDENCIES
|
105
|
+
bundler
|
106
|
+
hashie
|
107
|
+
jeweler (~> 1.8.3)
|
108
|
+
rails
|
109
|
+
rdoc (~> 3.12)
|
110
|
+
rspec (~> 2.8.0)
|
111
|
+
simplecov
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012 David Somers <jalada@gmail.com>
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
# yappconfig
|
2
|
+
|
3
|
+
A clean way to use a YAML file for configuration.
|
4
|
+
|
5
|
+
## Configuring
|
6
|
+
|
7
|
+
In Rails, yappconfig should Just Work™. For everything else you can configure it
|
8
|
+
using a `configure` block:
|
9
|
+
|
10
|
+
AppConfig.configure do |config|
|
11
|
+
config.config_file = "/path/to/config" # Default in Rails app is config/config.yml.
|
12
|
+
config.environment = "production" # Multi-stage config files, default none.
|
13
|
+
config.auto_reload = false # Defaults to true.
|
14
|
+
end
|
15
|
+
|
16
|
+
## Accessing configuration settings
|
17
|
+
|
18
|
+
Once configured you can use yappconfig throughout your app by accessing your
|
19
|
+
configuration through the `AppConfig` constant. For example:
|
20
|
+
|
21
|
+
# config/config.yml
|
22
|
+
twitter:
|
23
|
+
access_token: "MY_TWITTER_TOKEN"
|
24
|
+
|
25
|
+
# In your app
|
26
|
+
AppConfig.twitter.access_token
|
27
|
+
# => "MY_TWITTER_TOKEN"
|
28
|
+
|
29
|
+
You can also access it through other constants: `APP_CONFIG`, `YappConfig` and
|
30
|
+
`YAPP_CONFIG`. Whichever you prefer :).
|
31
|
+
|
32
|
+
## Sample configuration files
|
33
|
+
|
34
|
+
yappconfig supports single stage and multi-stage files. In Rails it will expect
|
35
|
+
a multi-stage file where the stages correspond with your Rails environment
|
36
|
+
variable. It will also expect the configuration file to be in
|
37
|
+
`config/config.yml` in the root of your application.
|
38
|
+
|
39
|
+
### Single stage example
|
40
|
+
|
41
|
+
simple_config: "is simple"
|
42
|
+
nested_config:
|
43
|
+
is_nested: true
|
44
|
+
|
45
|
+
### Multi-stage example
|
46
|
+
|
47
|
+
Here, every stage inherits from defaults and then configurations can be
|
48
|
+
overriden.
|
49
|
+
|
50
|
+
defaults: &defaults
|
51
|
+
|
52
|
+
multistage_config: "is clever"
|
53
|
+
|
54
|
+
development:
|
55
|
+
<<: *defaults
|
56
|
+
|
57
|
+
production:
|
58
|
+
<<: *defaults
|
59
|
+
|
60
|
+
multistage_config: "is very clever"
|
61
|
+
|
62
|
+
Watch out for this:
|
63
|
+
|
64
|
+
defaults: &defaults
|
65
|
+
|
66
|
+
server:
|
67
|
+
host: localhost
|
68
|
+
port: 6789
|
69
|
+
|
70
|
+
production:
|
71
|
+
<<: *defaults
|
72
|
+
|
73
|
+
server:
|
74
|
+
host: production-box
|
75
|
+
# port is now unset!
|
76
|
+
|
77
|
+
That is, by overriding `server` all nested values have been 'deleted' because
|
78
|
+
it has been overridden with a new hash. In this example, you would have to
|
79
|
+
explicitly set `port` again in production. For this reason, it's probably best
|
80
|
+
to avoid too much nesting...
|
81
|
+
|
82
|
+
|
83
|
+
## Contributing to yappconfig
|
84
|
+
|
85
|
+
* Check out the latest master to make sure the feature hasn't been implemented
|
86
|
+
or the bug hasn't been fixed yet.
|
87
|
+
* Check out the issue tracker to make sure someone already hasn't requested it
|
88
|
+
and/or contributed it.
|
89
|
+
* Fork the project.
|
90
|
+
* Start a feature/bugfix branch.
|
91
|
+
* Commit and push until you are happy with your contribution.
|
92
|
+
* Make sure to add tests for it. This is important so I don't break it in a
|
93
|
+
future version unintentionally.
|
94
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to
|
95
|
+
have your own version, or is otherwise necessary, that is fine, but please
|
96
|
+
isolate to its own commit so I can cherry-pick around it.
|
97
|
+
|
98
|
+
## Copyright
|
99
|
+
|
100
|
+
Copyright (c) 2012 David Somers <jalada@gmail.com>. See LICENSE.txt for further
|
101
|
+
details.
|
102
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "yappconfig"
|
18
|
+
gem.homepage = "http://github.com/jalada/yappconfig"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{An application config, best for Rails apps}
|
21
|
+
gem.description = %Q{yappconfig provides your application with a global configuration based on the environment. The configuration is loaded in from YAML. It has sensible defaults for Rails applications}
|
22
|
+
gem.email = "jalada@gmail.com"
|
23
|
+
gem.authors = ["David Somers"]
|
24
|
+
|
25
|
+
gem.files.exclude 'spec/dummy'
|
26
|
+
end
|
27
|
+
Jeweler::RubygemsDotOrgTasks.new
|
28
|
+
|
29
|
+
require 'rspec/core'
|
30
|
+
require 'rspec/core/rake_task'
|
31
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
32
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
33
|
+
end
|
34
|
+
|
35
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
36
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
37
|
+
spec.rcov = true
|
38
|
+
end
|
39
|
+
|
40
|
+
task :default => :spec
|
41
|
+
|
42
|
+
require 'rdoc/task'
|
43
|
+
Rake::RDocTask.new do |rdoc|
|
44
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
45
|
+
|
46
|
+
rdoc.rdoc_dir = 'rdoc'
|
47
|
+
rdoc.title = "yappconfig #{version}"
|
48
|
+
rdoc.rdoc_files.include('README*')
|
49
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
50
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.2.0
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'rails'
|
2
|
+
|
3
|
+
module AppConfig
|
4
|
+
class Railtie < Rails::Railtie
|
5
|
+
|
6
|
+
initializer "app-config.configure_for_rails" do
|
7
|
+
AppConfig.configure do |config|
|
8
|
+
config.config_file = Rails.root.join("config", "config.yml")
|
9
|
+
config.environment = Rails.env
|
10
|
+
config.auto_reload = true if Rails.env == "development"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
data/lib/app-config.rb
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
require 'app-config/railtie' if defined?(Rails)
|
2
|
+
require 'erb'
|
3
|
+
|
4
|
+
# Public: Application Configuration singleton. Config is stored within as
|
5
|
+
# a class
|
6
|
+
module AppConfig
|
7
|
+
|
8
|
+
# Private: Standard error.
|
9
|
+
class Error < StandardError; end
|
10
|
+
|
11
|
+
# Private: Actual configuration class. A new one of these is created whenever
|
12
|
+
# AppConfig is configured.
|
13
|
+
class Config
|
14
|
+
require 'hashie'
|
15
|
+
|
16
|
+
# Private: Initialize the class with a filename and environment (optional).
|
17
|
+
# Takes a hash of options.
|
18
|
+
#
|
19
|
+
# filename - configuration filename. Must exist.
|
20
|
+
# environment - optional, environment to pick in the configuration file.
|
21
|
+
#
|
22
|
+
# Returns the new config.
|
23
|
+
def initialize(options)
|
24
|
+
@options = options
|
25
|
+
yaml = YAML.load(ERB.new(IO.read @options.config_file).result)
|
26
|
+
yaml = yaml[@options.environment] if @options.environment
|
27
|
+
@config = Hashie::Mash.new yaml
|
28
|
+
@last_mtime = File.mtime @options.config_file
|
29
|
+
@config
|
30
|
+
end
|
31
|
+
|
32
|
+
# Private: Override method_missing to access the config object. If the file
|
33
|
+
# has been modified and auto_reload is set to true, re-run initialize.
|
34
|
+
#
|
35
|
+
# Returns the result of applying the method to the config object.
|
36
|
+
def method_missing(method, *args, &block)
|
37
|
+
if @options.auto_reload and @last_mtime != File.mtime(@options.config_file)
|
38
|
+
initialize @options
|
39
|
+
end
|
40
|
+
@config.__send__(method, *args, &block)
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
# Create a configuration attribute
|
46
|
+
class << self
|
47
|
+
attr_accessor :configuration
|
48
|
+
end
|
49
|
+
|
50
|
+
# Public: Configure AppConfig. Note that repeated calls to configure will
|
51
|
+
# reset all configuration and clear the existing config class. Therefore you
|
52
|
+
# need to configure AppConfig all in one go, or alternatively access
|
53
|
+
# configuration parameters directly e.g. AppConfig.configuration.config_file
|
54
|
+
#
|
55
|
+
# Yields to the provided block, then sets defaults on top.
|
56
|
+
def self.configure(&block)
|
57
|
+
self.configuration = Configuration.new
|
58
|
+
@klass = nil
|
59
|
+
yield(configuration)
|
60
|
+
self.configuration.defaults
|
61
|
+
end
|
62
|
+
|
63
|
+
# Private: Holds the configuration.
|
64
|
+
class Configuration
|
65
|
+
attr_accessor :environment
|
66
|
+
attr_accessor :config_file
|
67
|
+
attr_accessor :auto_reload
|
68
|
+
|
69
|
+
# Private: Set default configuration values that haven't been set by
|
70
|
+
# the user
|
71
|
+
def defaults
|
72
|
+
@auto_reload ||= @environment == "production" ? false : true
|
73
|
+
end
|
74
|
+
|
75
|
+
def config_file=(filename)
|
76
|
+
raise Error, "File does not exist or is not a file: #{filename}" unless File.file? filename
|
77
|
+
@config_file = filename
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def self.method_missing(method, *args, &block)
|
82
|
+
if @klass || self.configuration.config_file
|
83
|
+
@klass ||= Config.new(self.configuration)
|
84
|
+
@klass.__send__(method, *args, &block)
|
85
|
+
else
|
86
|
+
raise Error, "Please set a config_file with AppConfig.configure first"
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
# Default configuration
|
91
|
+
configure {}
|
92
|
+
|
93
|
+
end
|
94
|
+
|
95
|
+
# Alias for old applications
|
96
|
+
APP_CONFIG = AppConfig
|
97
|
+
# Alias for people who like to yap.
|
98
|
+
YappConfig = YAPP_CONFIG = AppConfig
|
data/lib/yappconfig.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'app-config'
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
ENV["RAILS_ENV"] ||= "test"
|
4
|
+
require File.expand_path("../../dummy/config/environment.rb", __FILE__)
|
5
|
+
|
6
|
+
require 'app-config/railtie'
|
7
|
+
|
8
|
+
describe "AppConfig with Rails" do
|
9
|
+
|
10
|
+
before :each do
|
11
|
+
AppConfig::Railtie.initializers.map{|i| i.run}
|
12
|
+
end
|
13
|
+
|
14
|
+
it "Should default to the Rails environment" do
|
15
|
+
AppConfig.configuration.environment.should == Rails.env
|
16
|
+
end
|
17
|
+
|
18
|
+
it "Should default to Rails.root/config/config.yml" do
|
19
|
+
AppConfig.configuration.config_file.should == Rails.root.join("config/config.yml")
|
20
|
+
end
|
21
|
+
|
22
|
+
it "Auto reloads if the Rails environment is development" do
|
23
|
+
Rails.env = "development"
|
24
|
+
AppConfig::Railtie.initializers.map{|i| i.run}
|
25
|
+
AppConfig.configuration.auto_reload.should == true
|
26
|
+
end
|
27
|
+
|
28
|
+
it "Doesn't auto-reload if the Rails environment is production" do
|
29
|
+
Rails.env = "production"
|
30
|
+
AppConfig::Railtie.initializers.map{|i| i.run}
|
31
|
+
AppConfig.configuration.auto_reload.should_not == true
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "AppConfig" do
|
4
|
+
|
5
|
+
|
6
|
+
it "Should be accessible through APP_CONFIG too" do
|
7
|
+
APP_CONFIG.should == AppConfig
|
8
|
+
end
|
9
|
+
|
10
|
+
it "Should set a config file" do
|
11
|
+
AppConfig.configure do |config|
|
12
|
+
config.config_file = config_file("test.yml")
|
13
|
+
end
|
14
|
+
AppConfig.configuration.config_file.should == config_file("test.yml")
|
15
|
+
end
|
16
|
+
|
17
|
+
it "Should set an environment" do
|
18
|
+
AppConfig.configure do |config|
|
19
|
+
config.environment = "production"
|
20
|
+
end
|
21
|
+
AppConfig.configuration.environment.should == "production"
|
22
|
+
end
|
23
|
+
|
24
|
+
it "Should raise an exception if config is accessed without setting a file" do
|
25
|
+
expect { AppConfig.random_method }.to raise_error(AppConfig::Error, /Please set/)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "Should default to autoreload" do
|
29
|
+
AppConfig.configuration.auto_reload.should == true
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "accessing the config" do
|
33
|
+
describe "Single stage configuration" do
|
34
|
+
before :each do
|
35
|
+
AppConfig.configure do |config|
|
36
|
+
config.config_file = config_file("single_stage.yml")
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
it "Should work" do
|
41
|
+
AppConfig.simple_config.should == "is simple"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
before :each do
|
46
|
+
AppConfig.configure do |config|
|
47
|
+
config.config_file = config_file("test.yml")
|
48
|
+
config.environment = "development"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
it "Should support dot notation" do
|
53
|
+
AppConfig.test_key.should == "value"
|
54
|
+
end
|
55
|
+
|
56
|
+
it "Should support square bracket notation" do
|
57
|
+
AppConfig[:test_key].should == "value"
|
58
|
+
end
|
59
|
+
|
60
|
+
describe "With auto-reload" do
|
61
|
+
before :all do
|
62
|
+
@original = File.read config_file("reloader.yml")
|
63
|
+
end
|
64
|
+
|
65
|
+
after :each do
|
66
|
+
f = File.open(config_file("reloader.yml"), "w")
|
67
|
+
f.write @original
|
68
|
+
f.close
|
69
|
+
end
|
70
|
+
|
71
|
+
before :each do
|
72
|
+
AppConfig.configure do |config|
|
73
|
+
config.config_file = config_file("reloader.yml")
|
74
|
+
config.auto_reload = true
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
it "Should auto_reload on file change" do
|
79
|
+
AppConfig.test_key.should == 1
|
80
|
+
f = File.open(config_file("reloader.yml"), "w")
|
81
|
+
f.write(@original.gsub(/1/, "2"))
|
82
|
+
f.close
|
83
|
+
AppConfig.test_key.should == 2
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
:test_key: 1
|
@@ -0,0 +1 @@
|
|
1
|
+
:simple_config: "is simple"
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# See http://help.github.com/ignore-files/ for more about ignoring files.
|
2
|
+
#
|
3
|
+
# If you find yourself ignoring temporary files generated by your text editor
|
4
|
+
# or operating system, you probably want to add a global ignore instead:
|
5
|
+
# git config --global core.excludesfile ~/.gitignore_global
|
6
|
+
|
7
|
+
# Ignore bundler config
|
8
|
+
/.bundle
|
9
|
+
|
10
|
+
# Ignore the default SQLite database.
|
11
|
+
/db/*.sqlite3
|
12
|
+
|
13
|
+
# Ignore all logfiles and tempfiles.
|
14
|
+
/log/*.log
|
15
|
+
/tmp
|
data/spec/dummy/Gemfile
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
gem 'rails', '3.2.3'
|
4
|
+
|
5
|
+
# Bundle edge Rails instead:
|
6
|
+
# gem 'rails', :git => 'git://github.com/rails/rails.git'
|
7
|
+
|
8
|
+
gem 'sqlite3'
|
9
|
+
|
10
|
+
|
11
|
+
# Gems used only for assets and not required
|
12
|
+
# in production environments by default.
|
13
|
+
group :assets do
|
14
|
+
gem 'sass-rails', '~> 3.2.3'
|
15
|
+
gem 'coffee-rails', '~> 3.2.1'
|
16
|
+
|
17
|
+
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
|
18
|
+
# gem 'therubyracer', :platform => :ruby
|
19
|
+
|
20
|
+
gem 'uglifier', '>= 1.0.3'
|
21
|
+
end
|
22
|
+
|
23
|
+
gem 'jquery-rails'
|
24
|
+
|
25
|
+
# To use ActiveModel has_secure_password
|
26
|
+
# gem 'bcrypt-ruby', '~> 3.0.0'
|
27
|
+
|
28
|
+
# To use Jbuilder templates for JSON
|
29
|
+
# gem 'jbuilder'
|
30
|
+
|
31
|
+
# Use unicorn as the app server
|
32
|
+
# gem 'unicorn'
|
33
|
+
|
34
|
+
# Deploy with Capistrano
|
35
|
+
# gem 'capistrano'
|
36
|
+
|
37
|
+
# To use debugger
|
38
|
+
# gem 'ruby-debug19', :require => 'ruby-debug'
|