anyway_config 1.3.0 → 1.3.1
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 +4 -4
- data/anyway_config.gemspec +1 -1
- data/lib/anyway/config.rb +5 -1
- data/lib/anyway/rails/config.rb +1 -0
- data/lib/anyway/version.rb +1 -1
- data/spec/config_spec.rb +29 -0
- data/spec/support/print_warning_matcher.rb +34 -0
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b5deaa09c29ffb32bb0b6454e3c6efc5a3870b01caf4f7794034e7d329d65c43
|
4
|
+
data.tar.gz: 86b948b10fbfac5a56e2cd980a00144f9b6e538dab109923277c00f4466e1220
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7bd2c01d521402aa0e1dc6ffae192c5a969383e8e7420a24d39af01b5af3d8e7cd62e084c52e093e8496a67b2007358bce586c0d2501745f1092b2fd7ef82903
|
7
|
+
data.tar.gz: 2a3e279019bca94cba9ec99084e4991ead85e36df3b9e7b9436774b04b520f0c3e4c2a33711a9d23cc2d2db404a534ca87e59f7e81182e540cc8502bc68b3d91
|
data/anyway_config.gemspec
CHANGED
@@ -23,6 +23,6 @@ Gem::Specification.new do |s|
|
|
23
23
|
s.required_ruby_version = '>= 2.3'
|
24
24
|
|
25
25
|
s.add_development_dependency "rspec", "~> 3.5"
|
26
|
-
s.add_development_dependency "rubocop", "~> 0.
|
26
|
+
s.add_development_dependency "rubocop", "~> 0.59.0"
|
27
27
|
s.add_development_dependency "simplecov", ">= 0.3.8"
|
28
28
|
end
|
data/lib/anyway/config.rb
CHANGED
@@ -31,12 +31,14 @@ module Anyway # :nodoc:
|
|
31
31
|
|
32
32
|
def config_name(val = nil)
|
33
33
|
return (@config_name = val.to_s) unless val.nil?
|
34
|
+
|
34
35
|
@config_name = underscore_name unless defined?(@config_name)
|
35
36
|
@config_name
|
36
37
|
end
|
37
38
|
|
38
39
|
def env_prefix(val = nil)
|
39
40
|
return (@env_prefix = val.to_s) unless val.nil?
|
41
|
+
|
40
42
|
@env_prefix
|
41
43
|
end
|
42
44
|
|
@@ -54,6 +56,7 @@ module Anyway # :nodoc:
|
|
54
56
|
|
55
57
|
def underscore_name
|
56
58
|
return unless name
|
59
|
+
|
57
60
|
word = name[/^(\w+)/]
|
58
61
|
word.gsub!(/([A-Z\d]+)([A-Z][a-z])/, '\1_\2')
|
59
62
|
word.downcase!
|
@@ -75,7 +78,7 @@ module Anyway # :nodoc:
|
|
75
78
|
|
76
79
|
raise ArgumentError, "Config name is missing" unless @config_name
|
77
80
|
|
78
|
-
if @config_name.to_s.include?('_') &&
|
81
|
+
if @config_name.to_s.include?('_') && self.class.env_prefix.nil?
|
79
82
|
warn "[Deprecated] As your config_name is #{@config_name}, " \
|
80
83
|
"the prefix `#{@config_name.to_s.delete('_').upcase}` " \
|
81
84
|
"will be used to parse env variables. " \
|
@@ -115,6 +118,7 @@ module Anyway # :nodoc:
|
|
115
118
|
def load_from_sources(config = {})
|
116
119
|
# Handle anonymous configs
|
117
120
|
return config unless config_name
|
121
|
+
|
118
122
|
load_from_file(config)
|
119
123
|
load_from_env(config)
|
120
124
|
end
|
data/lib/anyway/rails/config.rb
CHANGED
data/lib/anyway/version.rb
CHANGED
data/spec/config_spec.rb
CHANGED
@@ -100,6 +100,35 @@ describe Anyway::Config do
|
|
100
100
|
end
|
101
101
|
end
|
102
102
|
|
103
|
+
context "when config_name contains underscores" do
|
104
|
+
let(:conf) do
|
105
|
+
klass = CoolConfig.dup
|
106
|
+
klass.class_eval do
|
107
|
+
config_name :cool_thing
|
108
|
+
end
|
109
|
+
klass.new
|
110
|
+
end
|
111
|
+
|
112
|
+
it "warns user about deprecated behaviour" do
|
113
|
+
expect { conf }.to print_warning
|
114
|
+
end
|
115
|
+
|
116
|
+
context "when env_name is set" do
|
117
|
+
let(:conf) do
|
118
|
+
klass = CoolConfig.dup
|
119
|
+
klass.class_eval do
|
120
|
+
config_name :cool_thing
|
121
|
+
env_prefix :cool_thing
|
122
|
+
end
|
123
|
+
klass.new
|
124
|
+
end
|
125
|
+
|
126
|
+
it "doesn't print deprecation warning" do
|
127
|
+
expect { conf }.not_to print_warning
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
103
132
|
it "handle ENV in YML thru ERB" do
|
104
133
|
ENV['ANYWAY_SECRET_PASSWORD'] = 'my_pass'
|
105
134
|
expect(conf.user[:password]).to eq 'my_pass'
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec::Matchers.define :print_warning do |message|
|
4
|
+
def supports_block_expectations?
|
5
|
+
true
|
6
|
+
end
|
7
|
+
|
8
|
+
match do |block|
|
9
|
+
stderr = fake_stderr(&block)
|
10
|
+
message ? stderr.include?(message) : !stderr.empty?
|
11
|
+
end
|
12
|
+
|
13
|
+
description do
|
14
|
+
"write #{message && "\"#{message}\"" || 'anything'} to standard error"
|
15
|
+
end
|
16
|
+
|
17
|
+
failure_message do
|
18
|
+
"expected to #{description}"
|
19
|
+
end
|
20
|
+
|
21
|
+
failure_message_when_negated do
|
22
|
+
"expected not to #{description}"
|
23
|
+
end
|
24
|
+
|
25
|
+
# Fake STDERR and return a string written to it.
|
26
|
+
def fake_stderr
|
27
|
+
original_stderr = $stderr
|
28
|
+
$stderr = StringIO.new
|
29
|
+
yield
|
30
|
+
$stderr.string
|
31
|
+
ensure
|
32
|
+
$stderr = original_stderr
|
33
|
+
end
|
34
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: anyway_config
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vladimir Dementyev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-09-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 0.
|
33
|
+
version: 0.59.0
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 0.
|
40
|
+
version: 0.59.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: simplecov
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -103,6 +103,7 @@ files:
|
|
103
103
|
- spec/spec_helper.rb
|
104
104
|
- spec/spec_norails_helper.rb
|
105
105
|
- spec/support/cool_config.rb
|
106
|
+
- spec/support/print_warning_matcher.rb
|
106
107
|
- spec/support/small_config.rb
|
107
108
|
- spec/support/test_config.rb
|
108
109
|
homepage: http://github.com/palkan/anyway_config
|