-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue#1243 configurations with unimplemented environments #1244
Issue#1243 configurations with unimplemented environments #1244
Conversation
9999791
to
8894a8f
Compare
if hash.respond_to? :keys and hash.keys.all? { |k| environments.include? k.to_s } | ||
hash = hash[environment.to_s] || hash[environment.to_sym] | ||
end | ||
# Given a +hash+ with some application configuration, returns the settings |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This word, +hash+
refers to the new-renamed parameter (now called config
), so the API docs generation will miss this annotation.
end | ||
end | ||
|
||
# Returns true if supplied with a hash that has any recognized | ||
# +environments+ in it's root keys. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Grammar: it's
=> its
8894a8f
to
3ba8697
Compare
Issues by @olleolleolle fixed & branch rebased. |
@zzak Is this ready for re-review? I believe so. |
|
||
# Returns a hash that can be accessed by both strings and symbols, when | ||
# supplied with a hash with string keys. | ||
def with_indifferent_access(hash) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need Yet Another Indifferent Hash implementation? Can't we use the one in core?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this PR precedes the work to build out a full IndifferentHash implementation. I can definitely look at switching to that today.
cf36257
to
d670cea
Compare
@zzak think this is ready for review. Refactored a good bit and it uses IndifferentHash from core. |
@JonMidhir Could you be using That becomes a SafeYAML.load(your_thing) and constrains to the types allowed by the schemas. (That is, white-listed according to a pre-defined list of data-types.) |
@olleolleolle I'd prefer |
OK If we use That's bound to break some existing configurations for users. ERB templates that produce Dates, for example, will be cast to Strings unpredictably or error out with I'm inclined to leave it as-is for now. What do you think @olleolleolle? |
Re: safe_load, I think it's fine to leave it. It would be a potentially big behavior change and supposing that people know the contents of the config files they are loading. |
Looks like this is due to be merged soon. Need it rebased? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the late reply. As you said, this should be rebased. And then, I pointed a problem about this change, please take a look at it?
end | ||
yaml = YAML.load(document) | ||
config = config_for_env(yaml) | ||
config.each_pair { |key, value| set(key, value) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You shouldn't remove the conditional expressions because the following unintentional behavior will happen.
# config.yml
development:
raise_errors: "foo"
require 'sinatra'
require 'sinatra/config_file'
config_file './config.yml'
get '/' do
settings.raise_errors.to_s #=> expected "false", but got "foo"
end
I think that it isn't desirable to automatically overwrite settings
defined by default by config file settings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@namusyaka Running this against both master and this branch I notice the default setting being overwritten. I don't think the original conditional defends against this behaviour. I can't actually think of a condition where the original would be met at all.
However, I can add this behaviour if you'd prefer?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, makes sense.
It seems that the sample I showed was wrong.
However, we must grasp the condition that the original conditional expression was trying to protect.
Welcome if you can look it up.
Then, if the original conditional expression is meaningful, we have to add a test on that matter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have the case where this would fail. If the value is being set to nil and it's set using this style, the conditional will be met and setting ignored:
# config.yml
raise_errors:
development:
# app.rb
settings.raise_errors #=> expected nil, got false
However in both other styles the conditional is not met, and the default value is overwritten:
# config.yml
raise_errors:
# app.rb
settings.raise_errors #=> expected nil, got nil
# config.yml
development:
raise_errors:
# app.rb
settings.raise_errors #=> expected nil, got nil
If we're changing the behaviour anyway do we really want to stop people from overriding default values using the config file? It seems reasonable that it should be possible to do so.
If not we can exclude all cases or have it function exactly as it did before.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's no problem, I think.
I've reviewed this change to a certain extent, but I judged that it is almost no problem.
Sure thing, I can see the missing conditional. I'll fix it tonight. |
d670cea
to
9426aa0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for clarification. lgtm.
Please squash commits.
end | ||
yaml = YAML.load(document) | ||
config = config_for_env(yaml) | ||
config.each_pair { |key, value| set(key, value) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's no problem, I think.
I've reviewed this change to a certain extent, but I judged that it is almost no problem.
9426aa0
to
5043030
Compare
…ironments in settings file.
5043030
to
dac5160
Compare
Done 👍 |
@JonMidhir Thank you |
## 2.0.4 / 2018-09-15 * Don't blow up when passing frozen string to `send_file` disposition [#1137](sinatra/sinatra#1137) by Andrew Selder * Fix ubygems LoadError [#1436](sinatra/sinatra#1436) by Pavel Rosick�«ò * Unescape regex captures [#1446](sinatra/sinatra#1446) by Jordan Owens * Slight performance improvements for IndifferentHash [#1427](sinatra/sinatra#1427) by Mike Pastore * Improve development support and documentation and source code by Will Yang, Jake Craige, Grey Baker and Guilherme Goettems Schneider ## 2.0.3 / 2018-06-09 * Fix the backports gem regression [#1442](sinatra/sinatra#1442) by Marc-Andr�«± Lafortune ## 2.0.2 / 2018-06-05 * Escape invalid query parameters [#1432](sinatra/sinatra#1432) by Kunpei Sakai * The patch fixes [CVE-2018-11627](https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2018-11627). * Fix undefined method error for `Sinatra::RequiredParams` with hash key [#1431](sinatra/sinatra#1431) by Arpit Chauhan * Add xml content-types to valid html_types for Rack::Protection [#1413](sinatra/sinatra#1413) by Reenan Arbitrario * Encode route parameters using :default_encoding setting [#1412](sinatra/sinatra#1412) by Brian m. Carlson * Fix unpredictable behaviour from Sinatra::ConfigFile [#1244](sinatra/sinatra#1244) by John Hope * Add Sinatra::IndifferentHash#slice [#1405](sinatra/sinatra#1405) by Shota Iguchi * Remove status code 205 from drop body response [#1398](sinatra/sinatra#1398) by Shota Iguchi * Ignore empty captures from params [#1390](sinatra/sinatra#1390) by Shota Iguchi * Improve development support and documentation and source code by Zp Yuan, Andreas Finger, Olle Jonsson, Shota Iguchi, Nikita Bulai and Joshua O'Brien
Fixes unpredictable behaviour from Sinatra::ConfigFile detailed in #1243.
Loads settings for the current environment regardless of other environments defined in the configuration file. Previously settings failed for all environments unless all in the file were implemented in the application.
Removes the restriction that settings can only be inherited from other environments, so that this is possible:
Amends source documentation to represent new behaviour.
Includes tests for the new behaviour.
Backwards compatible with existing settings implementations.