mc-settings 0.1.6 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,13 +1,31 @@
1
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
- $LOAD_PATH.unshift(File.dirname(__FILE__))
1
+ ENV['RUBYOPT'] = 'W0'
2
+
3
+ lib = File.expand_path('../lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+
3
6
  require 'rspec'
4
- require 'mc-settings'
5
- require 'ruby-debug'
7
+ require 'rspec/mocks'
8
+ require 'rspec/expectations'
9
+ require 'pry-byebug'
10
+
11
+ if ARGV.empty?
12
+ require 'simplecov'
13
+
14
+ SimpleCov.start do
15
+ add_filter 'spec/'
16
+ end
17
+ end
6
18
 
7
19
  # Requires supporting files with custom matchers and macros, etc,
8
20
  # in ./support/ and its subdirectories.
9
21
  Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
10
22
 
11
- RSpec.configure do |config|
12
-
23
+ RSpec.configure do |spec|
24
+ spec.expect_with :rspec do |expectations|
25
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
26
+ end
27
+ spec.raise_errors_for_deprecations!
28
+ spec.mock_with :rspec do |mocks|
29
+ mocks.verify_partial_doubles = true
30
+ end
13
31
  end
@@ -1,5 +1,5 @@
1
1
  def stub_setting_files
2
- defaults = <<-CONTENT
2
+ defaults = <<~YAML
3
3
  one: default
4
4
  two:
5
5
  three: 3
@@ -24,8 +24,9 @@ def stub_setting_files
24
24
  - first
25
25
  - second
26
26
  - third
27
- CONTENT
28
- test = <<-CONTENT
27
+ YAML
28
+
29
+ test = <<~YAML
29
30
  one: test
30
31
  two:
31
32
  three: 5
@@ -38,22 +39,31 @@ CONTENT
38
39
  - first
39
40
  - four
40
41
  - five
41
- CONTENT
42
+ YAML
42
43
 
43
- empty = <<-CONTENT
44
- CONTENT
44
+ empty = <<~YAML
45
+ YAML
45
46
 
46
- custom = <<-CONTENT
47
+ custom = <<~YAML
47
48
  seven:
48
49
  default: "seven from custom"
49
- CONTENT
50
+ YAML
51
+
52
+ %w[
53
+ config/settings/default.yml
54
+ config/settings/environments/test.yml
55
+ config/settings/local/custom.yml
56
+ config/settings/local/empty.yml
57
+ ].each do |path|
58
+ allow(File).to receive(:exist?).with(path).and_return(true)
59
+ end
60
+
61
+ allow(File).to receive(:exist?).with("config/settings/environments/development.yml").and_return(false)
50
62
 
51
- File.stub!(:exists?).and_return(true)
52
- File.stub!(:exists?).with("config/settings/environments/development.yml").and_return(false)
53
- IO.stub!(:read).with("config/settings/default.yml").and_return(defaults)
54
- IO.stub!(:read).with("config/settings/environments/test.yml").and_return(test)
55
- IO.stub!(:read).with("config/settings/local/custom.yml").and_return(custom)
56
- IO.stub!(:read).with("config/settings/local/empty.yml").and_return(empty)
63
+ allow(IO).to receive(:read).with("config/settings/default.yml").and_return(defaults)
64
+ allow(IO).to receive(:read).with("config/settings/environments/test.yml").and_return(test)
65
+ allow(IO).to receive(:read).with("config/settings/local/custom.yml").and_return(custom)
66
+ allow(IO).to receive(:read).with("config/settings/local/empty.yml").and_return(empty)
57
67
 
58
- Dir.stub!(:glob).and_return(["config/settings/local/empty.yml", "config/settings/local/custom.yml"])
59
- end
68
+ allow(Dir).to receive(:glob).and_return(%w[config/settings/local/empty.yml config/settings/local/custom.yml])
69
+ end
metadata CHANGED
@@ -1,159 +1,178 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: mc-settings
3
- version: !ruby/object:Gem::Version
4
- hash: 23
5
- prerelease:
6
- segments:
7
- - 0
8
- - 1
9
- - 6
10
- version: 0.1.6
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
11
5
  platform: ruby
12
- authors:
6
+ authors:
13
7
  - Edwin Cruz
14
8
  - Colin Shield
15
- autorequire:
9
+ - Konstantin Gredeskoul
10
+ autorequire:
16
11
  bindir: bin
17
12
  cert_chain: []
18
-
19
- date: 2011-09-06 00:00:00 -07:00
20
- default_executable:
21
- dependencies:
22
- - !ruby/object:Gem::Dependency
23
- name: rspec
24
- version_requirements: &id001 !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
13
+ date: 2020-09-01 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: bundler
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
27
19
  - - ">="
28
- - !ruby/object:Gem::Version
29
- hash: 3
30
- segments:
31
- - 0
32
- version: "0"
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
33
23
  prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ version: '0'
29
+ - !ruby/object:Gem::Dependency
30
+ name: rspec
31
+ requirement: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - "~>"
34
+ - !ruby/object:Gem::Version
35
+ version: '3.0'
34
36
  type: :development
35
- requirement: *id001
36
- - !ruby/object:Gem::Dependency
37
- name: bundler
38
- version_requirements: &id002 !ruby/object:Gem::Requirement
39
- none: false
40
- requirements:
41
- - - ~>
42
- - !ruby/object:Gem::Version
43
- hash: 23
44
- segments:
45
- - 1
46
- - 0
47
- - 0
48
- version: 1.0.0
49
37
  prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - "~>"
41
+ - !ruby/object:Gem::Version
42
+ version: '3.0'
43
+ - !ruby/object:Gem::Dependency
44
+ name: simplecov
45
+ requirement: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
50
  type: :development
51
- requirement: *id002
52
- - !ruby/object:Gem::Dependency
53
- name: jeweler
54
- version_requirements: &id003 !ruby/object:Gem::Requirement
55
- none: false
56
- requirements:
57
- - - ~>
58
- - !ruby/object:Gem::Version
59
- hash: 1
60
- segments:
61
- - 1
62
- - 5
63
- - 1
64
- version: 1.5.1
65
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: rake
59
+ requirement: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
66
64
  type: :development
67
- requirement: *id003
68
- - !ruby/object:Gem::Dependency
69
- name: rcov
70
- version_requirements: &id004 !ruby/object:Gem::Requirement
71
- none: false
72
- requirements:
65
+ prerelease: false
66
+ version_requirements: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ - !ruby/object:Gem::Dependency
72
+ name: pry-byebug
73
+ requirement: !ruby/object:Gem::Requirement
74
+ requirements:
73
75
  - - ">="
74
- - !ruby/object:Gem::Version
75
- hash: 3
76
- segments:
77
- - 0
78
- version: "0"
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ type: :development
79
79
  prerelease: false
80
+ version_requirements: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ - !ruby/object:Gem::Dependency
86
+ name: rspec-mocks
87
+ requirement: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
80
92
  type: :development
81
- requirement: *id004
82
- - !ruby/object:Gem::Dependency
83
- name: ruby-debug
84
- version_requirements: &id005 !ruby/object:Gem::Requirement
85
- none: false
86
- requirements:
93
+ prerelease: false
94
+ version_requirements: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ - !ruby/object:Gem::Dependency
100
+ name: asciidoctor
101
+ requirement: !ruby/object:Gem::Requirement
102
+ requirements:
87
103
  - - ">="
88
- - !ruby/object:Gem::Version
89
- hash: 3
90
- segments:
91
- - 0
92
- version: "0"
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ type: :development
93
107
  prerelease: false
108
+ version_requirements: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ - !ruby/object:Gem::Dependency
114
+ name: rspec-expectations
115
+ requirement: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
94
120
  type: :development
95
- requirement: *id005
96
- description: implement custom keys indenendently of environment
97
- email: rubydev@modcloth.com
121
+ prerelease: false
122
+ version_requirements: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ description: Manage application configuration and settings per deployment environment
128
+ email:
129
+ - softr8@gmail.com
130
+ - kigster@gmail.com
98
131
  executables: []
99
-
100
132
  extensions: []
101
-
102
- extra_rdoc_files:
133
+ extra_rdoc_files:
103
134
  - LICENSE.txt
104
- - README.rdoc
105
- files:
106
- - .document
135
+ - README.adoc
136
+ files:
137
+ - ".github/workflows/ruby.yml"
138
+ - ".gitignore"
107
139
  - Gemfile
108
140
  - Gemfile.lock
109
141
  - LICENSE.txt
110
- - README.rdoc
142
+ - README.adoc
111
143
  - Rakefile
112
- - VERSION
144
+ - codecov.yml
113
145
  - lib/mc-settings.rb
146
+ - lib/mc-settings/version.rb
114
147
  - lib/setting.rb
115
148
  - mc-settings.gemspec
116
- - spec/fixtures/joes-colors.yml
117
- - spec/fixtures/sample.yml
118
- - spec/fixtures/shipping.yml
119
149
  - spec/mc_settings_spec.rb
120
150
  - spec/spec_helper.rb
121
151
  - spec/support/settings_helper.rb
122
- has_rdoc: true
123
- homepage: http://github.com/modcloth/mc-settings
124
- licenses:
152
+ homepage: https://github.com/kigster/mc-settings
153
+ licenses:
125
154
  - MIT
126
- post_install_message:
155
+ metadata: {}
156
+ post_install_message:
127
157
  rdoc_options: []
128
-
129
- require_paths:
158
+ require_paths:
130
159
  - lib
131
- required_ruby_version: !ruby/object:Gem::Requirement
132
- none: false
133
- requirements:
160
+ required_ruby_version: !ruby/object:Gem::Requirement
161
+ requirements:
134
162
  - - ">="
135
- - !ruby/object:Gem::Version
136
- hash: 3
137
- segments:
138
- - 0
139
- version: "0"
140
- required_rubygems_version: !ruby/object:Gem::Requirement
141
- none: false
142
- requirements:
163
+ - !ruby/object:Gem::Version
164
+ version: '0'
165
+ required_rubygems_version: !ruby/object:Gem::Requirement
166
+ requirements:
143
167
  - - ">="
144
- - !ruby/object:Gem::Version
145
- hash: 3
146
- segments:
147
- - 0
148
- version: "0"
168
+ - !ruby/object:Gem::Version
169
+ version: '0'
149
170
  requirements: []
150
-
151
- rubyforge_project:
152
- rubygems_version: 1.5.3
153
- signing_key:
154
- specification_version: 3
155
- summary: Manage settings per environment
156
- test_files:
171
+ rubygems_version: 3.1.4
172
+ signing_key:
173
+ specification_version: 4
174
+ summary: Manage application configuration and settings per deployment environment
175
+ test_files:
157
176
  - spec/mc_settings_spec.rb
158
177
  - spec/spec_helper.rb
159
178
  - spec/support/settings_helper.rb
data/.document DELETED
@@ -1,5 +0,0 @@
1
- lib/**/*.rb
2
- bin/*
3
- -
4
- features/**/*.feature
5
- LICENSE.txt
@@ -1,175 +0,0 @@
1
- = Application Settings Manager
2
-
3
- == Summary
4
-
5
- This gem provides an easy and Capistrano-friendly way to manage application configuration across
6
- multiple environments, such as development, QA, staging, production, etc.
7
-
8
- Applications typically rely on configuration settings, such as host names, URLs, usernames and many
9
- more. Some change between environemnts, some do not. This gem assumes that application configuration
10
- is represented by a Hash of arbitrary depth, and provides convenient and compact syntax to access the
11
- settings through a singleton instance inside Setting class.
12
-
13
- Configuration is stored in one or more YAML files with the top-level data structure being a Hash,
14
- with keys being the names of individual settings. For example, consider the following sample
15
- application configuration file:
16
-
17
- tax:
18
- default: 0.0
19
- california: 7.5
20
- states:
21
- default:
22
- - 'CA'
23
- - 'WA'
24
- - 'NY'
25
- ship_to:
26
- - 'CA'
27
- - 'NY'
28
- math_pi: 3.14159526
29
-
30
- Setting Gem provides Setting.load(..) method to load configuration from files in a way that allows
31
- some configuration files to override previously loaded values, and then offers a simple method API
32
- to access the values, for example Setting.tax(:california) or Setting.tax. Supporting default values
33
- in 2nd, 3rd, .. - level hashes is one of the advantages of using this gem.
34
-
35
- By loading configuration from YAML files, Setting gem is inherently compatible with Capistrano deployment
36
- methodology, where a certain set of files may become "activated" by simply sym-linking them into
37
- the appropriate settings folder.
38
-
39
- Note: using example above, "1st level" hash is the one with keys "tax", "states" and "math_pi".
40
- 2nd-level hash is, for example, the tax definition one, with keys "default" and "california".
41
-
42
- == Usage in Code
43
-
44
- Once configuration is initialized using Setting#load or Setting#reload methods (see below), they can be used in
45
- code in the following way:
46
-
47
- * Setting.key_name is optimized to return default value if available instead of a Hash.
48
- * Setting.key_name(:sub_key_name) returns a value from the 2nd level hash.
49
- * Setting.key_name(:sub_key_name, :sub_sub_key_name) returns value from the 3rd level hash if available. The algorithm is recursive, so only the maximum method stack depth will limit the number of nested hash values you can access this way.
50
- * Special syntax Setting[:key_name], Setting[:key_name][:sub_key_name], etc also supported. This method, however, does not support default values (see below).
51
-
52
- Method notation is recommended over square bracket notation for accessing single values. However,
53
- square bracket notation may be useful when you want to fetch the entire 2nd level hash that
54
- includes the default value, instead of the default value itself.
55
-
56
- For example, given the above YAML file, you can access the settings in your code as follows:
57
-
58
- Setting.tax => 0.0
59
- Setting.tax(:california) => 7.5
60
- Setting.math_pi => 3.14159526
61
- Setting[:math_pi] => 3.14159526
62
- Setting.states => [ 'CA', 'WA', 'NY' ]
63
- Setting.states['ship_to'] => [ 'CA', 'NY' ]
64
-
65
- Method-calling notation allows passing an array of keys to fetch a value from a nested hash.
66
- This method also supports returning a default value, stored against the "default" key.
67
-
68
- Setting.tax => 0.0
69
-
70
- Square bracket syntax returns the actual nested hash, without any regard for the default value:
71
-
72
- Setting[:tax] => { 'default' => 0.0, 'california' => 7.5 }
73
-
74
- == Loading Settings
75
-
76
- The gem should be initialized in your environment.rb (if using Rails), or in any other
77
- application initialization block. Setting.load() method is provided for loading settings, and it
78
- can be called only once in application lifecycle, or it will throw an exception. If you need to reload
79
- settings completely, you can use reload() method with similar arguments.
80
-
81
- Consider an example:
82
-
83
- Setting.load(:path => "#{Rails.root}/config/settings",
84
- :files => ["default.yml", "environments/#{Rails.env}.yml"],
85
- :local => true)
86
-
87
- The argument is an options hash that configures which YAML files to load, in what order, and from where.
88
-
89
- * path specifies the "root" folder where settings files will be loaded from
90
- * files is an array that lists file names relative to the :path. In the example above, settings folder contains subfolder "environments" where Rails-specific environment files are located (such as "development.yml", "staging.yml", "production.yml", etc)
91
- * local can be optionally specified as a true value, and if specified Setting gem will load all *.yml files that live under the :path/local folder.
92
-
93
- Below is list of YAML files loaded in order specified in the above example, assuming that "development" is
94
- the Rails environment, and "local" folder exists with 3 additional YAML files in it:
95
-
96
- config/settings/default.yml
97
- config/settings/environments/development.yml
98
- config/settings/local/authorize-net.yml
99
- config/settings/local/paypal.yml
100
- config/settings/local/other.yml
101
-
102
- Each YML file defines a ruby Hash. During file loading, the hashes are merged,
103
- so that values loaded in early files may be overwritten by values in subsequent
104
- files. This is deliberate and by design: it allows you to create small "override"
105
- files for each environment, or even each machine you want to deploy to. Exactly
106
- how you split your application settings in files is up to you.
107
-
108
- == Nested Hashes and Default Values
109
-
110
- MC Setting gem provides a convenient way to access nested values, including full
111
- support for the default values within nested hashes (as of 0.1.1).
112
-
113
- Consider the following nested hash example:
114
-
115
- default.yml:
116
-
117
- services:
118
- inventory:
119
- url: http://ims.mycompany.com:3443/inventory_manager
120
- name: Inventory Management
121
- shipping:
122
- url: http://ship.mycompany.com:3443/shipper
123
- name: Shipping
124
-
125
- Setting.load(:files => ['default.yml'], :path => ...)
126
-
127
- Setting.services(:inventory) => { :url => "http://localhost:3443/inventory_manager" :name => "Inventory Management"}
128
- Setting.services(:inventory, :url) => "http://localhost:3443/inventory_manager"
129
-
130
- staging.yml
131
-
132
- We are changing URLs for services in staging.yml, so they work in the staging environment. Service URLs have been updated
133
- to use localhost:
134
-
135
- services:
136
- inventory:
137
- url: http://localhost:8009/inventory_manager
138
- shipping:
139
- url: http://localhost:8008/shipper
140
-
141
-
142
- Setting.load(:files => ['default.yml', 'staging.yml'], :path => ...)
143
-
144
- Setting.services(:inventory) => { :url => "http://localhost:8009/inventory_manager" :name => "Inventory Management"}
145
- Setting.services(:inventory, :url) => "http://localhost:8008/inventory_manager"
146
-
147
- == Capistrano Recommendations
148
-
149
- Assume the directory structure of your Rails application is as follows:
150
-
151
- config/settings/default.yml
152
- config/settings/environments/development.yml
153
- config/settings/environments/staging.yml
154
- config/settings/environments/production.yml
155
- config/settings/local
156
- config/settings/systems/reporting.yml
157
- config/settings/systems/admin.yml
158
-
159
- Note that the "local" directory is empty, and that "systems" directory contains several YAML files that provide alternative
160
- configuration for a reporting server, and an admin server (both of which run in "production" rails environment).
161
-
162
- When deploying to the main production site, neither YAML files inside "systems" folder are activated or used.
163
-
164
- But upon deployment to the admin server, Capistrano could symlink "admin.yml" from config/settings/local folder, so the Setting gem
165
- would load these values. So for each Capistrano role, you can define which files need to be symlinked into local, thus creating
166
- a very flexible configuration scheme that's easily managed by Capistrano.
167
-
168
- == Copyright
169
-
170
- Copyright 2010 (c) ModCloth Inc.
171
-
172
- Authors: 2010 Edwin Cruz & Konstantin Gredeskoul
173
-
174
- See LICENSE.txt for further details.
175
-