anyway_config 1.3.1 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rubocop.yml +4 -1
- data/CHANGELOG.md +26 -0
- data/README.md +45 -9
- data/anyway_config.gemspec +1 -1
- data/lib/anyway/config.rb +40 -13
- data/lib/anyway/env.rb +3 -31
- data/lib/anyway/ext/hash.rb +2 -0
- data/lib/anyway/ext/string.rb +44 -0
- data/lib/anyway/option_parser_builder.rb +31 -0
- data/lib/anyway/version.rb +1 -1
- data/spec/config_spec.rb +85 -6
- data/spec/ext/hash_spec.rb +39 -0
- data/spec/ext/string_spec.rb +32 -0
- metadata +9 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b57f348945f2dbb59224655d3967880fd8c02adba6b54748b14436266c4c0c5d
|
4
|
+
data.tar.gz: 36101f8dcb28679c746846d861a220ec28d836eb62cbbdaa5cb3f1254b56446b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d623918a56e50ab8c2f7eba539d2a4c1ea487a3192277525b559443d49328ee2cb70e9739bdd8524298ef3bff69fde6819b26262e245dafd7712a8a2c5a50d27
|
7
|
+
data.tar.gz: 60a2be222bc918750f6896bb4fcb1c2f1a2570ca32780a3f55e8d3610f8f3fdc78033971c9104968f5970c9b3943272f54fe911995dc43819f774a669010c80a
|
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
@@ -19,7 +19,7 @@ Style/Documentation:
|
|
19
19
|
Exclude:
|
20
20
|
- 'spec/**/*.rb'
|
21
21
|
|
22
|
-
Style/StringLiterals:
|
22
|
+
Style/StringLiterals:
|
23
23
|
Enabled: false
|
24
24
|
|
25
25
|
Style/BlockDelimiters:
|
@@ -34,6 +34,9 @@ Metrics/BlockLength:
|
|
34
34
|
Exclude:
|
35
35
|
- 'spec/**/*.rb'
|
36
36
|
|
37
|
+
Metrics/ClassLength:
|
38
|
+
Max: 140
|
39
|
+
|
37
40
|
Metrics/LineLength:
|
38
41
|
Max: 100
|
39
42
|
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,31 @@
|
|
2
2
|
|
3
3
|
## master
|
4
4
|
|
5
|
+
## 1.4.0 (2018-10-29)
|
6
|
+
|
7
|
+
- Add OptionParse integration ([@jastkand][])
|
8
|
+
|
9
|
+
See more https://github.com/palkan/anyway_config/pull/18
|
10
|
+
|
11
|
+
- Use underscored config name as an env prefix. ([@palkan][])
|
12
|
+
|
13
|
+
For a config class:
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
class MyApp < Anyway::Config
|
17
|
+
end
|
18
|
+
```
|
19
|
+
|
20
|
+
Before this change we use `MYAPP_` prefix, now it's `MY_APP_`.
|
21
|
+
|
22
|
+
You can specify the prefix explictly:
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
class MyApp < Anyway::Config
|
26
|
+
env_prefix "MYAPP_"
|
27
|
+
end
|
28
|
+
```
|
29
|
+
|
5
30
|
## 1.3.0 (2018-06-15)
|
6
31
|
|
7
32
|
- Ruby 2.2 is no longer supported.
|
@@ -67,3 +92,4 @@ Initial version.
|
|
67
92
|
[@onemanstartup]: https://github.com/onemanstartup
|
68
93
|
[@dsalahutdinov]: https://github.com/dsalahutdinov
|
69
94
|
[@charlie-wasp]: https://github.com/charlie-wasp
|
95
|
+
[@jastkand]: https://github.com/jastkand
|
data/README.md
CHANGED
@@ -91,8 +91,8 @@ end
|
|
91
91
|
|
92
92
|
#### Customize env variable names prefix
|
93
93
|
|
94
|
-
By default, Anyway Config
|
95
|
-
`config_name :my_app` will result to parsing `
|
94
|
+
By default, Anyway Config uses underscored config name as a prefix for env variable names (e.g.
|
95
|
+
`config_name :my_app` will result to parsing `MY_APP_HOST` variable). You can set env prefix
|
96
96
|
explicitly, and it will be used as is:
|
97
97
|
|
98
98
|
```ruby
|
@@ -105,10 +105,6 @@ module MyCoolGem
|
|
105
105
|
end
|
106
106
|
```
|
107
107
|
|
108
|
-
**DEPRECATION WARNING** In the 1.4 version no stripping will be applied on config_names by default, so if you use explicit config names with
|
109
|
-
underscores and use env variables, your app will be broken. In this case it is recommended to start using `env_prefix`
|
110
|
-
now.
|
111
|
-
|
112
108
|
#### Provide explicit values
|
113
109
|
|
114
110
|
Sometimes it's useful to set some parameters explicitly during config initialization.
|
@@ -150,7 +146,7 @@ Your config will be filled up with values from the following sources (ordered by
|
|
150
146
|
By default, Anyway Config is looking for a config YAML at `./config/<config-name>.yml`. You can override this setting
|
151
147
|
through special environment variable – 'MYGEM_CONF' – containing the path to the YAML file.
|
152
148
|
|
153
|
-
Environmental variables work the same way as with Rails.
|
149
|
+
Environmental variables work the same way as with Rails.
|
154
150
|
|
155
151
|
|
156
152
|
### Config clear and reload
|
@@ -159,9 +155,49 @@ There are `#clear` and `#reload` functions on your config (which do exactly what
|
|
159
155
|
|
160
156
|
Note: `#reload` also accepts `overrides` key to provide explicit values (see above).
|
161
157
|
|
158
|
+
### OptionParser integration
|
159
|
+
|
160
|
+
It's possible to use config as option parser (e.g. for CLI apps/libraries). It uses
|
161
|
+
[`optparse`](https://ruby-doc.org/stdlib-2.5.1/libdoc/optparse/rdoc/OptionParser.html) under the hood.
|
162
|
+
|
163
|
+
Example usage:
|
164
|
+
|
165
|
+
```ruby
|
166
|
+
class MyConfig < Anyway::Config
|
167
|
+
attr_config :host, :log_level, :concurrency, server_args: {}
|
168
|
+
|
169
|
+
# specify which options shouldn't be handled by option parser
|
170
|
+
ignore_options :server_args
|
171
|
+
|
172
|
+
# provide description for options
|
173
|
+
describe_options(
|
174
|
+
concurrency: "number of threads to use"
|
175
|
+
)
|
176
|
+
|
177
|
+
# extend an option parser object (i.e. add banner or version/help handlers)
|
178
|
+
extend_options do |parser|
|
179
|
+
parser.banner = "mycli [options]"
|
180
|
+
parser.on_tail "-h", "--help" do
|
181
|
+
puts parser
|
182
|
+
end
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
config = MyConfig.new
|
187
|
+
|
188
|
+
config.parse_options!(%w(--host localhost --port 3333 --log-level debug))
|
189
|
+
|
190
|
+
config.host # => "localhost"
|
191
|
+
config.port # => 3333
|
192
|
+
config.log_level # => "debug"
|
193
|
+
|
194
|
+
# Get the instance of OptionParser
|
195
|
+
config.option_parser
|
196
|
+
```
|
197
|
+
|
162
198
|
## `Rails.application.config_for` vs `Anyway::Config.for`
|
163
199
|
|
164
|
-
Rails 4.2 introduced new feature: `Rails.application.config_for`. It looks very similar to
|
200
|
+
Rails 4.2 introduced new feature: `Rails.application.config_for`. It looks very similar to
|
165
201
|
`Anyway::Config.for`, but there are some differences:
|
166
202
|
|
167
203
|
| Feature | Rails | Anyway Config |
|
@@ -169,7 +205,7 @@ Rails 4.2 introduced new feature: `Rails.application.config_for`. It looks very
|
|
169
205
|
| load data from `config/app.yml` | yes | yes |
|
170
206
|
| load data from `secrets` | no | yes |
|
171
207
|
| load data from environment | no | yes |
|
172
|
-
| return Hash with indifferent access | no | yes |
|
208
|
+
| return Hash with indifferent access | no | yes |
|
173
209
|
| support ERB within `config/app.yml` | yes | yes* |
|
174
210
|
| raise errors if file doesn't exist | yes | no |
|
175
211
|
|
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.60.0"
|
27
27
|
s.add_development_dependency "simplecov", ">= 0.3.8"
|
28
28
|
end
|
data/lib/anyway/config.rb
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
require 'anyway/ext/deep_dup'
|
4
4
|
require 'anyway/ext/deep_freeze'
|
5
5
|
require 'anyway/ext/hash'
|
6
|
+
require 'anyway/option_parser_builder'
|
6
7
|
|
7
8
|
module Anyway # :nodoc:
|
8
9
|
using Anyway::Ext::DeepDup
|
@@ -14,7 +15,7 @@ module Anyway # :nodoc:
|
|
14
15
|
# configuration parameters and set defaults
|
15
16
|
class Config
|
16
17
|
class << self
|
17
|
-
attr_reader :defaults, :config_attributes
|
18
|
+
attr_reader :defaults, :config_attributes, :option_parser_extension
|
18
19
|
|
19
20
|
def attr_config(*args, **hargs)
|
20
21
|
@defaults ||= {}
|
@@ -36,6 +37,30 @@ module Anyway # :nodoc:
|
|
36
37
|
@config_name
|
37
38
|
end
|
38
39
|
|
40
|
+
def ignore_options(*args)
|
41
|
+
@ignore_options ||= []
|
42
|
+
@ignore_options |= args
|
43
|
+
end
|
44
|
+
|
45
|
+
def describe_options(**hargs)
|
46
|
+
@option_parser_descriptions ||= {}
|
47
|
+
@option_parser_descriptions.merge!(hargs.stringify_keys!)
|
48
|
+
end
|
49
|
+
|
50
|
+
def extend_options(&block)
|
51
|
+
@option_parser_extension = block
|
52
|
+
end
|
53
|
+
|
54
|
+
def option_parser_options
|
55
|
+
ignored_options = @ignore_options || []
|
56
|
+
descriptions = @option_parser_descriptions || {}
|
57
|
+
config_attributes.each_with_object({}) do |key, result|
|
58
|
+
next if ignored_options.include?(key.to_sym)
|
59
|
+
|
60
|
+
result[key] ||= descriptions[key.to_s]
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
39
64
|
def env_prefix(val = nil)
|
40
65
|
return (@env_prefix = val.to_s) unless val.nil?
|
41
66
|
|
@@ -72,26 +97,15 @@ module Anyway # :nodoc:
|
|
72
97
|
#
|
73
98
|
# my_config = Anyway::Config.new(name: :my_app, load: true, overrides: { some: :value })
|
74
99
|
#
|
75
|
-
# rubocop:disable Metrics/MethodLength,Metrics/AbcSize,Metrics/LineLength,Metrics/CyclomaticComplexity
|
76
100
|
def initialize(name: nil, load: true, overrides: {})
|
77
101
|
@config_name = name || self.class.config_name
|
78
102
|
|
79
103
|
raise ArgumentError, "Config name is missing" unless @config_name
|
80
104
|
|
81
|
-
|
82
|
-
warn "[Deprecated] As your config_name is #{@config_name}, " \
|
83
|
-
"the prefix `#{@config_name.to_s.delete('_').upcase}` " \
|
84
|
-
"will be used to parse env variables. " \
|
85
|
-
"This behavior is about to change in 1.4.0 (no more deleting underscores). " \
|
86
|
-
"Env prefix can be set explicitly with `env_prefix` method now already " \
|
87
|
-
"(check out the docs), and it will be used as is."
|
88
|
-
end
|
89
|
-
|
90
|
-
@env_prefix = self.class.env_prefix || @config_name.to_s&.delete('_')
|
105
|
+
@env_prefix = self.class.env_prefix || @config_name
|
91
106
|
|
92
107
|
self.load(overrides) if load
|
93
108
|
end
|
94
|
-
# rubocop:enable Metrics/MethodLength,Metrics/AbcSize,Metrics/LineLength,Metrics/CyclomaticComplexity
|
95
109
|
|
96
110
|
def reload(overrides = {})
|
97
111
|
clear
|
@@ -135,6 +149,19 @@ module Anyway # :nodoc:
|
|
135
149
|
config
|
136
150
|
end
|
137
151
|
|
152
|
+
def option_parser
|
153
|
+
@option_parser ||= begin
|
154
|
+
parser = OptionParserBuilder.call(self.class.option_parser_options) do |key, arg|
|
155
|
+
set_value(key, arg)
|
156
|
+
end
|
157
|
+
self.class.option_parser_extension&.call(parser) || parser
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
def parse_options!(options)
|
162
|
+
option_parser.parse!(options)
|
163
|
+
end
|
164
|
+
|
138
165
|
def to_h
|
139
166
|
self.class.config_attributes.each_with_object({}) do |key, obj|
|
140
167
|
obj[key.to_sym] = send(key)
|
data/lib/anyway/env.rb
CHANGED
@@ -1,17 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'anyway/ext/deep_dup'
|
4
|
+
require 'anyway/ext/string'
|
4
5
|
|
5
6
|
module Anyway
|
6
7
|
# Parses environment variables and provides
|
7
8
|
# method-like access
|
8
9
|
class Env
|
9
10
|
using Anyway::Ext::DeepDup
|
10
|
-
|
11
|
-
# Regexp to detect array values
|
12
|
-
# Array value is a values that contains at least one comma
|
13
|
-
# and doesn't start/end with quote
|
14
|
-
ARRAY_RXP = /\A[^'"].*\s*,\s*.*[^'"]\z/
|
11
|
+
using Anyway::Ext::String
|
15
12
|
|
16
13
|
def initialize
|
17
14
|
@data = {}
|
@@ -33,7 +30,7 @@ module Anyway
|
|
33
30
|
next unless key.start_with?(prefix)
|
34
31
|
|
35
32
|
path = key.sub(/^#{prefix}_/, '').downcase
|
36
|
-
set_by_path(data, path,
|
33
|
+
set_by_path(data, path, val.serialize)
|
37
34
|
end
|
38
35
|
end
|
39
36
|
|
@@ -48,30 +45,5 @@ module Anyway
|
|
48
45
|
def get_hash(from, name)
|
49
46
|
(from[name] ||= {})
|
50
47
|
end
|
51
|
-
|
52
|
-
# rubocop:disable Metrics/MethodLength
|
53
|
-
# rubocop:disable Metrics/CyclomaticComplexity
|
54
|
-
def serialize_val(value)
|
55
|
-
case value
|
56
|
-
when ARRAY_RXP
|
57
|
-
value.split(/\s*,\s*/).map(&method(:serialize_val))
|
58
|
-
when /\A(true|t|yes|y)\z/i
|
59
|
-
true
|
60
|
-
when /\A(false|f|no|n)\z/i
|
61
|
-
false
|
62
|
-
when /\A(nil|null)\z/i
|
63
|
-
nil
|
64
|
-
when /\A\d+\z/
|
65
|
-
value.to_i
|
66
|
-
when /\A\d*\.\d+\z/
|
67
|
-
value.to_f
|
68
|
-
when /\A['"].*['"]\z/
|
69
|
-
value.gsub(/(\A['"]|['"]\z)/, '')
|
70
|
-
else
|
71
|
-
value
|
72
|
-
end
|
73
|
-
end
|
74
|
-
# rubocop:enable Metrics/MethodLength
|
75
|
-
# rubocop:enable Metrics/CyclomaticComplexity
|
76
48
|
end
|
77
49
|
end
|
data/lib/anyway/ext/hash.rb
CHANGED
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Anyway
|
4
|
+
module Ext
|
5
|
+
# Extend String through refinements
|
6
|
+
module String
|
7
|
+
refine ::String do
|
8
|
+
# Regexp to detect array values
|
9
|
+
# Array value is a values that contains at least one comma
|
10
|
+
# and doesn't start/end with quote
|
11
|
+
ARRAY_RXP = /\A[^'"].*\s*,\s*.*[^'"]\z/
|
12
|
+
|
13
|
+
# rubocop:disable Metrics/MethodLength
|
14
|
+
# rubocop:disable Metrics/CyclomaticComplexity
|
15
|
+
def serialize
|
16
|
+
case self
|
17
|
+
when ARRAY_RXP
|
18
|
+
# rubocop:disable Style/SymbolProc
|
19
|
+
split(/\s*,\s*/).map { |word| word.serialize }
|
20
|
+
# rubocop:enable Style/SymbolProc
|
21
|
+
when /\A(true|t|yes|y)\z/i
|
22
|
+
true
|
23
|
+
when /\A(false|f|no|n)\z/i
|
24
|
+
false
|
25
|
+
when /\A(nil|null)\z/i
|
26
|
+
nil
|
27
|
+
when /\A\d+\z/
|
28
|
+
to_i
|
29
|
+
when /\A\d*\.\d+\z/
|
30
|
+
to_f
|
31
|
+
when /\A['"].*['"]\z/
|
32
|
+
gsub(/(\A['"]|['"]\z)/, '')
|
33
|
+
else
|
34
|
+
self
|
35
|
+
end
|
36
|
+
end
|
37
|
+
# rubocop:enable Metrics/MethodLength
|
38
|
+
# rubocop:enable Metrics/CyclomaticComplexity
|
39
|
+
end
|
40
|
+
|
41
|
+
using self
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'optparse'
|
4
|
+
require 'anyway/ext/string'
|
5
|
+
|
6
|
+
module Anyway # :nodoc:
|
7
|
+
using Anyway::Ext::String
|
8
|
+
|
9
|
+
# Initializes the OptionParser instance using the given configuration
|
10
|
+
class OptionParserBuilder
|
11
|
+
class << self
|
12
|
+
def call(options)
|
13
|
+
OptionParser.new do |opts|
|
14
|
+
options.each do |key, description|
|
15
|
+
opts.on(*option_parser_on_args(key, description)) do |arg|
|
16
|
+
yield [key, arg.serialize]
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def option_parser_on_args(key, description)
|
25
|
+
on_args = ["--#{key.to_s.tr('_', '-')} VALUE"]
|
26
|
+
on_args << description unless description.nil?
|
27
|
+
on_args
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/lib/anyway/version.rb
CHANGED
data/spec/config_spec.rb
CHANGED
@@ -109,10 +109,6 @@ describe Anyway::Config do
|
|
109
109
|
klass.new
|
110
110
|
end
|
111
111
|
|
112
|
-
it "warns user about deprecated behaviour" do
|
113
|
-
expect { conf }.to print_warning
|
114
|
-
end
|
115
|
-
|
116
112
|
context "when env_name is set" do
|
117
113
|
let(:conf) do
|
118
114
|
klass = CoolConfig.dup
|
@@ -177,8 +173,8 @@ describe Anyway::Config do
|
|
177
173
|
end
|
178
174
|
|
179
175
|
it "load data by config name", :aggregate_failures do
|
180
|
-
ENV['
|
181
|
-
ENV['
|
176
|
+
ENV['MY_APP_TEST'] = '1'
|
177
|
+
ENV['MY_APP_NAME'] = 'my_app'
|
182
178
|
Anyway.env.clear
|
183
179
|
data = Anyway::Config.for(:my_app)
|
184
180
|
expect(data[:test]).to eq 1
|
@@ -236,4 +232,87 @@ describe Anyway::Config do
|
|
236
232
|
expect(new_config.new_param).to eq 'a'
|
237
233
|
end
|
238
234
|
end
|
235
|
+
|
236
|
+
describe "#parse_options!" do
|
237
|
+
let(:config_instance) { config.new }
|
238
|
+
|
239
|
+
context "when `ignore_options` is not provided" do
|
240
|
+
let(:config) do
|
241
|
+
Class.new(described_class) do
|
242
|
+
config_name 'optparse'
|
243
|
+
attr_config :host, :port, :log_level, :debug
|
244
|
+
end
|
245
|
+
end
|
246
|
+
|
247
|
+
it "parses ARGC string" do
|
248
|
+
config_instance.parse_options!(%w[--host localhost --port 3333 --log-level debug --debug T])
|
249
|
+
expect(config_instance.host).to eq("localhost")
|
250
|
+
expect(config_instance.port).to eq(3333)
|
251
|
+
expect(config_instance.log_level).to eq("debug")
|
252
|
+
expect(config_instance.debug).to eq(true)
|
253
|
+
end
|
254
|
+
end
|
255
|
+
|
256
|
+
context 'when `ignore_options` is provided' do
|
257
|
+
let(:config) do
|
258
|
+
Class.new(described_class) do
|
259
|
+
config_name 'optparse'
|
260
|
+
attr_config :host, :log_level, :concurrency, server_args: {}
|
261
|
+
|
262
|
+
ignore_options :server_args
|
263
|
+
end
|
264
|
+
end
|
265
|
+
|
266
|
+
it "parses ARGC string" do
|
267
|
+
expect do
|
268
|
+
config_instance.parse_options!(
|
269
|
+
%w[--host localhost --concurrency 10 --log-level debug --server-args SOME_ARGS]
|
270
|
+
)
|
271
|
+
end.to raise_error(OptionParser::InvalidOption, /--server-args/)
|
272
|
+
|
273
|
+
expect(config_instance.host).to eq("localhost")
|
274
|
+
expect(config_instance.concurrency).to eq(10)
|
275
|
+
expect(config_instance.log_level).to eq("debug")
|
276
|
+
expect(config_instance.server_args).to eq({})
|
277
|
+
end
|
278
|
+
end
|
279
|
+
|
280
|
+
context 'when `describe_options` is provided' do
|
281
|
+
let(:config) do
|
282
|
+
Class.new(described_class) do
|
283
|
+
config_name 'optparse'
|
284
|
+
attr_config :host, :log_level, :concurrency, server_args: {}
|
285
|
+
|
286
|
+
describe_options(
|
287
|
+
concurrency: "number of threads to use"
|
288
|
+
)
|
289
|
+
end
|
290
|
+
end
|
291
|
+
|
292
|
+
it "contains options description" do
|
293
|
+
expect(config_instance.option_parser.help).to include("number of threads to use")
|
294
|
+
end
|
295
|
+
end
|
296
|
+
|
297
|
+
context "customization of option parser" do
|
298
|
+
let(:config) do
|
299
|
+
Class.new(described_class) do
|
300
|
+
config_name 'optparse'
|
301
|
+
attr_config :host, :log_level, :concurrency, server_args: {}
|
302
|
+
|
303
|
+
extend_options do |parser|
|
304
|
+
parser.banner = "mycli [options]"
|
305
|
+
|
306
|
+
parser.on_tail "-h", "--help" do
|
307
|
+
puts parser
|
308
|
+
end
|
309
|
+
end
|
310
|
+
end
|
311
|
+
end
|
312
|
+
|
313
|
+
it "allows to customize the parser" do
|
314
|
+
expect(config_instance.option_parser.help).to include("mycli [options]")
|
315
|
+
end
|
316
|
+
end
|
317
|
+
end
|
239
318
|
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Anyway::Ext::Hash do
|
6
|
+
using Anyway::Ext::Hash
|
7
|
+
|
8
|
+
describe "#stringify_keys!" do
|
9
|
+
let(:source) do
|
10
|
+
{
|
11
|
+
a: 1,
|
12
|
+
b: 'hello',
|
13
|
+
c: {
|
14
|
+
id: 1
|
15
|
+
}
|
16
|
+
}
|
17
|
+
end
|
18
|
+
|
19
|
+
let(:expected_result) do
|
20
|
+
{
|
21
|
+
'a' => 1,
|
22
|
+
'b' => 'hello',
|
23
|
+
'c' => {
|
24
|
+
'id' => 1
|
25
|
+
}
|
26
|
+
}
|
27
|
+
end
|
28
|
+
|
29
|
+
it "transforms keys of hash to strings" do
|
30
|
+
source.stringify_keys!
|
31
|
+
|
32
|
+
expect(source).to eq(expected_result)
|
33
|
+
end
|
34
|
+
|
35
|
+
it "returns a hash with transformed keys to strings" do
|
36
|
+
expect(source.stringify_keys!).to eq(expected_result)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Anyway::Ext::String do
|
6
|
+
using Anyway::Ext::String
|
7
|
+
|
8
|
+
it "serializes a string", :aggregate_failures do
|
9
|
+
expect("1,2, 3".serialize).to eq [1, 2, 3]
|
10
|
+
|
11
|
+
expect("t".serialize).to eq true
|
12
|
+
expect("true".serialize).to eq true
|
13
|
+
expect("y".serialize).to eq true
|
14
|
+
expect("yes".serialize).to eq true
|
15
|
+
|
16
|
+
expect("f".serialize).to eq false
|
17
|
+
expect("false".serialize).to eq false
|
18
|
+
expect("n".serialize).to eq false
|
19
|
+
expect("no".serialize).to eq false
|
20
|
+
|
21
|
+
expect("null".serialize).to eq nil
|
22
|
+
expect("nil".serialize).to eq nil
|
23
|
+
|
24
|
+
expect("1".serialize).to eq 1
|
25
|
+
|
26
|
+
expect("1.5".serialize).to eq 1.5
|
27
|
+
|
28
|
+
expect("'localhost'".serialize).to eq "localhost"
|
29
|
+
|
30
|
+
expect("localhost".serialize).to eq "localhost"
|
31
|
+
end
|
32
|
+
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.
|
4
|
+
version: 1.4.0
|
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-10-29 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.60.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.60.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: simplecov
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -82,6 +82,8 @@ files:
|
|
82
82
|
- lib/anyway/ext/deep_dup.rb
|
83
83
|
- lib/anyway/ext/deep_freeze.rb
|
84
84
|
- lib/anyway/ext/hash.rb
|
85
|
+
- lib/anyway/ext/string.rb
|
86
|
+
- lib/anyway/option_parser_builder.rb
|
85
87
|
- lib/anyway/rails/config.rb
|
86
88
|
- lib/anyway/version.rb
|
87
89
|
- lib/anyway_config.rb
|
@@ -100,6 +102,8 @@ files:
|
|
100
102
|
- spec/env_spec.rb
|
101
103
|
- spec/ext/deep_dup_spec.rb
|
102
104
|
- spec/ext/deep_freeze_spec.rb
|
105
|
+
- spec/ext/hash_spec.rb
|
106
|
+
- spec/ext/string_spec.rb
|
103
107
|
- spec/spec_helper.rb
|
104
108
|
- spec/spec_norails_helper.rb
|
105
109
|
- spec/support/cool_config.rb
|
@@ -126,7 +130,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
126
130
|
version: '0'
|
127
131
|
requirements: []
|
128
132
|
rubyforge_project:
|
129
|
-
rubygems_version: 2.7.
|
133
|
+
rubygems_version: 2.7.7
|
130
134
|
signing_key:
|
131
135
|
specification_version: 4
|
132
136
|
summary: Configuration DSL for Ruby libraries and applications
|