sinclair 2.0.0 → 2.1.0
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/README.md +3 -3
- data/config/check_specs.yml +2 -0
- data/config/yardstick.yml +5 -1
- data/lib/sinclair/chain_settable.rb +83 -0
- data/lib/sinclair/class_methods.rb +2 -2
- data/lib/sinclair/core_ext/object.rb +39 -0
- data/lib/sinclair/env_settable.rb +35 -17
- data/lib/sinclair/settable/builder.rb +140 -0
- data/lib/sinclair/settable/caster.rb +61 -0
- data/lib/sinclair/settable/class_methods.rb +80 -0
- data/lib/sinclair/settable.rb +115 -0
- data/lib/sinclair/version.rb +1 -1
- data/lib/sinclair.rb +2 -0
- data/spec/integration/yard/sinclair/env_settable_spec.rb +6 -25
- data/spec/integration/yard/sinclair/settable/caster_spec.rb +41 -0
- data/spec/integration/yard/sinclair/settable/class_methods_spec.rb +11 -0
- data/spec/integration/yard/sinclair/settable_spec.rb +26 -0
- data/spec/lib/sinclair/chain_settable_spec.rb +76 -0
- data/spec/lib/sinclair/class_methods_spec.rb +24 -4
- data/spec/lib/sinclair/env_settable_spec.rb +4 -2
- data/spec/lib/sinclair/settable/builder_spec.rb +47 -0
- data/spec/lib/sinclair/settable_spec.rb +46 -0
- data/spec/support/files/config.yml +1 -0
- data/spec/support/models/app_client.rb +1 -0
- data/spec/support/models/complex_builder.rb +17 -0
- data/spec/support/models/hash_app_client.rb +14 -0
- data/spec/support/models/hash_settable.rb +10 -0
- data/spec/support/models/json_env_settings.rb +18 -0
- data/spec/support/models/math_env_settings.rb +17 -0
- data/spec/support/models/my_app_client.rb +1 -0
- data/spec/support/models/non_default_app_client.rb +8 -0
- data/spec/support/models/yaml_file_settings.rb +26 -0
- data/spec/support/shared_examples/settable.rb +86 -0
- metadata +22 -5
- data/lib/sinclair/env_settable/builder.rb +0 -61
- data/spec/lib/sinclair/env_settable/builder_spec.rb +0 -35
- data/spec/support/shared_examples/env_settable.rb +0 -43
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sinclair
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- DarthJee
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-07-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -275,6 +275,7 @@ files:
|
|
275
275
|
- lib/sinclair.rb
|
276
276
|
- lib/sinclair/caster.rb
|
277
277
|
- lib/sinclair/caster/class_methods.rb
|
278
|
+
- lib/sinclair/chain_settable.rb
|
278
279
|
- lib/sinclair/class_methods.rb
|
279
280
|
- lib/sinclair/comparable.rb
|
280
281
|
- lib/sinclair/comparable/class_methods.rb
|
@@ -286,7 +287,6 @@ files:
|
|
286
287
|
- lib/sinclair/configurable.rb
|
287
288
|
- lib/sinclair/core_ext/object.rb
|
288
289
|
- lib/sinclair/env_settable.rb
|
289
|
-
- lib/sinclair/env_settable/builder.rb
|
290
290
|
- lib/sinclair/equals_checker.rb
|
291
291
|
- lib/sinclair/equals_checker/reader.rb
|
292
292
|
- lib/sinclair/exception.rb
|
@@ -326,6 +326,10 @@ files:
|
|
326
326
|
- lib/sinclair/options/builder.rb
|
327
327
|
- lib/sinclair/options/class_methods.rb
|
328
328
|
- lib/sinclair/options_parser.rb
|
329
|
+
- lib/sinclair/settable.rb
|
330
|
+
- lib/sinclair/settable/builder.rb
|
331
|
+
- lib/sinclair/settable/caster.rb
|
332
|
+
- lib/sinclair/settable/class_methods.rb
|
329
333
|
- lib/sinclair/version.rb
|
330
334
|
- sinclair.gemspec
|
331
335
|
- sinclair.jpg
|
@@ -367,9 +371,13 @@ files:
|
|
367
371
|
- spec/integration/yard/sinclair/model_spec.rb
|
368
372
|
- spec/integration/yard/sinclair/options_parser_spec.rb
|
369
373
|
- spec/integration/yard/sinclair/options_spec.rb
|
374
|
+
- spec/integration/yard/sinclair/settable/caster_spec.rb
|
375
|
+
- spec/integration/yard/sinclair/settable/class_methods_spec.rb
|
376
|
+
- spec/integration/yard/sinclair/settable_spec.rb
|
370
377
|
- spec/integration/yard/sinclair_spec.rb
|
371
378
|
- spec/lib/sinclair/caster/class_methods_spec.rb
|
372
379
|
- spec/lib/sinclair/caster_spec.rb
|
380
|
+
- spec/lib/sinclair/chain_settable_spec.rb
|
373
381
|
- spec/lib/sinclair/class_methods_spec.rb
|
374
382
|
- spec/lib/sinclair/comparable_spec.rb
|
375
383
|
- spec/lib/sinclair/config/methods_builder_spec.rb
|
@@ -379,7 +387,6 @@ files:
|
|
379
387
|
- spec/lib/sinclair/config_spec.rb
|
380
388
|
- spec/lib/sinclair/configurable_spec.rb
|
381
389
|
- spec/lib/sinclair/core_ext/object_spec.rb
|
382
|
-
- spec/lib/sinclair/env_settable/builder_spec.rb
|
383
390
|
- spec/lib/sinclair/env_settable_spec.rb
|
384
391
|
- spec/lib/sinclair/equals_checker/reader_spec.rb
|
385
392
|
- spec/lib/sinclair/equals_checker_spec.rb
|
@@ -413,14 +420,18 @@ files:
|
|
413
420
|
- spec/lib/sinclair/options/class_methods_spec.rb
|
414
421
|
- spec/lib/sinclair/options_parser_spec.rb
|
415
422
|
- spec/lib/sinclair/options_spec.rb
|
423
|
+
- spec/lib/sinclair/settable/builder_spec.rb
|
424
|
+
- spec/lib/sinclair/settable_spec.rb
|
416
425
|
- spec/lib/sinclair_spec.rb
|
417
426
|
- spec/spec_helper.rb
|
427
|
+
- spec/support/files/config.yml
|
418
428
|
- spec/support/fixture_helpers.rb
|
419
429
|
- spec/support/models/app_client.rb
|
420
430
|
- spec/support/models/app_config.rb
|
421
431
|
- spec/support/models/builder_options.rb
|
422
432
|
- spec/support/models/car.rb
|
423
433
|
- spec/support/models/client.rb
|
434
|
+
- spec/support/models/complex_builder.rb
|
424
435
|
- spec/support/models/connection_options.rb
|
425
436
|
- spec/support/models/default_value.rb
|
426
437
|
- spec/support/models/default_value_builder.rb
|
@@ -433,17 +444,21 @@ files:
|
|
433
444
|
- spec/support/models/enum_caster.rb
|
434
445
|
- spec/support/models/enum_converter.rb
|
435
446
|
- spec/support/models/env_settings.rb
|
447
|
+
- spec/support/models/hash_app_client.rb
|
436
448
|
- spec/support/models/hash_model.rb
|
437
449
|
- spec/support/models/hash_person.rb
|
450
|
+
- spec/support/models/hash_settable.rb
|
438
451
|
- spec/support/models/host_config.rb
|
439
452
|
- spec/support/models/http_json_model.rb
|
440
453
|
- spec/support/models/http_person.rb
|
441
454
|
- spec/support/models/human.rb
|
442
455
|
- spec/support/models/initial_valuer.rb
|
443
456
|
- spec/support/models/job.rb
|
457
|
+
- spec/support/models/json_env_settings.rb
|
444
458
|
- spec/support/models/login_config.rb
|
445
459
|
- spec/support/models/login_configurable.rb
|
446
460
|
- spec/support/models/math_caster.rb
|
461
|
+
- spec/support/models/math_env_settings.rb
|
447
462
|
- spec/support/models/my_app_client.rb
|
448
463
|
- spec/support/models/my_builder.rb
|
449
464
|
- spec/support/models/my_class.rb
|
@@ -452,6 +467,7 @@ files:
|
|
452
467
|
- spec/support/models/my_configurable.rb
|
453
468
|
- spec/support/models/my_model.rb
|
454
469
|
- spec/support/models/my_server_config.rb
|
470
|
+
- spec/support/models/non_default_app_client.rb
|
455
471
|
- spec/support/models/open_options.rb
|
456
472
|
- spec/support/models/person.rb
|
457
473
|
- spec/support/models/purchase.rb
|
@@ -464,13 +480,14 @@ files:
|
|
464
480
|
- spec/support/models/string_parser.rb
|
465
481
|
- spec/support/models/tv.rb
|
466
482
|
- spec/support/models/validator_builder.rb
|
483
|
+
- spec/support/models/yaml_file_settings.rb
|
467
484
|
- spec/support/shared_examples/attribute_accessor.rb
|
468
485
|
- spec/support/shared_examples/class_method_definition.rb
|
469
486
|
- spec/support/shared_examples/config.rb
|
470
487
|
- spec/support/shared_examples/config_factory.rb
|
471
|
-
- spec/support/shared_examples/env_settable.rb
|
472
488
|
- spec/support/shared_examples/instance_method_definition.rb
|
473
489
|
- spec/support/shared_examples/model.rb
|
490
|
+
- spec/support/shared_examples/settable.rb
|
474
491
|
- spec/support/shared_examples/sinclair.rb
|
475
492
|
homepage: https://github.com/darthjee/sinclair
|
476
493
|
licenses: []
|
@@ -1,61 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
class Sinclair
|
4
|
-
module EnvSettable
|
5
|
-
# @api private
|
6
|
-
# @author darthjee
|
7
|
-
#
|
8
|
-
# Env setting methods builder
|
9
|
-
#
|
10
|
-
# This builder does the magic of adding methods
|
11
|
-
# that will fetch variables from env or a default value
|
12
|
-
class Builder < Sinclair
|
13
|
-
# @param klass [Class] Class that will receive the methods
|
14
|
-
# @param prefix [String] Env keys prefix
|
15
|
-
# @param (see EnvSettable#with_settings)
|
16
|
-
def initialize(klass, prefix, *settings_name, **defaults)
|
17
|
-
super(klass, prefix: prefix)
|
18
|
-
|
19
|
-
@settings = Sinclair::InputHash.input_hash(*settings_name, **defaults)
|
20
|
-
|
21
|
-
add_all_methods
|
22
|
-
end
|
23
|
-
|
24
|
-
private
|
25
|
-
|
26
|
-
attr_reader :settings
|
27
|
-
# @method settings
|
28
|
-
# @private
|
29
|
-
# @api private
|
30
|
-
#
|
31
|
-
# Settings map with default values
|
32
|
-
#
|
33
|
-
# @return [Hash<Symbol,Object>]
|
34
|
-
|
35
|
-
delegate :prefix, to: :options_object
|
36
|
-
# @method prefix
|
37
|
-
# @private
|
38
|
-
# @api private
|
39
|
-
#
|
40
|
-
# Env keys prefix
|
41
|
-
#
|
42
|
-
# @return [String]
|
43
|
-
|
44
|
-
# @private
|
45
|
-
# @api private
|
46
|
-
#
|
47
|
-
# Process all settings adding the methods
|
48
|
-
#
|
49
|
-
# @return (see settings)
|
50
|
-
def add_all_methods
|
51
|
-
settings.each do |name, value|
|
52
|
-
key = [prefix, name].compact.join('_').to_s.upcase
|
53
|
-
|
54
|
-
add_class_method(name) do
|
55
|
-
ENV[key] || value
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
@@ -1,35 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe Sinclair::EnvSettable::Builder do
|
6
|
-
subject(:settable) { Class.new }
|
7
|
-
|
8
|
-
let(:username) { 'my_login' }
|
9
|
-
let(:password) { Random.rand(10_000).to_s }
|
10
|
-
|
11
|
-
let(:builder) do
|
12
|
-
described_class.new(settable, prefix, :username, :password, host: 'my-host.com')
|
13
|
-
end
|
14
|
-
|
15
|
-
before { builder.build }
|
16
|
-
|
17
|
-
context 'when not using prefix' do
|
18
|
-
let(:prefix) { nil }
|
19
|
-
|
20
|
-
let(:username_key) { 'USERNAME' }
|
21
|
-
let(:password_key) { 'PASSWORD' }
|
22
|
-
let(:host_key) { 'HOST' }
|
23
|
-
|
24
|
-
it_behaves_like 'settings reading from env'
|
25
|
-
end
|
26
|
-
|
27
|
-
context 'when defining a prefix' do
|
28
|
-
let(:prefix) { 'MY_APP' }
|
29
|
-
let(:username_key) { 'MY_APP_USERNAME' }
|
30
|
-
let(:password_key) { 'MY_APP_PASSWORD' }
|
31
|
-
let(:host_key) { 'MY_APP_HOST' }
|
32
|
-
|
33
|
-
it_behaves_like 'settings reading from env'
|
34
|
-
end
|
35
|
-
end
|
@@ -1,43 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
shared_examples 'settings reading from env' do
|
4
|
-
before do
|
5
|
-
ENV[username_key] = username
|
6
|
-
ENV[password_key] = password
|
7
|
-
end
|
8
|
-
|
9
|
-
after do
|
10
|
-
ENV.delete(username_key)
|
11
|
-
ENV.delete(password_key)
|
12
|
-
end
|
13
|
-
|
14
|
-
it 'retrieves username from env' do
|
15
|
-
expect(settable.username).to eq(username)
|
16
|
-
end
|
17
|
-
|
18
|
-
it 'retrieves password from env' do
|
19
|
-
expect(settable.password).to eq(password)
|
20
|
-
end
|
21
|
-
|
22
|
-
context 'when defining defaults' do
|
23
|
-
it 'returns default value' do
|
24
|
-
expect(settable.host).to eq('my-host.com')
|
25
|
-
end
|
26
|
-
|
27
|
-
context 'when setting the env variable' do
|
28
|
-
let(:other_host) { 'other-host.com' }
|
29
|
-
|
30
|
-
before do
|
31
|
-
ENV[host_key] = other_host
|
32
|
-
end
|
33
|
-
|
34
|
-
after do
|
35
|
-
ENV.delete(host_key)
|
36
|
-
end
|
37
|
-
|
38
|
-
it 'retrieves host from env' do
|
39
|
-
expect(settable.host).to eq(other_host)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|