sinatra-contrib 2.0.1 → 2.0.2

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
- SHA1:
3
- metadata.gz: 64ccf4e1e4d7f4b815eca96f762f60861be3c6b9
4
- data.tar.gz: 23254cf9a8ea40d37287c79d747f51eea7f59060
2
+ SHA256:
3
+ metadata.gz: 8c8f28c33c3ece99365dbedf54e005d0ca8c1f67fa9b185ea3e3007d02859c01
4
+ data.tar.gz: 6faec8475cd013a114fa920ce028ecd635e217da2693e4d313530c3eea2cfd93
5
5
  SHA512:
6
- metadata.gz: e81c0fa5f000e6929dc9230eeda7f5c00cf51a04b95a785defae763e9ea646d65a65a78c0a2304c7757d2f0e9cd1afea9c93378d0d2881ee1876cf72dc17c01e
7
- data.tar.gz: 01a00fbcf1e8c78e8508d46bc24aff45dbe0716ae001a88186813b11f0b3ddb25f45580f23107ca00ccf5b4ff9188f96aa7fbb05ebc73e3d4d0ad4ba161e6bc5
6
+ metadata.gz: e1200e05c63c903e39a349c1959c681304bdcd848abdbac6cd30a008e27ee4e335f5194504289dde64156bb7b572369c7b4bd9c45a4a322d1b0b48fe12ff5fdf
7
+ data.tar.gz: 229bd1e2f2f9166a914aa0936ebb2fee6ae95acdcd4fd188a1879881096e6079fd11e85f42dfe7076a3c7f80d06c18eca62208ffb208c555c095c0547dfa9364
data/README.md CHANGED
@@ -154,22 +154,22 @@ end
154
154
  For more info check the [official docs](http://www.sinatrarb.com/contrib/) and
155
155
  [api docs](http://www.rubydoc.info/gems/sinatra-contrib).
156
156
 
157
- [sinatra-reloader]: /contrib/reloader
158
- [sinatra-namespace]: /contrib/namespace
159
- [sinatra-content-for]: /contrib/content_for
160
- [sinatra-cookies]: /contrib/cookies
161
- [sinatra-streaming]: /contrib/streaming
162
- [sinatra-webdav]: /contrib/webdav
163
- [sinatra-runner]: /contrib/runner
164
- [sinatra-extension]: /contrib/extension
165
- [sinatra-test-helpers]: /contrib/test_helpers
166
- [sinatra-required-params]: /contrib/required_params
167
- [sinatra-custom-logger]: /contrib/custom_logger
168
- [sinatra-multi-route]: /contrib/multi_route
169
- [sinatra-json]: /contrib/json
170
- [sinatra-respond-with]: /contrib/respond_with
171
- [sinatra-config-file]: /contrib/config_file
172
- [sinatra-link-header]: /contrib/link_header
173
- [sinatra-capture]: /contrib/capture
174
- [sinatra-engine-tracking]: /contrib/engine_tracking
157
+ [sinatra-reloader]: http://www.sinatrarb.com/contrib/reloader
158
+ [sinatra-namespace]: http://www.sinatrarb.com/contrib/namespace
159
+ [sinatra-content-for]: http://www.sinatrarb.com/contrib/content_for
160
+ [sinatra-cookies]: http://www.sinatrarb.com/contrib/cookies
161
+ [sinatra-streaming]: http://www.sinatrarb.com/contrib/streaming
162
+ [sinatra-webdav]: http://www.sinatrarb.com/contrib/webdav
163
+ [sinatra-runner]: http://www.sinatrarb.com/contrib/runner
164
+ [sinatra-extension]: http://www.sinatrarb.com/contrib/extension
165
+ [sinatra-test-helpers]: https://github.com/sinatra/sinatra/blob/master/sinatra-contrib/lib/sinatra/test_helpers.rb
166
+ [sinatra-required-params]: http://www.sinatrarb.com/contrib/required_params
167
+ [sinatra-custom-logger]: http://www.sinatrarb.com/contrib/custom_logger
168
+ [sinatra-multi-route]: http://www.sinatrarb.com/contrib/multi_route
169
+ [sinatra-json]: http://www.sinatrarb.com/contrib/json
170
+ [sinatra-respond-with]: http://www.sinatrarb.com/contrib/respond_with
171
+ [sinatra-config-file]: http://www.sinatrarb.com/contrib/config_file
172
+ [sinatra-link-header]: http://www.sinatrarb.com/contrib/link_header
173
+ [sinatra-capture]: http://www.sinatrarb.com/contrib/capture
174
+ [sinatra-engine-tracking]: https://github.com/sinatra/sinatra/blob/master/sinatra-contrib/lib/sinatra/engine_tracking.rb
175
175
 
@@ -8,7 +8,7 @@ module Sinatra
8
8
  #
9
9
  # <tt>Sinatra::ConfigFile</tt> is an extension that allows you to load the
10
10
  # application's configuration from YAML files. It automatically detects if
11
- # the files contains specific environment settings and it will use the
11
+ # the files contain specific environment settings and it will use those
12
12
  # corresponding to the current one.
13
13
  #
14
14
  # You can access those options through +settings+ within the application. If
@@ -94,18 +94,11 @@ module Sinatra
94
94
  # In either case, <tt>settings.foo</tt> will return the environment name, and
95
95
  # <tt>settings.bar</tt> will return <tt>"bar"</tt>.
96
96
  #
97
- # Be aware that if you have a different environment, besides development,
98
- # test and production, you will also need to adjust the +environments+
99
- # setting, otherwise the settings will not load. For instance, when
100
- # you also have a staging environment:
97
+ # If you wish to provide defaults that may be shared among all the
98
+ # environments, this can be done by using a YAML alias, and then overwriting
99
+ # values in environments where appropriate:
101
100
  #
102
- # set :environments, %w{development test production staging}
103
- #
104
- # If you wish to provide defaults that may be shared among all the environments,
105
- # this can be done by using one of the existing environments as the default using
106
- # the YAML alias, and then overwriting values in the other environments:
107
- #
108
- # development: &common_settings
101
+ # default: &common_settings
109
102
  # foo: 'foo'
110
103
  # bar: 'bar'
111
104
  #
@@ -131,11 +124,9 @@ module Sinatra
131
124
  raise UnsupportedConfigType unless ['.yml', '.erb'].include?(File.extname(file))
132
125
  logger.info "loading config file '#{file}'" if logging? && respond_to?(:logger)
133
126
  document = ERB.new(IO.read(file)).result
134
- yaml = config_for_env(YAML.load(document)) || {}
135
- yaml.each_pair do |key, value|
136
- for_env = config_for_env(value)
137
- set key, for_env unless value and for_env.nil? and respond_to? key
138
- end
127
+ yaml = YAML.load(document)
128
+ config = config_for_env(yaml)
129
+ config.each_pair { |key, value| set(key, value) }
139
130
  end
140
131
  end
141
132
  end
@@ -149,23 +140,32 @@ module Sinatra
149
140
 
150
141
  private
151
142
 
152
- # Given a +hash+ with some application configuration it returns the
153
- # settings applicable to the current environment. Note that this can only
154
- # be done when all the keys of +hash+ are environment names included in the
155
- # +environments+ setting (which is an Array of Strings). Also, the
156
- # returned config is a indifferently accessible Hash, which means that you
157
- # can get its values using Strings or Symbols as keys.
143
+ # Given a +hash+ containing application configuration it returns
144
+ # settings applicable to the current environment. Note: It gives
145
+ # precedence to environment settings defined at the root-level.
158
146
  def config_for_env(hash)
159
- if hash.respond_to?(:keys) && hash.keys.all? { |k| environments.include?(k.to_s) }
160
- hash = hash[environment.to_s] || hash[environment.to_sym]
161
- end
147
+ return from_environment_key(hash) if environment_keys?(hash)
162
148
 
163
- if hash.respond_to?(:to_hash)
164
- IndifferentHash[hash.to_hash]
165
- else
166
- hash
149
+ hash.each_with_object(IndifferentHash[]) do |(k, v), acc|
150
+ if environment_keys?(v)
151
+ acc.merge!(k => v[environment.to_s]) if v.key?(environment.to_s)
152
+ else
153
+ acc.merge!(k => v)
154
+ end
167
155
  end
168
156
  end
157
+
158
+ # Given a +hash+ returns the settings corresponding to the current
159
+ # environment.
160
+ def from_environment_key(hash)
161
+ hash[environment.to_s] || hash[environment.to_sym] || {}
162
+ end
163
+
164
+ # Returns true if supplied with a hash that has any recognized
165
+ # +environments+ in its root keys.
166
+ def environment_keys?(hash)
167
+ hash.is_a?(Hash) && hash.any? { |k, _| environments.include?(k.to_s) }
168
+ end
169
169
  end
170
170
 
171
171
  register ConfigFile
@@ -1,6 +1,6 @@
1
1
  module Sinatra
2
2
  module Contrib
3
- VERSION = '2.0.1'
3
+ VERSION = '2.0.2'
4
4
  end
5
5
  end
6
6
 
File without changes
@@ -8,7 +8,7 @@ module Sinatra
8
8
  # == Usage
9
9
  #
10
10
  # Set required query parameter keys in the argument.
11
- # It'll halt with 400 if requried keys don't exist.
11
+ # It'll halt with 400 if required keys don't exist.
12
12
  #
13
13
  # get '/simple_keys' do
14
14
  # required_params :p1, :p2
@@ -60,7 +60,7 @@ module Sinatra
60
60
  elsif key.is_a?(Array)
61
61
  _required_params(p, *key)
62
62
  else
63
- halt 400 unless p.has_key?(key.to_s)
63
+ halt 400 unless p && p.respond_to?(:has_key?) && p.has_key?(key.to_s)
64
64
  end
65
65
  end
66
66
  true
@@ -23,7 +23,7 @@ Gem::Specification.new do |s|
23
23
 
24
24
  s.add_dependency "sinatra", version
25
25
  s.add_dependency "mustermann", "~> 1.0"
26
- s.add_dependency "backports", ">= 2.0"
26
+ s.add_dependency "backports", "~> 2.8.2"
27
27
  s.add_dependency "tilt", ">= 1.3", "< 3"
28
28
  s.add_dependency "rack-protection", version
29
29
  s.add_dependency "multi_json"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sinatra-contrib
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - https://github.com/sinatra/sinatra/graphs/contributors
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-02-16 00:00:00.000000000 Z
11
+ date: 2018-06-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sinatra
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 2.0.1
19
+ version: 2.0.2
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 2.0.1
26
+ version: 2.0.2
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: mustermann
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -42,16 +42,16 @@ dependencies:
42
42
  name: backports
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '2.0'
47
+ version: 2.8.2
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ">="
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '2.0'
54
+ version: 2.8.2
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: tilt
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -78,14 +78,14 @@ dependencies:
78
78
  requirements:
79
79
  - - '='
80
80
  - !ruby/object:Gem::Version
81
- version: 2.0.1
81
+ version: 2.0.2
82
82
  type: :runtime
83
83
  prerelease: false
84
84
  version_requirements: !ruby/object:Gem::Requirement
85
85
  requirements:
86
86
  - - '='
87
87
  - !ruby/object:Gem::Version
88
- version: 2.0.1
88
+ version: 2.0.2
89
89
  - !ruby/object:Gem::Dependency
90
90
  name: multi_json
91
91
  requirement: !ruby/object:Gem::Requirement
@@ -420,7 +420,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
420
420
  version: '0'
421
421
  requirements: []
422
422
  rubyforge_project:
423
- rubygems_version: 2.6.8
423
+ rubygems_version: 2.7.6
424
424
  signing_key:
425
425
  specification_version: 4
426
426
  summary: Collection of useful Sinatra extensions