sinclair 1.7.0 → 1.8.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4e9a5068ba9c9c0f3def716decd2cea72fbdea0e6a3255d2bd0d324462de4ef5
4
- data.tar.gz: c067ae53d0320738e785675306dc7f8848851a3adb964217bd30593c15eaedbf
3
+ metadata.gz: 0c06e4b7038a22a311b6ee13f1b8fd2df24211d8953982035df626dba8fb66c5
4
+ data.tar.gz: b19227562faa97bca59e76d997998917068ccb2d230a0b90dfa76140f2032209
5
5
  SHA512:
6
- metadata.gz: ddc575979d46b47983aa57083243e674ac1da951e1e8407b98ee188a17e60e7683d5a73ad829914e34d076764970fb93484f9da67b767a89b301f47d081aad47
7
- data.tar.gz: 0052e1e9b9e86758cf2b35c215509d6d4946b5e8bd0fde994b2e8121b83807de04d8c4e84d3fa3ee47565e4a07f89313f0ef871d6156f93ebdd7e6c8df0a83c5
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.7.0](https://www.rubydoc.info/gems/sinclair/1.7.0)
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)
@@ -63,10 +63,10 @@ class Sinclair
63
63
  # conf.password :some_password
64
64
  # end
65
65
  #
66
- # options = LoginConfigurable.config.options
66
+ # options = LoginConfigurable.config.as_options
67
67
  #
68
- # config.options.username # returns :some_username
69
- # config.options.password # returns :some_password
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.options(
77
+ # options = LoginConfigurable.config.as_options(
78
78
  # password: :correct_password
79
79
  # )
80
80
  #
81
- # config.options.username # returns :some_username
82
- # config.options.password # returns :correct_password
83
- def options(options_hash = {})
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
@@ -105,7 +105,7 @@ class Sinclair
105
105
  #
106
106
  # @return [Class<Sinclair::Options>]
107
107
  def options_class
108
- @options_class ||= Class.new(Sinclair::Options)
108
+ @options_class ||= Class.new(superclass.try(:options_class) || Options)
109
109
  end
110
110
  end
111
111
  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
- # and {#configurable_by .configurable_by}
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 options(options_hash = {})
81
+ # @method as_options(options_hash = {})
82
82
  # @api public
83
83
  #
84
- # @param (see Sinclair::Config#options)
85
- # @return (see Sinclair::Config#options)
86
- # @example (see Sinclair::Config#options)
87
- delegate :options, to: :config
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] klass
14
+ # @param target [Class]
15
15
  # Class where the class method should be added to
16
16
  #
17
- # @param method_name [SYmbol,String] 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)
@@ -4,7 +4,7 @@ require 'set'
4
4
 
5
5
  class Sinclair
6
6
  class Options
7
- # Class Methods for {Sinclai::Options}
7
+ # Class Methods for {Sinclair::Options}
8
8
  module ClassMethods
9
9
  # @api private
10
10
  #
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Sinclair
4
- VERSION = '1.7.0'
4
+ VERSION = '1.8.0'
5
5
  end
@@ -25,7 +25,17 @@ describe Sinclair::Configurable do
25
25
  .to eq(5555)
26
26
  end
27
27
 
28
- context 'when #rest_config is called' do
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.options.username).to eq(:some_username)
42
- expect(config.options.password).to eq(:some_password)
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.options(password: :correct_password) }
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 '#options' do
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.options).to be_a(Sinclair::Options)
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.options)
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.options)
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.options(password: :some_password))
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.options('password' => :some_password))
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sinclair
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.0
4
+ version: 1.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - DarthJee