rails_config 0.5.0.beta1 → 0.99.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e61cf6197d3a2803156500248660b7e93fb724ff
4
- data.tar.gz: d6163325528368ca7ea2f31c7a5f1e4609faa2c5
3
+ metadata.gz: 50dc431bc17d3f3444dd0eb593864289d2999da1
4
+ data.tar.gz: 6257637dc3173d7a9459460063249353edae7eb0
5
5
  SHA512:
6
- metadata.gz: 39685ffecfdd708a5aa825a1a1ea323eeee36610b37bc95c471bc9033f722038d45039313003b77ec2934e941ba95e431d71dc9b2f9e62520eca5e2158bf5020
7
- data.tar.gz: 539b6ef9a90acacba394d3c6d8fd6e3c62f7b330cdc2b52af5eb995597b9eeb37928b65344d3826eb3c3cf0e6f22390adb5d395bfa2ab6f6ed8e18d99362866d
6
+ metadata.gz: 00cf5d46576299d40497a7ee1e8c9d1fe3e3a4b993e6f007529d4601195f4129d4f0eecd6289585320453cc2f896630d811814f01b6451b91c005e6ef2ab1c4f
7
+ data.tar.gz: 38e322f4680d0601acb3001db02d12cb14cf66fb28880ae8023cfcfe8fcab803d312696464b6025a5f086c05010e767f9e70dc707a522275e3a65561199ef4d5
@@ -0,0 +1,14 @@
1
+ .DS_Store
2
+ .rvmrc
3
+ .idea
4
+ .bundle
5
+ gemfiles/*.lock
6
+ log
7
+ pkg
8
+ spec/app/**/db/*.sqlite*
9
+ spec/app/**/log/
10
+ spec/app/**/tmp/
11
+ spec/app/**/.sass-cache
12
+ tmp
13
+ Gemfile.lock
14
+ *.gem
@@ -0,0 +1 @@
1
+ 2.1.6
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Declare your gem's dependencies in rails_config.gemspec.
4
+ # Bundler will treat runtime dependencies like base dependencies, and
5
+ # development dependencies will be added by default to the :development group.
6
+ gemspec
data/README.md CHANGED
@@ -1,6 +1,8 @@
1
- [![Build Status](https://api.travis-ci.org/railsconfig/rails_config.png?branch=master)](http://travis-ci.org/railsconfig/rails_config)
1
+ [![Build Status](https://api.travis-ci.org/railsconfig/rails_config.svg?branch=master)](http://travis-ci.org/railsconfig/rails_config)
2
2
  [![Gem Version](https://badge.fury.io/rb/rails_config.svg)](http://badge.fury.io/rb/rails_config)
3
- [![Dependency Status](https://gemnasium.com/railsjedi/rails_config.svg)](https://gemnasium.com/railsjedi/rails_config)
3
+ [![Dependency Status](https://gemnasium.com/railsconfig/rails_config.svg)](https://gemnasium.com/railsconfig/rails_config)
4
+ [![Code Climate](https://codeclimate.com/github/railsconfig/rails_config/badges/gpa.svg)](https://codeclimate.com/github/railsconfig/rails_config)
5
+ [![Test Coverage](https://codeclimate.com/github/railsconfig/rails_config/badges/coverage.svg)](https://codeclimate.com/github/railsconfig/rails_config/coverage)
4
6
 
5
7
  # RailsConfig
6
8
 
@@ -17,6 +19,7 @@ RailsConfig helps you easily manage environment specific Rails settings in an ea
17
19
 
18
20
  ## Compatibility
19
21
 
22
+ * Ruby 2.x
20
23
  * Rails 3.x and 4.x
21
24
  * Padrino
22
25
  * Sinatra
@@ -31,6 +34,25 @@ Add this to your `Gemfile`:
31
34
  gem "rails_config"
32
35
  ```
33
36
 
37
+ If you want to use Settings before rails application initialization process you can load RailsConfig railtie manually:
38
+
39
+ ```ruby
40
+ module Appname
41
+ class Application < Rails::Application
42
+
43
+ Bundler.require(*Rails.groups)
44
+ RailsConfig::Integration::Rails::Railtie.preload
45
+
46
+ ...
47
+
48
+ config.time_zone = Settings.time_zone
49
+
50
+ ...
51
+
52
+ end
53
+ end
54
+ ```
55
+
34
56
  ## Installing on Padrino
35
57
 
36
58
  Add this to your `Gemfile`:
@@ -174,6 +196,16 @@ Settings.reload!
174
196
 
175
197
  This will use the given source.yml file and use its settings to overwrite any previous ones.
176
198
 
199
+ On the other hand, you can prepend a YML file to the list of configuration files:
200
+
201
+ ```ruby
202
+ Settings.prepend_source!("/path/to/source.yml")
203
+ Settings.reload!
204
+ ```
205
+
206
+ This will do the same as `add_source`, but the given YML file will be loaded first (instead of last) and its settings will be overwritten by any other configuration file.
207
+ This is especially useful if you want to define defaults.
208
+
177
209
  One thing I like to do for my Rails projects is provide a local.yml config file that is .gitignored (so its independent per developer). Then I create a new initializer in `config/initializers/add_local_config.rb` with the contents
178
210
 
179
211
  ```ruby
@@ -192,15 +224,13 @@ Embedded Ruby is allowed in the configuration files. See examples below.
192
224
 
193
225
  Consider the two following config files.
194
226
 
195
- #{Rails.root}/config/settings.yml:
196
-
227
+ * ```#{Rails.root}/config/settings.yml```
197
228
  ```yaml
198
229
  size: 1
199
230
  server: google.com
200
231
  ```
201
232
 
202
- #{Rails.root}/config/environments/development.yml:
203
-
233
+ * ```#{Rails.root}/config/environments/development.yml```
204
234
  ```yaml
205
235
  size: 2
206
236
  computed: <%= 1 + 2 + 3 %>
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env rake
2
+
3
+ begin
4
+ require 'bundler/setup'
5
+
6
+ Bundler::GemHelper.install_tasks
7
+
8
+ rescue LoadError
9
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
10
+ end
11
+
12
+ task :default do
13
+ system "rake -T"
14
+ end
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", "3.2.22"
6
+
7
+ gemspec :path => "../"
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", "4.1.12"
6
+
7
+ gemspec :path => "../"
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", "4.2.3"
6
+
7
+ gemspec :path => "../"
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", "4.0.13"
6
+
7
+ gemspec :path => "../"
@@ -1,64 +1,2 @@
1
- require 'active_support/core_ext/module/attribute_accessors'
2
-
3
- require 'rails_config/options'
4
- require 'rails_config/version'
5
- require 'rails_config/engine' if defined?(::Rails)
6
- require 'rails_config/sources/yaml_source'
7
- require 'rails_config/vendor/deep_merge' unless defined?(DeepMerge)
8
-
9
1
  module RailsConfig
10
- # ensures the setup only gets run once
11
- @@_ran_once = false
12
-
13
- mattr_accessor :const_name, :use_env
14
- @@const_name = "Settings"
15
- @@use_env = false
16
-
17
- def self.setup
18
- yield self if @@_ran_once == false
19
- @@_ran_once = true
20
- end
21
-
22
- # Create a populated Options instance from a yaml file. If a second yaml file is given, then the sections of that file will overwrite the sections
23
- # if the first file if they exist in the first file.
24
- def self.load_files(*files)
25
- config = Options.new
26
-
27
- # add yaml sources
28
- [files].flatten.compact.uniq.each do |file|
29
- config.add_source!(file.to_s)
30
- end
31
-
32
- config.load!
33
- config.load_env! if @@use_env
34
- config
35
- end
36
-
37
- # Loads and sets the settings constant!
38
- def self.load_and_set_settings(*files)
39
- Kernel.send(:remove_const, RailsConfig.const_name) if Kernel.const_defined?(RailsConfig.const_name)
40
- Kernel.const_set(RailsConfig.const_name, RailsConfig.load_files(files))
41
- end
42
-
43
- def self.setting_files(config_root, env)
44
- [
45
- File.join(config_root, "settings.yml").to_s,
46
- File.join(config_root, "settings", "#{env}.yml").to_s,
47
- File.join(config_root, "environments", "#{env}.yml").to_s,
48
-
49
- File.join(config_root, "settings.local.yml").to_s,
50
- File.join(config_root, "settings", "#{env}.local.yml").to_s,
51
- File.join(config_root, "environments", "#{env}.local.yml").to_s
52
- ].freeze
53
- end
54
-
55
- def self.reload!
56
- Kernel.const_get(RailsConfig.const_name).reload!
57
- end
58
2
  end
59
-
60
- # add rails integration
61
- require('rails_config/integration/rails') if defined?(::Rails)
62
-
63
- # add sinatra integration
64
- require('rails_config/integration/sinatra') if defined?(::Sinatra)
@@ -1,3 +1,3 @@
1
1
  module RailsConfig
2
- VERSION = '0.5.0.beta1'
2
+ VERSION = '0.99.0'
3
3
  end
@@ -0,0 +1,27 @@
1
+ $:.push File.expand_path("../lib", __FILE__)
2
+
3
+ # Maintain your gem's version:
4
+ require 'rails_config/version'
5
+
6
+ # Describe your gem and declare its dependencies:
7
+ Gem::Specification.new do |s|
8
+ s.name = "rails_config"
9
+ s.version = RailsConfig::VERSION
10
+ s.date = Time.now.strftime '%F'
11
+ s.authors = ["Jacques Crocker", "Fred Wu", "Piotr Kuczynski"]
12
+ s.email = ["railsjedi@gmail.com", "ifredwu@gmail.com", "piotr.kuczynski@gmail.com"]
13
+ s.summary = "Please install the Config gem instead."
14
+ s.description = "Please install the Config gem instead."
15
+ s.homepage = "https://github.com/railsconfig/rails_config"
16
+ s.license = "MIT"
17
+ s.extra_rdoc_files = ["README.md"]
18
+ s.rdoc_options = ["--charset=UTF-8"]
19
+
20
+ s.files = `git ls-files`.split($/)
21
+
22
+ s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
23
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
24
+ s.require_paths = ["lib"]
25
+
26
+ s.add_dependency "config", ">= 1.0.0.beta1"
27
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_config
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0.beta1
4
+ version: 0.99.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jacques Crocker
@@ -10,164 +10,23 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2014-08-29 00:00:00.000000000 Z
13
+ date: 2015-08-05 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
- name: activesupport
16
+ name: config
17
17
  requirement: !ruby/object:Gem::Requirement
18
18
  requirements:
19
19
  - - ">="
20
20
  - !ruby/object:Gem::Version
21
- version: '3.0'
21
+ version: 1.0.0.beta1
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  requirements:
26
26
  - - ">="
27
27
  - !ruby/object:Gem::Version
28
- version: '3.0'
29
- - !ruby/object:Gem::Dependency
30
- name: bundler
31
- requirement: !ruby/object:Gem::Requirement
32
- requirements:
33
- - - "~>"
34
- - !ruby/object:Gem::Version
35
- version: '1.5'
36
- type: :development
37
- prerelease: false
38
- version_requirements: !ruby/object:Gem::Requirement
39
- requirements:
40
- - - "~>"
41
- - !ruby/object:Gem::Version
42
- version: '1.5'
43
- - !ruby/object:Gem::Dependency
44
- name: rake
45
- requirement: !ruby/object:Gem::Requirement
46
- requirements:
47
- - - ">="
48
- - !ruby/object:Gem::Version
49
- version: '0'
50
- type: :development
51
- prerelease: false
52
- version_requirements: !ruby/object:Gem::Requirement
53
- requirements:
54
- - - ">="
55
- - !ruby/object:Gem::Version
56
- version: '0'
57
- - !ruby/object:Gem::Dependency
58
- name: rdoc
59
- requirement: !ruby/object:Gem::Requirement
60
- requirements:
61
- - - "~>"
62
- - !ruby/object:Gem::Version
63
- version: '3.4'
64
- type: :development
65
- prerelease: false
66
- version_requirements: !ruby/object:Gem::Requirement
67
- requirements:
68
- - - "~>"
69
- - !ruby/object:Gem::Version
70
- version: '3.4'
71
- - !ruby/object:Gem::Dependency
72
- name: rails
73
- requirement: !ruby/object:Gem::Requirement
74
- requirements:
75
- - - "~>"
76
- - !ruby/object:Gem::Version
77
- version: 3.2.17
78
- type: :development
79
- prerelease: false
80
- version_requirements: !ruby/object:Gem::Requirement
81
- requirements:
82
- - - "~>"
83
- - !ruby/object:Gem::Version
84
- version: 3.2.17
85
- - !ruby/object:Gem::Dependency
86
- name: rspec
87
- requirement: !ruby/object:Gem::Requirement
88
- requirements:
89
- - - "~>"
90
- - !ruby/object:Gem::Version
91
- version: '2.14'
92
- type: :development
93
- prerelease: false
94
- version_requirements: !ruby/object:Gem::Requirement
95
- requirements:
96
- - - "~>"
97
- - !ruby/object:Gem::Version
98
- version: '2.14'
99
- - !ruby/object:Gem::Dependency
100
- name: rspec-rails
101
- requirement: !ruby/object:Gem::Requirement
102
- requirements:
103
- - - "~>"
104
- - !ruby/object:Gem::Version
105
- version: '2.14'
106
- type: :development
107
- prerelease: false
108
- version_requirements: !ruby/object:Gem::Requirement
109
- requirements:
110
- - - "~>"
111
- - !ruby/object:Gem::Version
112
- version: '2.14'
113
- - !ruby/object:Gem::Dependency
114
- name: sqlite3
115
- requirement: !ruby/object:Gem::Requirement
116
- requirements:
117
- - - ">="
118
- - !ruby/object:Gem::Version
119
- version: '0'
120
- type: :development
121
- prerelease: false
122
- version_requirements: !ruby/object:Gem::Requirement
123
- requirements:
124
- - - ">="
125
- - !ruby/object:Gem::Version
126
- version: '0'
127
- - !ruby/object:Gem::Dependency
128
- name: rubocop
129
- requirement: !ruby/object:Gem::Requirement
130
- requirements:
131
- - - ">="
132
- - !ruby/object:Gem::Version
133
- version: '0'
134
- type: :development
135
- prerelease: false
136
- version_requirements: !ruby/object:Gem::Requirement
137
- requirements:
138
- - - ">="
139
- - !ruby/object:Gem::Version
140
- version: '0'
141
- - !ruby/object:Gem::Dependency
142
- name: appraisal
143
- requirement: !ruby/object:Gem::Requirement
144
- requirements:
145
- - - ">="
146
- - !ruby/object:Gem::Version
147
- version: '0'
148
- type: :development
149
- prerelease: false
150
- version_requirements: !ruby/object:Gem::Requirement
151
- requirements:
152
- - - ">="
153
- - !ruby/object:Gem::Version
154
- version: '0'
155
- - !ruby/object:Gem::Dependency
156
- name: gem-release
157
- requirement: !ruby/object:Gem::Requirement
158
- requirements:
159
- - - ">="
160
- - !ruby/object:Gem::Version
161
- version: '0'
162
- type: :development
163
- prerelease: false
164
- version_requirements: !ruby/object:Gem::Requirement
165
- requirements:
166
- - - ">="
167
- - !ruby/object:Gem::Version
168
- version: '0'
169
- description: Easy to use Settings helper that loads its data in from config/settings.yml.
170
- Handles adding multiple sources, and easy reloading.
28
+ version: 1.0.0.beta1
29
+ description: Please install the Config gem instead.
171
30
  email:
172
31
  - railsjedi@gmail.com
173
32
  - ifredwu@gmail.com
@@ -177,29 +36,20 @@ extensions: []
177
36
  extra_rdoc_files:
178
37
  - README.md
179
38
  files:
180
- - CHANGELOG.md
39
+ - ".gitignore"
40
+ - ".ruby-version"
41
+ - Gemfile
181
42
  - LICENSE.md
182
43
  - README.md
183
- - lib/generators/rails_config/install_generator.rb
184
- - lib/generators/rails_config/templates/rails_config.rb
185
- - lib/generators/rails_config/templates/settings.local.yml
186
- - lib/generators/rails_config/templates/settings.yml
187
- - lib/generators/rails_config/templates/settings/development.yml
188
- - lib/generators/rails_config/templates/settings/production.yml
189
- - lib/generators/rails_config/templates/settings/test.yml
44
+ - Rakefile
45
+ - gemfiles/rails_3.gemfile
46
+ - gemfiles/rails_4.1.gemfile
47
+ - gemfiles/rails_4.2.gemfile
48
+ - gemfiles/rails_4.gemfile
190
49
  - lib/rails_config.rb
191
- - lib/rails_config/engine.rb
192
- - lib/rails_config/integration/rails.rb
193
- - lib/rails_config/integration/sinatra.rb
194
- - lib/rails_config/options.rb
195
- - lib/rails_config/rack/reloader.rb
196
- - lib/rails_config/railtie.rb
197
- - lib/rails_config/sources/yaml_source.rb
198
- - lib/rails_config/tasks.rb
199
- - lib/rails_config/tasks/heroku.rake
200
- - lib/rails_config/vendor/deep_merge.rb
201
50
  - lib/rails_config/version.rb
202
- homepage: http://github.com/railsjedi/rails_config
51
+ - rails_config.gemspec
52
+ homepage: https://github.com/railsconfig/rails_config
203
53
  licenses:
204
54
  - MIT
205
55
  metadata: {}
@@ -215,13 +65,13 @@ required_ruby_version: !ruby/object:Gem::Requirement
215
65
  version: '0'
216
66
  required_rubygems_version: !ruby/object:Gem::Requirement
217
67
  requirements:
218
- - - ">"
68
+ - - ">="
219
69
  - !ruby/object:Gem::Version
220
- version: 1.3.1
70
+ version: '0'
221
71
  requirements: []
222
72
  rubyforge_project:
223
- rubygems_version: 2.4.1
73
+ rubygems_version: 2.4.5
224
74
  signing_key:
225
75
  specification_version: 4
226
- summary: Provides a Settings helper for Rails that reads from config/settings.yml
76
+ summary: Please install the Config gem instead.
227
77
  test_files: []
@@ -1,16 +0,0 @@
1
- # 0.4.2
2
- * ability to specify the app name when calling the Heroku rake task ([#75](https://github.com/railsjedi/rails_config/issues/75))
3
-
4
- # 0.4.1
5
-
6
- * fixed compatibility with Rails 4.1 ([#72](https://github.com/railsjedi/rails_config/issues/72))
7
- * testing suite verifies compatibility with Rails 3.2, 4.0 and 4.1
8
-
9
- # 0.4.0
10
-
11
- * compatibility with Heroku ([#64](https://github.com/railsjedi/rails_config/issues/64))
12
-
13
- # 0.3.4
14
-
15
- * expose Settings in application.rb, so you don't have to duplicate configuration for each environment file ([#59](https://github.com/railsjedi/rails_config/issues/59))
16
- * adding support for Rails 4.1.0.rc ([#70](https://github.com/railsjedi/rails_config/issues/70))
@@ -1,32 +0,0 @@
1
- module RailsConfig
2
- module Generators
3
- class InstallGenerator < ::Rails::Generators::Base
4
- desc "Generates a custom Rails Config initializer file."
5
-
6
- def self.source_root
7
- @_rails_config_source_root ||= File.expand_path("../templates", __FILE__)
8
- end
9
-
10
- def copy_initializer
11
- template "rails_config.rb", "config/initializers/rails_config.rb"
12
- end
13
-
14
- def copy_settings
15
- template "settings.yml", "config/settings.yml"
16
- template "settings.local.yml", "config/settings.local.yml"
17
- directory "settings", "config/settings"
18
- end
19
-
20
- def modify_gitignore
21
- create_file '.gitignore' unless File.exists? '.gitignore'
22
-
23
- append_to_file '.gitignore' do
24
- "\n" +
25
- "config/settings.local.yml\n" +
26
- "config/settings/*.local.yml\n" +
27
- "config/environments/*.local.yml\n"
28
- end
29
- end
30
- end
31
- end
32
- end
@@ -1,3 +0,0 @@
1
- RailsConfig.setup do |config|
2
- config.const_name = "Settings"
3
- end
@@ -1,5 +0,0 @@
1
- module RailsConfig
2
- class Engine < ::Rails::Engine
3
- isolate_namespace RailsConfig
4
- end
5
- end
@@ -1,34 +0,0 @@
1
- module RailsConfig
2
- module Integration
3
- module Rails
4
- if defined?(::Rails::Railtie)
5
- class Railtie < ::Rails::Railtie
6
- # Load rake tasks (eg. Heroku)
7
- rake_tasks do
8
- Dir[File.join(File.dirname(__FILE__),'../tasks/*.rake')].each { |f| load f }
9
- end
10
-
11
- ActiveSupport.on_load :before_configuration, :yield => true do
12
- # Manually load the custom initializer before everything else
13
- initializer = ::Rails.root.join("config", "initializers", "rails_config.rb")
14
- require initializer if File.exist?(initializer)
15
-
16
- # Parse the settings before any of the initializers
17
- RailsConfig.load_and_set_settings(
18
- RailsConfig.setting_files(::Rails.root.join("config"), ::Rails.env)
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.reload! }
27
- end
28
- end
29
- end
30
- end
31
- end
32
- end
33
- end
34
- end
@@ -1,26 +0,0 @@
1
- require "rails_config/rack/reloader"
2
-
3
- module RailsConfig
4
- # provide helper to register within your Sinatra app
5
- #
6
- # set :root, File.dirname(__FILE__)
7
- # register RailsConfig
8
- #
9
- def self.registered(app)
10
- app.configure do |inner_app|
11
-
12
- env = inner_app.environment || ENV["RACK_ENV"]
13
- root = inner_app.root
14
-
15
- # use Padrino settings if applicable
16
- if defined?(Padrino)
17
- env = Padrino.env
18
- root = Padrino.root
19
- end
20
-
21
- RailsConfig.load_and_set_settings(RailsConfig.setting_files(File.join(root, 'config'), env))
22
-
23
- inner_app.use(::RailsConfig::Rack::Reloader) if inner_app.development?
24
- end
25
- end
26
- end
@@ -1,117 +0,0 @@
1
- require 'ostruct'
2
- module RailsConfig
3
- class Options < OpenStruct
4
- include Enumerable
5
-
6
- def keys() marshal_dump.keys; end
7
- def empty?() marshal_dump.empty?; end
8
-
9
- def add_source!(source)
10
- # handle yaml file paths
11
- source = (Sources::YAMLSource.new(source)) if source.is_a?(String)
12
-
13
- @config_sources ||= []
14
- @config_sources << source
15
- end
16
-
17
- def reload_env!
18
- return self if ENV.nil? || ENV.empty?
19
- conf = Hash.new
20
- ENV.each do |key, value|
21
- next unless key.to_s.index(RailsConfig.const_name) == 0
22
- hash = value
23
- key.to_s.split('.').reverse.each do |element|
24
- hash = {element => hash}
25
- end
26
- DeepMerge.deep_merge!(hash, conf, :preserve_unmergeables => false)
27
- end
28
-
29
- merge!(conf[RailsConfig.const_name] || {})
30
- end
31
-
32
- alias :load_env! :reload_env!
33
-
34
- # look through all our sources and rebuild the configuration
35
- def reload!
36
- conf = {}
37
- @config_sources.each do |source|
38
- source_conf = source.load
39
-
40
- if conf.empty?
41
- conf = source_conf
42
- else
43
- DeepMerge.deep_merge!(source_conf, conf, :preserve_unmergeables => false)
44
- end
45
- end
46
-
47
- # swap out the contents of the OStruct with a hash (need to recursively convert)
48
- marshal_load(__convert(conf).marshal_dump)
49
-
50
- reload_env! if RailsConfig.use_env
51
-
52
- return self
53
- end
54
-
55
- alias :load! :reload!
56
-
57
- def reload_from_files(*files)
58
- RailsConfig.load_and_set_settings(files)
59
- reload!
60
- end
61
-
62
- def to_hash
63
- result = {}
64
- marshal_dump.each do |k, v|
65
- result[k] = v.instance_of?(RailsConfig::Options) ? v.to_hash : v
66
- end
67
- result
68
- end
69
-
70
- def each(*args, &block)
71
- marshal_dump.each(*args, &block)
72
- end
73
-
74
- def to_json(*args)
75
- require "json" unless defined?(JSON)
76
- to_hash.to_json(*args)
77
- end
78
-
79
- def merge!(hash)
80
- current = to_hash
81
- DeepMerge.deep_merge!(hash.dup, current)
82
- marshal_load(__convert(current).marshal_dump)
83
- self
84
- end
85
-
86
- # An alternative mechanism for property access.
87
- # This let's you do foo['bar'] along with foo.bar.
88
- def [](param)
89
- send("#{param}")
90
- end
91
-
92
- def []=(param, value)
93
- send("#{param}=", value)
94
- end
95
-
96
- protected
97
-
98
- # Recursively converts Hashes to Options (including Hashes inside Arrays)
99
- def __convert(h) #:nodoc:
100
- s = self.class.new
101
-
102
- h.each do |k, v|
103
- k = k.to_s if !k.respond_to?(:to_sym) && k.respond_to?(:to_s)
104
- s.new_ostruct_member(k)
105
-
106
- if v.is_a?(Hash)
107
- v = v["type"] == "hash" ? v["contents"] : __convert(v)
108
- elsif v.is_a?(Array)
109
- v = v.collect { |e| e.instance_of?(Hash) ? __convert(e) : e }
110
- end
111
-
112
- s.send("#{k}=".to_sym, v)
113
- end
114
- s
115
- end
116
- end
117
- end
@@ -1,15 +0,0 @@
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
@@ -1,9 +0,0 @@
1
- require 'rails'
2
-
3
- module RailsConfig
4
- class Railtie < Rails::Railtie
5
- rake_tasks do
6
- Dir[File.join(File.dirname(__FILE__),'tasks/*.rake')].each { |f| load f }
7
- end
8
- end
9
- end
@@ -1,26 +0,0 @@
1
- require 'yaml'
2
- require 'erb'
3
-
4
- module RailsConfig
5
- module Sources
6
- class YAMLSource
7
- attr_accessor :path
8
-
9
- def initialize(path)
10
- @path = path
11
- end
12
-
13
- # returns a config hash from the YML file
14
- def load
15
- if @path and File.exist?(@path.to_s)
16
- result = YAML.load(ERB.new(IO.read(@path.to_s)).result)
17
- end
18
- result || {}
19
- rescue Psych::SyntaxError => e
20
- raise "YAML syntax error occurred while parsing #{@path}. " \
21
- "Please note that YAML must be consistently indented using spaces. Tabs are not allowed. " \
22
- "Error: #{e.message}"
23
- end
24
- end
25
- end
26
- end
@@ -1,59 +0,0 @@
1
- require "bundler"
2
-
3
- module RailsConfig
4
- module Tasks
5
- class Heroku < Struct.new(:app)
6
- def invoke
7
- puts 'Setting vars...'
8
- heroku_command = "config:set #{vars}"
9
- heroku(heroku_command)
10
- puts 'Vars set:'
11
- puts heroku_command
12
- end
13
-
14
- def vars
15
- # Load only local options to Heroku
16
- RailsConfig.load_and_set_settings(
17
- Rails.root.join("config", "settings.local.yml").to_s,
18
- Rails.root.join("config", "settings", "#{environment}.local.yml").to_s,
19
- Rails.root.join("config", "environments", "#{environment}.local.yml").to_s
20
- )
21
-
22
- out = ''
23
- dotted_hash = to_dotted_hash Kernel.const_get(RailsConfig.const_name).to_hash, {}, RailsConfig.const_name
24
- dotted_hash.each {|key, value| out += " #{key}=#{value} "}
25
- out
26
- end
27
-
28
- def environment
29
- heroku("run 'echo $RAILS_ENV'").chomp[/(\w+)\z/]
30
- end
31
-
32
- def heroku(command)
33
- with_app = app ? " --app #{app}" : ""
34
- `heroku #{command}#{with_app}`
35
- end
36
-
37
- def `(command)
38
- Bundler.with_clean_env { super }
39
- end
40
-
41
- def to_dotted_hash(source, target = {}, namespace = nil)
42
- prefix = "#{namespace}." if namespace
43
- case source
44
- when Hash
45
- source.each do |key, value|
46
- to_dotted_hash(value, target, "#{prefix}#{key}")
47
- end
48
- when Array
49
- source.each_with_index do |value, index|
50
- to_dotted_hash(value, target, "#{prefix}#{index}")
51
- end
52
- else
53
- target[namespace] = source
54
- end
55
- target
56
- end
57
- end
58
- end
59
- end
@@ -1,8 +0,0 @@
1
- # require 'rails_config'
2
- require 'rails_config/tasks'
3
-
4
- namespace 'rails_config' do
5
- task :heroku, [:app] => :environment do |_, args|
6
- RailsConfig::Tasks::Heroku.new(args[:app]).invoke
7
- end
8
- end
@@ -1,180 +0,0 @@
1
- module DeepMerge
2
- class InvalidParameter < StandardError; end
3
-
4
- DEFAULT_FIELD_KNOCKOUT_PREFIX = '--'
5
-
6
- # Deep Merge core documentation.
7
- # deep_merge! method permits merging of arbitrary child elements. The two top level
8
- # elements must be hashes. These hashes can contain unlimited (to stack limit) levels
9
- # of child elements. These child elements to not have to be of the same types.
10
- # Where child elements are of the same type, deep_merge will attempt to merge them together.
11
- # Where child elements are not of the same type, deep_merge will skip or optionally overwrite
12
- # the destination element with the contents of the source element at that level.
13
- # So if you have two hashes like this:
14
- # source = {:x => [1,2,3], :y => 2}
15
- # dest = {:x => [4,5,'6'], :y => [7,8,9]}
16
- # dest.deep_merge!(source)
17
- # Results: {:x => [1,2,3,4,5,'6'], :y => 2}
18
- # By default, "deep_merge!" will overwrite any unmergeables and merge everything else.
19
- # To avoid this, use "deep_merge" (no bang/exclamation mark)
20
- #
21
- # Options:
22
- # Options are specified in the last parameter passed, which should be in hash format:
23
- # hash.deep_merge!({:x => [1,2]}, {:knockout_prefix => '--'})
24
- # :preserve_unmergeables DEFAULT: false
25
- # Set to true to skip any unmergeable elements from source
26
- # :knockout_prefix DEFAULT: nil
27
- # Set to string value to signify prefix which deletes elements from existing element
28
- # :sort_merged_arrays DEFAULT: false
29
- # Set to true to sort all arrays that are merged together
30
- # :unpack_arrays DEFAULT: nil
31
- # Set to string value to run "Array::join" then "String::split" against all arrays
32
- # :merge_debug DEFAULT: false
33
- # Set to true to get console output of merge process for debugging
34
- #
35
- # Selected Options Details:
36
- # :knockout_prefix => The purpose of this is to provide a way to remove elements
37
- # from existing Hash by specifying them in a special way in incoming hash
38
- # source = {:x => ['--1', '2']}
39
- # dest = {:x => ['1', '3']}
40
- # dest.ko_deep_merge!(source)
41
- # Results: {:x => ['2','3']}
42
- # Additionally, if the knockout_prefix is passed alone as a string, it will cause
43
- # the entire element to be removed:
44
- # source = {:x => '--'}
45
- # dest = {:x => [1,2,3]}
46
- # dest.ko_deep_merge!(source)
47
- # Results: {:x => ""}
48
- # :unpack_arrays => The purpose of this is to permit compound elements to be passed
49
- # in as strings and to be converted into discrete array elements
50
- # irsource = {:x => ['1,2,3', '4']}
51
- # dest = {:x => ['5','6','7,8']}
52
- # dest.deep_merge!(source, {:unpack_arrays => ','})
53
- # Results: {:x => ['1','2','3','4','5','6','7','8'}
54
- # Why: If receiving data from an HTML form, this makes it easy for a checkbox
55
- # to pass multiple values from within a single HTML element
56
- #
57
- # There are many tests for this library - and you can learn more about the features
58
- # and usages of deep_merge! by just browsing the test examples
59
- def DeepMerge.deep_merge!(source, dest, options = {})
60
- # turn on this line for stdout debugging text
61
- merge_debug = options[:merge_debug] || false
62
- overwrite_unmergeable = !options[:preserve_unmergeables]
63
- knockout_prefix = options[:knockout_prefix] || nil
64
- if knockout_prefix == ""; raise InvalidParameter, "knockout_prefix cannot be an empty string in deep_merge!"; end
65
- if knockout_prefix && !overwrite_unmergeable; raise InvalidParameter, "overwrite_unmergeable must be true if knockout_prefix is specified in deep_merge!"; end
66
- # if present: we will split and join arrays on this char before merging
67
- array_split_char = options[:unpack_arrays] || false
68
- # request that we sort together any arrays when they are merged
69
- sort_merged_arrays = options[:sort_merged_arrays] || false
70
- di = options[:debug_indent] || ''
71
- # do nothing if source is nil
72
- if source.nil? || (!source.is_a?(FalseClass) && source.respond_to?(:blank?) && source.blank?); return dest; end
73
- # if dest doesn't exist, then simply copy source to it
74
- if dest.nil? && overwrite_unmergeable; dest = source; return dest; end
75
-
76
- puts "#{di}Source class: #{source.class.inspect} :: Dest class: #{dest.class.inspect}" if merge_debug
77
- if source.kind_of?(Hash)
78
- puts "#{di}Hashes: #{source.inspect} :: #{dest.inspect}" if merge_debug
79
- source.each do |src_key, src_value|
80
- if dest.kind_of?(Hash)
81
- puts "#{di} looping: #{src_key.inspect} => #{src_value.inspect} :: #{dest.inspect}" if merge_debug
82
- if !dest[src_key].nil?
83
- puts "#{di} ==>merging: #{src_key.inspect} => #{src_value.inspect} :: #{dest[src_key].inspect}" if merge_debug
84
- dest[src_key] = deep_merge!(src_value, dest[src_key], options.merge(:debug_indent => di + ' '))
85
- else # dest[src_key] doesn't exist so we want to create and overwrite it (but we do this via deep_merge!)
86
- puts "#{di} ==>merging over: #{src_key.inspect} => #{src_value.inspect}" if merge_debug
87
- # note: we rescue here b/c some classes respond to "dup" but don't implement it (Numeric, TrueClass, FalseClass, NilClass among maybe others)
88
- begin
89
- src_dup = src_value.dup # we dup src_value if possible because we're going to merge into it (since dest is empty)
90
- rescue TypeError
91
- src_dup = src_value
92
- end
93
- dest[src_key] = deep_merge!(src_value, src_dup, options.merge(:debug_indent => di + ' '))
94
- end
95
- else # dest isn't a hash, so we overwrite it completely (if permitted)
96
- if overwrite_unmergeable
97
- puts "#{di} overwriting dest: #{src_key.inspect} => #{src_value.inspect} -over-> #{dest.inspect}" if merge_debug
98
- dest = overwrite_unmergeables(source, dest, options)
99
- end
100
- end
101
- end
102
- elsif source.kind_of?(Array)
103
- puts "#{di}Arrays: #{source.inspect} :: #{dest.inspect}" if merge_debug
104
- # if we are instructed, join/split any source arrays before processing
105
- if array_split_char
106
- puts "#{di} split/join on source: #{source.inspect}" if merge_debug
107
- source = source.join(array_split_char).split(array_split_char)
108
- if dest.kind_of?(Array); dest = dest.join(array_split_char).split(array_split_char); end
109
- end
110
- # if there's a naked knockout_prefix in source, that means we are to truncate dest
111
- if source.index(knockout_prefix); dest = clear_or_nil(dest); source.delete(knockout_prefix); end
112
- if dest.kind_of?(Array)
113
- if knockout_prefix
114
- print "#{di} knocking out: " if merge_debug
115
- # remove knockout prefix items from both source and dest
116
- source.delete_if do |ko_item|
117
- retval = false
118
- item = ko_item.respond_to?(:gsub) ? ko_item.gsub(%r{^#{knockout_prefix}}, "") : ko_item
119
- if item != ko_item
120
- print "#{ko_item} - " if merge_debug
121
- dest.delete(item)
122
- dest.delete(ko_item)
123
- retval = true
124
- end
125
- retval
126
- end
127
- puts if merge_debug
128
- end
129
- puts "#{di} merging arrays: #{source.inspect} :: #{dest.inspect}" if merge_debug
130
- dest = dest | source
131
- if sort_merged_arrays; dest.sort!; end
132
- elsif overwrite_unmergeable
133
- puts "#{di} overwriting dest: #{source.inspect} -over-> #{dest.inspect}" if merge_debug
134
- dest = overwrite_unmergeables(source, dest, options)
135
- end
136
- else # src_hash is not an array or hash, so we'll have to overwrite dest
137
- puts "#{di}Others: #{source.inspect} :: #{dest.inspect}" if merge_debug
138
- dest = overwrite_unmergeables(source, dest, options)
139
- end
140
- puts "#{di}Returning #{dest.inspect}" if merge_debug
141
- dest
142
- end # deep_merge!
143
-
144
- # allows deep_merge! to uniformly handle overwriting of unmergeable entities
145
- def DeepMerge::overwrite_unmergeables(source, dest, options)
146
- merge_debug = options[:merge_debug] || false
147
- overwrite_unmergeable = !options[:preserve_unmergeables]
148
- knockout_prefix = options[:knockout_prefix] || false
149
- di = options[:debug_indent] || ''
150
- if knockout_prefix && overwrite_unmergeable
151
- if source.kind_of?(String) # remove knockout string from source before overwriting dest
152
- src_tmp = source.gsub(%r{^#{knockout_prefix}},"")
153
- elsif source.kind_of?(Array) # remove all knockout elements before overwriting dest
154
- src_tmp = source.delete_if {|ko_item| ko_item.kind_of?(String) && ko_item.match(%r{^#{knockout_prefix}}) }
155
- else
156
- src_tmp = source
157
- end
158
- if src_tmp == source # if we didn't find a knockout_prefix then we just overwrite dest
159
- puts "#{di}#{src_tmp.inspect} -over-> #{dest.inspect}" if merge_debug
160
- dest = src_tmp
161
- else # if we do find a knockout_prefix, then we just delete dest
162
- puts "#{di}\"\" -over-> #{dest.inspect}" if merge_debug
163
- dest = ""
164
- end
165
- elsif overwrite_unmergeable
166
- dest = source
167
- end
168
- dest
169
- end
170
-
171
- def DeepMerge::clear_or_nil(obj)
172
- if obj.respond_to?(:clear)
173
- obj.clear
174
- else
175
- obj = nil
176
- end
177
- obj
178
- end
179
-
180
- end # module DeepMerge