mc-settings 0.1.2 → 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
@@ -20,8 +20,13 @@ def stub_setting_files
20
20
  default: 7
21
21
  flag_false:
22
22
  default: false
23
- CONTENT
24
- test = <<-CONTENT
23
+ nested_array:
24
+ - first
25
+ - second
26
+ - third
27
+ YAML
28
+
29
+ test = <<~YAML
25
30
  one: test
26
31
  two:
27
32
  three: 5
@@ -30,22 +35,35 @@ CONTENT
30
35
  six:
31
36
  extra: "recursively overriden"
32
37
  test_specific: "exist"
33
- CONTENT
38
+ nested_array:
39
+ - first
40
+ - four
41
+ - five
42
+ YAML
34
43
 
35
- empty = <<-CONTENT
36
- CONTENT
44
+ empty = <<~YAML
45
+ YAML
37
46
 
38
- custom = <<-CONTENT
47
+ custom = <<~YAML
39
48
  seven:
40
49
  default: "seven from custom"
41
- 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)
42
62
 
43
- File.stub!(:exists?).and_return(true)
44
- File.stub!(:exists?).with("config/settings/environments/development.yml").and_return(false)
45
- File.stub!(:open).with("config/settings/default.yml").and_return(defaults)
46
- File.stub!(:open).with("config/settings/environments/test.yml").and_return(test)
47
- File.stub!(:open).with("config/settings/local/custom.yml").and_return(custom)
48
- File.stub!(:open).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)
49
67
 
50
- Dir.stub!(:glob).and_return(["config/settings/local/empty.yml", "config/settings/local/custom.yml"])
51
- 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,158 +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: 31
5
- prerelease: false
6
- segments:
7
- - 0
8
- - 1
9
- - 2
10
- version: 0.1.2
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-01-18 00:00:00 -08:00
20
- default_executable:
21
- dependencies:
22
- - !ruby/object:Gem::Dependency
23
- prerelease: false
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:
19
+ - - ">="
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
24
22
  type: :development
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
25
30
  name: rspec
26
- version_requirements: &id001 !ruby/object:Gem::Requirement
27
- none: false
28
- requirements:
31
+ requirement: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - "~>"
34
+ - !ruby/object:Gem::Version
35
+ version: '3.0'
36
+ type: :development
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:
29
47
  - - ">="
30
- - !ruby/object:Gem::Version
31
- hash: 3
32
- segments:
33
- - 0
34
- version: "0"
35
- requirement: *id001
36
- - !ruby/object:Gem::Dependency
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ type: :development
37
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'
38
64
  type: :development
39
- name: bundler
40
- version_requirements: &id002 !ruby/object:Gem::Requirement
41
- none: false
42
- requirements:
43
- - - ~>
44
- - !ruby/object:Gem::Version
45
- hash: 23
46
- segments:
47
- - 1
48
- - 0
49
- - 0
50
- version: 1.0.0
51
- requirement: *id002
52
- - !ruby/object:Gem::Dependency
53
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:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
54
78
  type: :development
55
- name: jeweler
56
- version_requirements: &id003 !ruby/object:Gem::Requirement
57
- none: false
58
- requirements:
59
- - - ~>
60
- - !ruby/object:Gem::Version
61
- hash: 1
62
- segments:
63
- - 1
64
- - 5
65
- - 1
66
- version: 1.5.1
67
- requirement: *id003
68
- - !ruby/object:Gem::Dependency
69
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'
70
92
  type: :development
71
- name: rcov
72
- version_requirements: &id004 !ruby/object:Gem::Requirement
73
- none: false
74
- requirements:
93
+ prerelease: false
94
+ version_requirements: !ruby/object:Gem::Requirement
95
+ requirements:
75
96
  - - ">="
76
- - !ruby/object:Gem::Version
77
- hash: 3
78
- segments:
79
- - 0
80
- version: "0"
81
- requirement: *id004
82
- - !ruby/object:Gem::Dependency
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ - !ruby/object:Gem::Dependency
100
+ name: asciidoctor
101
+ requirement: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ type: :development
83
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'
84
120
  type: :development
85
- name: ruby-debug
86
- version_requirements: &id005 !ruby/object:Gem::Requirement
87
- none: false
88
- requirements:
121
+ prerelease: false
122
+ version_requirements: !ruby/object:Gem::Requirement
123
+ requirements:
89
124
  - - ">="
90
- - !ruby/object:Gem::Version
91
- hash: 3
92
- segments:
93
- - 0
94
- version: "0"
95
- requirement: *id005
96
- description: implement custom keys indenendently of environment
97
- email: rubydev@modcloth.com
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
149
  - spec/mc_settings_spec.rb
119
150
  - spec/spec_helper.rb
120
151
  - spec/support/settings_helper.rb
121
- has_rdoc: true
122
- homepage: http://github.com/modcloth/mc-settings
123
- licenses:
152
+ homepage: https://github.com/kigster/mc-settings
153
+ licenses:
124
154
  - MIT
125
- post_install_message:
155
+ metadata: {}
156
+ post_install_message:
126
157
  rdoc_options: []
127
-
128
- require_paths:
158
+ require_paths:
129
159
  - lib
130
- required_ruby_version: !ruby/object:Gem::Requirement
131
- none: false
132
- requirements:
160
+ required_ruby_version: !ruby/object:Gem::Requirement
161
+ requirements:
133
162
  - - ">="
134
- - !ruby/object:Gem::Version
135
- hash: 3
136
- segments:
137
- - 0
138
- version: "0"
139
- required_rubygems_version: !ruby/object:Gem::Requirement
140
- none: false
141
- requirements:
163
+ - !ruby/object:Gem::Version
164
+ version: '0'
165
+ required_rubygems_version: !ruby/object:Gem::Requirement
166
+ requirements:
142
167
  - - ">="
143
- - !ruby/object:Gem::Version
144
- hash: 3
145
- segments:
146
- - 0
147
- version: "0"
168
+ - !ruby/object:Gem::Version
169
+ version: '0'
148
170
  requirements: []
149
-
150
- rubyforge_project:
151
- rubygems_version: 1.3.7
152
- signing_key:
153
- specification_version: 3
154
- summary: Manage settings per environment
155
- 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:
156
176
  - spec/mc_settings_spec.rb
157
177
  - spec/spec_helper.rb
158
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,154 +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, etc.. -level hashes is one of the advantages of using this gem.
34
-
35
- By loading configuration from files, Setting 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 acessing single values. However, square bracket notation
53
- may be useful when you want to fetch the entire 2nd level hash that includes the default value, instead of the
54
- 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 for nested hashes. It also supports default values
66
- if provided.
67
-
68
- Setting.tax => 0.0
69
-
70
- Square bracket syntax returns the actual 2nd-level hash, without any regard for a 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 a parameter hash that configures which YML files to load, and 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 YML files loaded in order specified in the above example, assuming that "development" is
94
- the Rails environment, and "local" folder exists with 3 additional YML 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, so that values loaded in early files may
103
- be overwritten by values in subsequent files. This is deliberate and by design: it allows you to create
104
- small "override" files for each environment, or even each machine you want to deploy to. Exactly how you split your
105
- application settings in files is up to you.
106
-
107
- == Nested Hashes and Default Values
108
-
109
- MC Setting gem provides a convenient way to access nested values, including full support for the default values within
110
- nested hashes (as of 0.1.1).
111
-
112
- Consider the following nested hash example:
113
-
114
- default.yml:
115
-
116
- services:
117
- inventory:
118
- url: http://ims.mycompany.com:3443/inventory_manager
119
- name: Inventory Management
120
- shipping:
121
- url: http://ship.mycompany.com:3443/shipper
122
- name: Shipping
123
-
124
- Setting.load(:files => ['default.yml'], :path => ...)
125
-
126
- Setting.tax(:inventory) => { :url => "http://localhost:3443/inventory_manager" :name => "Inventory Management"}
127
- Setting.tax(:inventory, :url) => "http://localhost:3443/inventory_manager"
128
-
129
- staging.yml is changing URLs for services so they work in the staging environment. Service URLs have been changed for
130
- staging only:
131
-
132
- services:
133
- inventory:
134
- url: http://localhost:8009/inventory_manager
135
- shipping:
136
- url: http://localhost:8008/shipper
137
-
138
- Setting.load(:files => ['default.yml', 'staging.yml'], :path => ...)
139
-
140
- Setting.tax(:inventory) => { :url => "http://localhost:8009/inventory_manager" :name => "Inventory Management"}
141
- Setting.tax(:inventory, :url) => "http://localhost:8008/inventory_manager"
142
-
143
- == Capistrano Recommendations
144
-
145
- TBD.
146
-
147
- == Copyright
148
-
149
- Copyright 2010 (c) ModCloth Inc.
150
-
151
- Authors: 2010 Edwin Cruz & Konstantin Gredeskoul
152
-
153
- See LICENSE.txt for further details.
154
-