anyway_config 1.3.0 → 1.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cdd74aa415435157e394ef1433722c7a579ff015e72923b095f9f7b25d02990e
4
- data.tar.gz: d10f5c7bfc2a8f7908ae1b9a43efcc16da7682974aef1519772af482d75c6cd8
3
+ metadata.gz: b5deaa09c29ffb32bb0b6454e3c6efc5a3870b01caf4f7794034e7d329d65c43
4
+ data.tar.gz: 86b948b10fbfac5a56e2cd980a00144f9b6e538dab109923277c00f4466e1220
5
5
  SHA512:
6
- metadata.gz: a6ac9bd78a2dbd84ae21124a3ad21556204fd6ebfe05dbb55276ac8ef8a94f5ae09ad070e51cf8e97fc3aca8e8f8126171b53e58ff4c81b012abdbbcc28a2779
7
- data.tar.gz: 7da007e994e49579dba02fedf82814367c469be4872bba8aafec1b19f57eb3bd6b46bee03e5e98e60e14bbb28e26b3ba76bf16aa40006ae36438ed0dcae409eb
6
+ metadata.gz: 7bd2c01d521402aa0e1dc6ffae192c5a969383e8e7420a24d39af01b5af3d8e7cd62e084c52e093e8496a67b2007358bce586c0d2501745f1092b2fd7ef82903
7
+ data.tar.gz: 2a3e279019bca94cba9ec99084e4991ead85e36df3b9e7b9436774b04b520f0c3e4c2a33711a9d23cc2d2db404a534ca87e59f7e81182e540cc8502bc68b3d91
@@ -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.57.2"
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?('_') && @env_prefix.nil?
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
@@ -5,6 +5,7 @@ module Anyway
5
5
  class << self
6
6
  def defaults
7
7
  return unless @defaults
8
+
8
9
  @defaults_wia ||= @defaults.with_indifferent_access
9
10
  end
10
11
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Anyway # :nodoc:
4
- VERSION = "1.3.0"
4
+ VERSION = "1.3.1"
5
5
  end
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.0
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-06-15 00:00:00.000000000 Z
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.57.2
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.57.2
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