sinclair 3.0.0 → 3.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.
data/spec/spec_helper.rb CHANGED
@@ -1,6 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'simplecov'
4
+ require 'simplecov-lcov'
5
+
6
+ if ENV['CI']
7
+ SimpleCov::Formatter::LcovFormatter.config.report_with_single_file = true
8
+ SimpleCov.formatter = SimpleCov::Formatter::LcovFormatter
9
+ end
4
10
 
5
11
  SimpleCov.profiles.define 'gem' do
6
12
  add_filter '/spec/'
@@ -5,4 +5,6 @@ class AppClient
5
5
 
6
6
  with_settings :username, :password, host: 'my-host.com'
7
7
  setting_with_options :port, type: :integer
8
+ setting_with_options :domain, cached: true
9
+ setting_with_options :secret, cached: false
8
10
  end
@@ -11,4 +11,6 @@ class HashAppClient
11
11
 
12
12
  with_settings :username, :password, host: 'my-host.com'
13
13
  setting_with_options :port, type: :integer
14
+ setting_with_options :domain, cached: true
15
+ setting_with_options :secret, cached: false
14
16
  end
@@ -7,4 +7,6 @@ class MyAppClient
7
7
 
8
8
  with_settings :username, :password, host: 'my-host.com'
9
9
  setting_with_options :port, type: :integer
10
+ setting_with_options :domain, cached: true
11
+ setting_with_options :secret, cached: false
10
12
  end
@@ -5,4 +5,6 @@ class NonDefaultAppClient
5
5
 
6
6
  with_settings :username, :password, :host
7
7
  setting_with_options :port, type: :integer
8
+ setting_with_options :domain, cached: true
9
+ setting_with_options :secret, cached: false
8
10
  end
@@ -4,6 +4,11 @@ shared_examples 'settings reading' do
4
4
  let(:env_hash) { ENV }
5
5
 
6
6
  context 'when the key is not set' do
7
+ after do
8
+ env_hash.delete(username_key)
9
+ env_hash.delete(password_key)
10
+ end
11
+
7
12
  it 'retrieves username from env' do
8
13
  expect(settable.username).to be_nil
9
14
  end
@@ -11,6 +16,16 @@ shared_examples 'settings reading' do
11
16
  it 'retrieves password from env' do
12
17
  expect(settable.password).to be_nil
13
18
  end
19
+
20
+ it 'cache username from env' do
21
+ expect { env_hash[username_key] = SecureRandom.hex }
22
+ .not_to(change(settable, :username))
23
+ end
24
+
25
+ it 'cache password from env' do
26
+ expect { env_hash[password_key] = SecureRandom.hex }
27
+ .not_to(change(settable, :password))
28
+ end
14
29
  end
15
30
 
16
31
  context 'when the key is set' do
@@ -31,14 +46,35 @@ shared_examples 'settings reading' do
31
46
  it 'retrieves password from env' do
32
47
  expect(settable.password).to eq(password)
33
48
  end
49
+
50
+ it 'cache username from env' do
51
+ expect { env_hash[username_key] = SecureRandom.hex }
52
+ .not_to(change(settable, :username))
53
+ end
54
+
55
+ it 'cache password from env' do
56
+ expect { env_hash[password_key] = SecureRandom.hex }
57
+ .not_to(change(settable, :password))
58
+ end
34
59
  end
35
60
 
36
61
  context 'when defining defaults' do
37
62
  let(:settings) { %i[host] }
38
63
  let(:options) { { prefix:, default: 'my-host.com' } }
39
64
 
40
- it 'returns default value' do
41
- expect(settable.host).to eq('my-host.com')
65
+ after do
66
+ env_hash.delete(host_key)
67
+ end
68
+
69
+ context 'when not setting the env variable' do
70
+ it 'returns default value' do
71
+ expect(settable.host).to eq('my-host.com')
72
+ end
73
+
74
+ it 'caches default value' do
75
+ expect { env_hash[host_key] = SecureRandom.hex }
76
+ .not_to(change(settable, :host))
77
+ end
42
78
  end
43
79
 
44
80
  context 'when setting the env variable' do
@@ -48,13 +84,14 @@ shared_examples 'settings reading' do
48
84
  env_hash[host_key] = other_host
49
85
  end
50
86
 
51
- after do
52
- env_hash.delete(host_key)
53
- end
54
-
55
87
  it 'retrieves host from env' do
56
88
  expect(settable.host).to eq(other_host)
57
89
  end
90
+
91
+ it 'caches env value' do
92
+ expect { env_hash[host_key] = SecureRandom.hex }
93
+ .not_to(change(settable, :host))
94
+ end
58
95
  end
59
96
  end
60
97
 
@@ -62,11 +99,21 @@ shared_examples 'settings reading' do
62
99
  let(:settings) { %i[port] }
63
100
  let(:options) { { prefix:, type: :integer } }
64
101
  let(:port) { Random.rand(10..100) }
102
+ let(:new_port) { Random.rand(1000..10_000) }
103
+
104
+ after do
105
+ env_hash.delete(port_key)
106
+ end
65
107
 
66
108
  context 'when the key is not set' do
67
109
  it 'retrieves port and cast to string' do
68
110
  expect(settable.port).to be_nil
69
111
  end
112
+
113
+ it 'caches port as nil' do
114
+ expect { env_hash[port_key] = new_port.to_s }
115
+ .not_to(change(settable, :port))
116
+ end
70
117
  end
71
118
 
72
119
  context 'when the key is set' do
@@ -74,13 +121,93 @@ shared_examples 'settings reading' do
74
121
  env_hash[port_key] = port.to_s
75
122
  end
76
123
 
77
- after do
78
- env_hash.delete(port_key)
79
- end
80
-
81
124
  it 'retrieves port and cast to string' do
82
125
  expect(settable.port).to eq(port)
83
126
  end
127
+
128
+ it 'caches port as integer' do
129
+ expect { env_hash[port_key] = new_port.to_s }
130
+ .not_to(change(settable, :port))
131
+ end
132
+ end
133
+ end
134
+
135
+ context 'when defining cache type as true' do
136
+ let(:settings) { %i[domain] }
137
+ let(:options) { { prefix:, cached: true } }
138
+ let(:options_hash) { options }
139
+ let(:domain) { 'example.com' }
140
+ let(:new_domain) { 'new-example.com' }
141
+
142
+ after do
143
+ env_hash.delete(domain_key)
144
+ end
145
+
146
+ context 'when the key is not set' do
147
+ it 'retrieves domain and cast to string' do
148
+ expect(settable.domain).to be_nil
149
+ end
150
+
151
+ it 'does not caches domain as nil' do
152
+ expect { env_hash[domain_key] = new_domain.to_s }
153
+ .to change(settable, :domain)
154
+ .from(nil).to(new_domain)
155
+ end
156
+ end
157
+
158
+ context 'when the key is set' do
159
+ before do
160
+ env_hash[domain_key] = domain.to_s
161
+ end
162
+
163
+ it 'retrieves domain and cast to string' do
164
+ expect(settable.domain).to eq(domain)
165
+ end
166
+
167
+ it 'caches domain as string' do
168
+ expect { env_hash[domain_key] = new_domain }
169
+ .not_to(change(settable, :domain))
170
+ end
171
+ end
172
+ end
173
+
174
+ context 'when defining cache false' do
175
+ let(:settings) { %i[secret] }
176
+ let(:options) { { prefix:, cached: false } }
177
+ let(:options_hash) { options }
178
+ let(:secret) { 'my_secret' }
179
+ let(:new_secret) { 'new_secret' }
180
+
181
+ after do
182
+ env_hash.delete(secret_key)
183
+ end
184
+
185
+ context 'when the key is not set' do
186
+ it 'retrieves secret and cast to string' do
187
+ expect(settable.secret).to be_nil
188
+ end
189
+
190
+ it 'does not caches secret as nil' do
191
+ expect { env_hash[secret_key] = new_secret.to_s }
192
+ .to change(settable, :secret)
193
+ .from(nil).to(new_secret)
194
+ end
195
+ end
196
+
197
+ context 'when the key is set' do
198
+ before do
199
+ env_hash[secret_key] = secret.to_s
200
+ end
201
+
202
+ it 'retrieves secret and cast to string' do
203
+ expect(settable.secret).to eq(secret)
204
+ end
205
+
206
+ it 'does not caches secret' do
207
+ expect { env_hash[secret_key] = new_secret }
208
+ .to change(settable, :secret)
209
+ .from(secret).to(new_secret)
210
+ end
84
211
  end
85
212
  end
86
213
  end
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: 3.0.0
4
+ version: 3.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: 2025-05-09 00:00:00.000000000 Z
11
+ date: 2026-03-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -32,6 +32,8 @@ extensions: []
32
32
  extra_rdoc_files: []
33
33
  files:
34
34
  - ".circleci/config.yml"
35
+ - ".github/copilot-instructions.md"
36
+ - ".github/sinclair-usage.md"
35
37
  - ".gitignore"
36
38
  - ".rspec"
37
39
  - ".rubocop.yml"
@@ -109,7 +111,7 @@ files:
109
111
  - lib/sinclair/settable/class_methods.rb
110
112
  - lib/sinclair/version.rb
111
113
  - sinclair.gemspec
112
- - sinclair.jpg
114
+ - sinclair.png
113
115
  - spec/integration/readme/my_class_spec.rb
114
116
  - spec/integration/readme/my_model_spec.rb
115
117
  - spec/integration/readme/sinclair/comparable_spec.rb
@@ -198,6 +200,7 @@ files:
198
200
  - spec/lib/sinclair/options_parser_spec.rb
199
201
  - spec/lib/sinclair/options_spec.rb
200
202
  - spec/lib/sinclair/settable/builder_spec.rb
203
+ - spec/lib/sinclair/settable/caster_spec.rb
201
204
  - spec/lib/sinclair/settable_spec.rb
202
205
  - spec/lib/sinclair_spec.rb
203
206
  - spec/spec_helper.rb
data/sinclair.jpg DELETED
Binary file