sinclair 1.7.0 → 1.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +8 -1
- data/lib/sinclair/config.rb +7 -7
- data/lib/sinclair/config_class.rb +1 -1
- data/lib/sinclair/configurable.rb +7 -7
- data/lib/sinclair/matchers/change_class_method_on.rb +2 -2
- data/lib/sinclair/options/class_methods.rb +1 -1
- data/lib/sinclair/version.rb +1 -1
- data/spec/integration/readme/sinclair/configurable_spec.rb +11 -1
- data/spec/integration/yard/sinclair/config_spec.rb +3 -3
- data/spec/lib/sinclair/config_spec.rb +24 -10
- data/spec/support/shared_examples/config.rb +55 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0c06e4b7038a22a311b6ee13f1b8fd2df24211d8953982035df626dba8fb66c5
|
4
|
+
data.tar.gz: b19227562faa97bca59e76d997998917068ccb2d230a0b90dfa76140f2032209
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 87daf64f9e084ef37bb47efee4fb6ff174e70cfdf5005e506acdff45647fd4ad502b348b23c6a3bbb1cce09676c14d7be52cc816b493fdbb4c92d23b94b33ecf
|
7
|
+
data.tar.gz: 3d02e09271942cd50dc21eb9e9578b63db0374196e084b3ce9b54e3d816206731a88f8cb470581d791ecaf5a0f7a5435d2489ecf7465fa446b56d8f8c8b6dd24
|
data/README.md
CHANGED
@@ -15,7 +15,7 @@ methods
|
|
15
15
|
|
16
16
|
Yard Documentation
|
17
17
|
-------------------
|
18
|
-
[https://www.rubydoc.info/gems/sinclair/1.
|
18
|
+
[https://www.rubydoc.info/gems/sinclair/1.8.0](https://www.rubydoc.info/gems/sinclair/1.8.0)
|
19
19
|
|
20
20
|
Installation
|
21
21
|
---------------
|
@@ -369,6 +369,12 @@ hash
|
|
369
369
|
MyConfigurable.config.host # returns 'interstella.art'
|
370
370
|
MyConfigurable.config.port # returns 5555
|
371
371
|
|
372
|
+
# Configurable enables options that can be passed
|
373
|
+
MyConfigurable.as_options.host # returns 'interstella.art'
|
374
|
+
|
375
|
+
# Configurable enables options that can be passed with custom values
|
376
|
+
MyConfigurable.as_options(host: 'other').host # returns 'other'
|
377
|
+
|
372
378
|
MyConfigurable.reset_config
|
373
379
|
|
374
380
|
MyConfigurable.config.host # returns nil
|
@@ -553,3 +559,4 @@ Projects Using
|
|
553
559
|
|
554
560
|
- [Arstotzka](https://github.com/darthjee/arstotzka)
|
555
561
|
- [Azeroth](https://github.com/darthjee/azeroth)
|
562
|
+
- [Magicka](https://github.com/darthjee/magicka)
|
data/lib/sinclair/config.rb
CHANGED
@@ -63,10 +63,10 @@ class Sinclair
|
|
63
63
|
# conf.password :some_password
|
64
64
|
# end
|
65
65
|
#
|
66
|
-
# options = LoginConfigurable.config.
|
66
|
+
# options = LoginConfigurable.config.as_options
|
67
67
|
#
|
68
|
-
# config.
|
69
|
-
# config.
|
68
|
+
# config.as_options.username # returns :some_username
|
69
|
+
# config.as_options.password # returns :some_password
|
70
70
|
#
|
71
71
|
# @example returning custom options
|
72
72
|
# LoginConfigurable.configure do |conf|
|
@@ -74,13 +74,13 @@ class Sinclair
|
|
74
74
|
# conf.password :some_password
|
75
75
|
# end
|
76
76
|
#
|
77
|
-
# options = LoginConfigurable.config.
|
77
|
+
# options = LoginConfigurable.config.as_options(
|
78
78
|
# password: :correct_password
|
79
79
|
# )
|
80
80
|
#
|
81
|
-
# config.
|
82
|
-
# config.
|
83
|
-
def
|
81
|
+
# config.as_options.username # returns :some_username
|
82
|
+
# config.as_options.password # returns :correct_password
|
83
|
+
def as_options(options_hash = {})
|
84
84
|
self.class.options_class.new(to_hash.merge(options_hash))
|
85
85
|
end
|
86
86
|
end
|
@@ -9,8 +9,8 @@ class Sinclair
|
|
9
9
|
# By extending Configurable, class receives the methods public
|
10
10
|
# {ConfigFactory#config .config}, {ConfigFactory#reset_config .reset_config}
|
11
11
|
# and {ConfigFactory#configure .configure}
|
12
|
-
# and the private methods {#configurable_with .configurable_with}
|
13
|
-
#
|
12
|
+
# and the private methods {#configurable_with .configurable_with},
|
13
|
+
# {#configurable_by .configurable_by} and {#as_options .as_options}
|
14
14
|
#
|
15
15
|
# @see ConfigFactory
|
16
16
|
# @see ConfigBuilder
|
@@ -78,13 +78,13 @@ class Sinclair
|
|
78
78
|
# @see ConfigFactory#configure
|
79
79
|
delegate :config, :reset_config, :configure, to: :config_factory
|
80
80
|
|
81
|
-
# @method
|
81
|
+
# @method as_options(options_hash = {})
|
82
82
|
# @api public
|
83
83
|
#
|
84
|
-
# @param (see Sinclair::Config#
|
85
|
-
# @return (see Sinclair::Config#
|
86
|
-
# @example (see Sinclair::Config#
|
87
|
-
delegate :
|
84
|
+
# @param (see Sinclair::Config#as_options)
|
85
|
+
# @return (see Sinclair::Config#as_options)
|
86
|
+
# @example (see Sinclair::Config#as_options)
|
87
|
+
delegate :as_options, to: :config
|
88
88
|
|
89
89
|
protected
|
90
90
|
|
@@ -11,10 +11,10 @@ class Sinclair
|
|
11
11
|
# This is used with a RSpec DSL method
|
12
12
|
# change_class_method(method_name).on(class_object)
|
13
13
|
class ChangeClassMethodOn < ChangeMethodOn
|
14
|
-
# @param [Class]
|
14
|
+
# @param target [Class]
|
15
15
|
# Class where the class method should be added to
|
16
16
|
#
|
17
|
-
# @param method_name [
|
17
|
+
# @param method_name [Symbol,String] method name
|
18
18
|
def initialize(target, method_name)
|
19
19
|
@klass = target
|
20
20
|
super(method_name)
|
data/lib/sinclair/version.rb
CHANGED
@@ -25,7 +25,17 @@ describe Sinclair::Configurable do
|
|
25
25
|
.to eq(5555)
|
26
26
|
end
|
27
27
|
|
28
|
-
|
28
|
+
it 'enables options to be returned' do
|
29
|
+
expect(MyConfigurable.as_options.host)
|
30
|
+
.to eq('interstella.art')
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'enables custom options to be returned' do
|
34
|
+
expect(MyConfigurable.as_options(host: 'other').host)
|
35
|
+
.to eq('other')
|
36
|
+
end
|
37
|
+
|
38
|
+
context 'when #reset_config is called' do
|
29
39
|
before do
|
30
40
|
MyConfigurable.reset_config
|
31
41
|
end
|
@@ -38,12 +38,12 @@ describe Sinclair::Config do
|
|
38
38
|
end
|
39
39
|
|
40
40
|
it 'returns options with correct values' do
|
41
|
-
expect(config.
|
42
|
-
expect(config.
|
41
|
+
expect(config.as_options.username).to eq(:some_username)
|
42
|
+
expect(config.as_options.password).to eq(:some_password)
|
43
43
|
end
|
44
44
|
|
45
45
|
context 'when merging with given attributes' do
|
46
|
-
subject(:options) { config.
|
46
|
+
subject(:options) { config.as_options(password: :correct_password) }
|
47
47
|
|
48
48
|
it 'returns options with custom values' do
|
49
49
|
expect(options.username).to eq(:some_username)
|
@@ -109,29 +109,29 @@ describe Sinclair::Config do
|
|
109
109
|
end
|
110
110
|
end
|
111
111
|
|
112
|
-
describe '#
|
112
|
+
describe '#as_options' do
|
113
113
|
let(:expected_options) do
|
114
114
|
klass.options_class.new(username: :user, password: nil)
|
115
115
|
end
|
116
116
|
|
117
|
+
let(:builder) do
|
118
|
+
Sinclair::ConfigBuilder.new(config, :username, :password)
|
119
|
+
end
|
120
|
+
|
117
121
|
before do
|
118
122
|
klass.add_configs(:password, username: :user)
|
119
123
|
end
|
120
124
|
|
121
125
|
it do
|
122
|
-
expect(config.
|
126
|
+
expect(config.as_options).to be_a(Sinclair::Options)
|
123
127
|
end
|
124
128
|
|
125
129
|
it 'returns an option with default values' do
|
126
|
-
expect(config.
|
130
|
+
expect(config.as_options)
|
127
131
|
.to eq(expected_options)
|
128
132
|
end
|
129
133
|
|
130
134
|
context 'when config has been changed' do
|
131
|
-
let(:builder) do
|
132
|
-
Sinclair::ConfigBuilder.new(config, :username, :password)
|
133
|
-
end
|
134
|
-
|
135
135
|
let(:expected_options) do
|
136
136
|
klass.options_class.new(
|
137
137
|
username: :other_user, password: :some_password
|
@@ -144,7 +144,7 @@ describe Sinclair::Config do
|
|
144
144
|
end
|
145
145
|
|
146
146
|
it 'returns an option with values from config' do
|
147
|
-
expect(config.
|
147
|
+
expect(config.as_options)
|
148
148
|
.to eq(expected_options)
|
149
149
|
end
|
150
150
|
end
|
@@ -157,7 +157,7 @@ describe Sinclair::Config do
|
|
157
157
|
end
|
158
158
|
|
159
159
|
it 'returns merged options' do
|
160
|
-
expect(config.
|
160
|
+
expect(config.as_options(password: :some_password))
|
161
161
|
.to eq(expected_options)
|
162
162
|
end
|
163
163
|
end
|
@@ -170,9 +170,23 @@ describe Sinclair::Config do
|
|
170
170
|
end
|
171
171
|
|
172
172
|
it 'returns merged options' do
|
173
|
-
expect(config.
|
173
|
+
expect(config.as_options('password' => :some_password))
|
174
174
|
.to eq(expected_options)
|
175
175
|
end
|
176
|
+
|
177
|
+
context 'when the config is changed' do
|
178
|
+
let(:options) { config.as_options }
|
179
|
+
|
180
|
+
it 'changes the option returned' do
|
181
|
+
expect { builder.username :other_user }
|
182
|
+
.to change { config.as_options.username }
|
183
|
+
end
|
184
|
+
|
185
|
+
it 'changes the option previously returned' do
|
186
|
+
expect { builder.username :other_user }
|
187
|
+
.not_to change(options, :username)
|
188
|
+
end
|
189
|
+
end
|
176
190
|
end
|
177
191
|
end
|
178
192
|
end
|
@@ -161,5 +161,60 @@ shared_examples 'a config class with .add_configs method' do
|
|
161
161
|
.to(klass.options_class)
|
162
162
|
end
|
163
163
|
end
|
164
|
+
|
165
|
+
context 'when there is a child class' do
|
166
|
+
let(:code_block) { proc { klass.add_configs(name: 'Bob') } }
|
167
|
+
|
168
|
+
it 'adds attributes to child class' do
|
169
|
+
expect(&code_block)
|
170
|
+
.to change(child_klass, :config_attributes)
|
171
|
+
.from([]).to(%i[name])
|
172
|
+
end
|
173
|
+
|
174
|
+
it 'adds attributes to child options class' do
|
175
|
+
expect(&code_block)
|
176
|
+
.to add_method(:name).to(child_klass)
|
177
|
+
end
|
178
|
+
|
179
|
+
context 'when child class already has attributes' do
|
180
|
+
before do
|
181
|
+
child_klass.add_configs('email')
|
182
|
+
end
|
183
|
+
|
184
|
+
it 'adds new attributes to child class' do
|
185
|
+
expect(&code_block)
|
186
|
+
.to change(child_klass, :config_attributes)
|
187
|
+
.from([:email]).to(%i[name email])
|
188
|
+
end
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
context 'when there is a parent class' do
|
193
|
+
let(:code_block) do
|
194
|
+
proc { child_klass.add_configs(name: 'Bob') }
|
195
|
+
end
|
196
|
+
|
197
|
+
it 'does not add attributes to parent class' do
|
198
|
+
expect(&code_block)
|
199
|
+
.not_to change(klass, :config_attributes)
|
200
|
+
end
|
201
|
+
|
202
|
+
it 'does not add attributes to child options class' do
|
203
|
+
expect(&code_block)
|
204
|
+
.not_to add_method(:name).to(klass)
|
205
|
+
end
|
206
|
+
|
207
|
+
context 'when parent already has attributes' do
|
208
|
+
before do
|
209
|
+
klass.config_attributes(:email, 'username')
|
210
|
+
end
|
211
|
+
|
212
|
+
it 'adds only attributes that had not been defined before' do
|
213
|
+
expect(&code_block)
|
214
|
+
.to change(child_klass, :config_attributes)
|
215
|
+
.from(%i[email username]).to(%i[email username name])
|
216
|
+
end
|
217
|
+
end
|
218
|
+
end
|
164
219
|
end
|
165
220
|
end
|