Skip to content
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

Fix warnings #7

Merged
merged 5 commits into from
Nov 11, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions .rspec
@@ -0,0 +1,2 @@
--color
--warnings
2 changes: 1 addition & 1 deletion .simplecov
@@ -1,7 +1,7 @@
begin
require 'coveralls'

SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
SimpleCov.formatters = [
Coveralls::SimpleCov::Formatter,
SimpleCov::Formatter::HTMLFormatter,
]
Expand Down
2 changes: 1 addition & 1 deletion lib/figgy/configuration.rb
Expand Up @@ -128,7 +128,7 @@ def overlay_value(name)
end

def overlay_values
@overlays.map &:last
@overlays.map(&:last)
end
end
end
4 changes: 2 additions & 2 deletions lib/figgy/finder.rb
Expand Up @@ -22,7 +22,7 @@ def load(name)
raise(Figgy::FileNotFound, "Can't find config files for key: #{name.inspect}")
end

result = files.reduce(nil) do |result, file|
final_result = files.reduce(nil) do |result, file|
object = @config.handler_for(file).call(File.read(file))
if result && result.respond_to?(:merge)
deep_merge(result, object)
Expand All @@ -31,7 +31,7 @@ def load(name)
end
end

deep_freeze(to_figgy_hash(result))
deep_freeze(to_figgy_hash(final_result))
end

# @param [String] name the configuration key to search for
Expand Down
108 changes: 54 additions & 54 deletions spec/figgy_spec.rb
Expand Up @@ -49,8 +49,8 @@
write_config 'values.yml', 'foo: 1'
write_config 'values.yaml', 'foo: 2'

config = test_config do |config|
config.define_handler('yml', 'yaml') { |body| YAML.load(body) }
config = test_config do |cfg|
cfg.define_handler('yml', 'yaml') { |body| YAML.load(body) }
end
expect(config.values.foo).to eq(2)
end
Expand Down Expand Up @@ -200,9 +200,9 @@
write_config 'root1/values', 'foo: 1'
write_config 'root2/values', 'bar: 2'

config = test_config do |config|
config.root = File.join(current_dir, 'root1')
config.add_root File.join(current_dir, 'root2')
config = test_config do |cfg|
cfg.root = File.join(current_dir, 'root1')
cfg.add_root File.join(current_dir, 'root2')
end

expect(config.values.foo).to eq(1)
Expand All @@ -215,10 +215,10 @@
write_config 'root2/values', 'bar: 1'
write_config 'root2/prod/values', 'bar: 2'

config = test_config do |config|
config.root = File.join(current_dir, 'root1')
config.add_root File.join(current_dir, 'root2')
config.define_overlay :environment, 'prod'
config = test_config do |cfg|
cfg.root = File.join(current_dir, 'root1')
cfg.add_root File.join(current_dir, 'root2')
cfg.define_overlay :environment, 'prod'
end

expect(config.values.foo).to eq(2)
Expand All @@ -230,10 +230,10 @@
write_config 'root1/prod/values', 'foo: 2'
write_config 'root2/prod/values', 'foo: 3'

config = test_config do |config|
config.root = File.join(current_dir, 'root1')
config.add_root File.join(current_dir, 'root2')
config.define_overlay :environment, 'prod'
config = test_config do |cfg|
cfg.root = File.join(current_dir, 'root1')
cfg.add_root File.join(current_dir, 'root2')
cfg.define_overlay :environment, 'prod'
end

expect(config.values.foo).to eq(2)
Expand All @@ -248,16 +248,16 @@

it "interprets a nil overlay value as an indication to read from the config root" do
write_config 'values', "foo: 1"
config = test_config do |config|
config.define_overlay :default, nil
config = test_config do |cfg|
cfg.define_overlay :default, nil
end
expect(config.values).to eq({ "foo" => 1 })
end

it "allows the overlay's value to be the result of a block" do
write_config 'prod/values', "foo: 1"
config = test_config do |config|
config.define_overlay(:environment) { 'prod' }
config = test_config do |cfg|
cfg.define_overlay(:environment) { 'prod' }
end
expect(config.values).to eq({ "foo" => 1 })
end
Expand All @@ -266,9 +266,9 @@
write_config 'some_string', "foo bar baz"
write_config 'prod/some_string', "foo bar baz quux"

config = test_config do |config|
config.define_overlay :default, nil
config.define_overlay :environment, 'prod'
config = test_config do |cfg|
cfg.define_overlay :default, nil
cfg.define_overlay :environment, 'prod'
end

expect(config.some_string).to eq("foo bar baz quux")
Expand All @@ -287,9 +287,9 @@
quux: hi!
YML

config = test_config do |config|
config.define_overlay :default, 'defaults'
config.define_overlay :environment, 'prod'
config = test_config do |cfg|
cfg.define_overlay :default, 'defaults'
cfg.define_overlay :environment, 'prod'
end

expect(config.values).to eq({ "foo" => { "bar" => 1, "baz" => 3 }, "quux" => "hi!" })
Expand All @@ -298,9 +298,9 @@
it "can use both a nil overlay and an overlay with a value" do
write_config 'values', "foo: 1\nbar: 2"
write_config 'prod/values', "foo: 2"
config = test_config do |config|
config.define_overlay :default, nil
config.define_overlay :environment, 'prod'
config = test_config do |cfg|
cfg.define_overlay :default, nil
cfg.define_overlay :environment, 'prod'
end
expect(config.values).to eq({ "foo" => 2, "bar" => 2 })
end
Expand All @@ -321,10 +321,10 @@
baz: 3
YML

config = test_config do |config|
config.define_overlay :default, 'defaults'
config.define_overlay :environment, 'prod'
config.define_overlay :local, 'local'
config = test_config do |cfg|
cfg.define_overlay :default, 'defaults'
cfg.define_overlay :environment, 'prod'
cfg.define_overlay :local, 'local'
end

expect(config.values).to eq({ "foo" => 1, "bar" => 2, "baz" => 3 })
Expand All @@ -337,11 +337,11 @@
write_config 'prod/keys', "foo: 2"
write_config 'prod_US/keys', "foo: 3"

config = test_config do |config|
config.define_overlay :default, nil
config.define_overlay :environment, 'prod'
config.define_overlay :country, 'US'
config.define_combined_overlay :environment, :country
config = test_config do |cfg|
cfg.define_overlay :default, nil
cfg.define_overlay :environment, 'prod'
cfg.define_overlay :country, 'US'
cfg.define_combined_overlay :environment, :country
end

expect(config.keys).to eq({ "foo" => 3 })
Expand All @@ -351,8 +351,8 @@
context "reloading" do
it "can reload on each access when config.always_reload = true" do
write_config 'values', 'foo: 1'
config = test_config do |config|
config.always_reload = true
config = test_config do |cfg|
cfg.always_reload = true
end
expect(config.values).to eq({ "foo" => 1 })

Expand All @@ -362,8 +362,8 @@

it "does not reload when config.always_reload = false" do
write_config 'values', 'foo: 1'
config = test_config do |config|
config.always_reload = false
config = test_config do |cfg|
cfg.always_reload = false
end
expect(config.values).to eq({ "foo" => 1 })

Expand All @@ -378,10 +378,10 @@
write_config 'prod/values', 'foo: 2'
write_config 'prod/prod_only', 'bar: baz'

config = test_config do |config|
config.define_overlay :default, nil
config.define_overlay :environment, 'prod'
config.preload = true
config = test_config do |cfg|
cfg.define_overlay :default, nil
cfg.define_overlay :environment, 'prod'
cfg.preload = true
end

write_config 'prod/values', 'foo: 3'
Expand All @@ -397,10 +397,10 @@
write_config 'prod/lonely.yml', 'only: yml'
write_config 'local/json_values.json', '{ "json": true }'

config = test_config do |config|
config.define_overlay :default, nil
config.define_overlay :environment, 'prod'
config.define_overlay :local, 'local'
config = test_config do |cfg|
cfg.define_overlay :default, nil
cfg.define_overlay :environment, 'prod'
cfg.define_overlay :local, 'local'
end

finder = config.instance_variable_get(:@finder)
Expand All @@ -410,9 +410,9 @@
it "still supports reloading when preloading is enabled" do
write_config 'values', 'foo: 1'

config = test_config do |config|
config.preload = true
config.always_reload = true
config = test_config do |cfg|
cfg.preload = true
cfg.always_reload = true
end

expect(config.values['foo']).to eq(1)
Expand All @@ -430,8 +430,8 @@

it "freezes the results when config.freeze = true" do
write_config 'values', "foo: '1'"
config = test_config do |config|
config.freeze = true
config = test_config do |cfg|
cfg.freeze = true
end
expect(config.values).to be_frozen
end
Expand All @@ -446,8 +446,8 @@
- and: an inner hash
YML

config = test_config do |config|
config.freeze = true
config = test_config do |cfg|
cfg.freeze = true
end

expect { config.values.outer.array[2]['and'] = 'foo' }.to raise_error(/can't modify frozen/)
Expand Down