sinclair 1.5.2 → 1.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +1 -1
- data/.rubocop.yml +9 -0
- data/.rubocop_todo.yml +1 -1
- data/Dockerfile +7 -16
- data/README.md +14 -14
- data/lib/sinclair.rb +3 -1
- data/lib/sinclair/exception.rb +46 -0
- data/lib/sinclair/options.rb +45 -0
- data/lib/sinclair/options/builder.rb +27 -0
- data/lib/sinclair/version.rb +1 -1
- data/sinclair.gemspec +13 -13
- data/spec/integration/readme/sinclair/matchers_spec.rb +0 -2
- data/spec/lib/sinclair/config_factory_spec.rb +6 -0
- data/spec/lib/sinclair/configurable_spec.rb +5 -2
- data/spec/lib/sinclair/exception/invalid_options_spec.rb +16 -0
- data/spec/lib/sinclair/method_builder_spec.rb +3 -3
- data/spec/lib/sinclair/method_definitions_spec.rb +1 -1
- data/spec/lib/sinclair/options_spec.rb +87 -0
- data/spec/support/models/connection_options.rb +5 -0
- metadata +34 -28
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6f1f053534fe80318f1a84b287fc624a243f70d5b5c48d6a8b36c256fcd37268
|
4
|
+
data.tar.gz: 2ecaef88cfe979d42ab08000c416cad6554983c57305b74603cb349d24bada41
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8bd3befeca69e2c7bd4f2edf93adc6688f810d5691c7c25fa574ee26337f8ad9a52a16abe194382f961774db53babc5859699c4178e9f54fb428cbaf168a5f30
|
7
|
+
data.tar.gz: 2ab928115bb31bc0214b2238accdb76033bb2a4baf974e19cbcdb60929aa0baab42dc6d1ae583e3975688443142c4c0ed705915f44c12051ab0516d05fa408ac
|
data/.circleci/config.yml
CHANGED
data/.rubocop.yml
CHANGED
data/.rubocop_todo.yml
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# This configuration was generated by
|
2
2
|
# `rubocop --auto-gen-config`
|
3
|
-
# on
|
3
|
+
# on 2020-04-27 21:26:53 +0000 using RuboCop version 0.80.1.
|
4
4
|
# The point is for the user to remove these configuration records
|
5
5
|
# one by one as the offenses are removed from the code base.
|
6
6
|
# Note that changes in the inspected code, or installation of new
|
data/Dockerfile
CHANGED
@@ -1,12 +1,14 @@
|
|
1
|
-
FROM darthjee/
|
2
|
-
|
1
|
+
FROM darthjee/scripts:0.1.7 as scripts
|
2
|
+
|
3
|
+
FROM darthjee/ruby_gems:0.5.0 as base
|
4
|
+
|
5
|
+
COPY --chown=app:app ./ /home/app/app/
|
3
6
|
|
4
7
|
######################################
|
5
8
|
|
6
9
|
FROM base as builder
|
7
10
|
|
8
|
-
COPY --chown=app
|
9
|
-
COPY --chown=app:app --from=scripts /home/scripts/builder/bundle_builder.sh /usr/local/sbin/
|
11
|
+
COPY --chown=app:app --from=scripts /home/scripts/builder/bundle_builder.sh /usr/local/sbin/bundle_builder.sh
|
10
12
|
|
11
13
|
ENV HOME_DIR /home/app
|
12
14
|
RUN bundle_builder.sh
|
@@ -14,17 +16,6 @@ RUN bundle_builder.sh
|
|
14
16
|
#######################
|
15
17
|
#FINAL IMAGE
|
16
18
|
FROM base
|
17
|
-
RUN mkdir lib/sinclair -p
|
18
|
-
|
19
|
-
USER root
|
20
|
-
|
21
|
-
COPY --chown=app:app --from=builder /home/app/bundle/gems /usr/local/bundle/gems
|
22
|
-
COPY --chown=app:app --from=builder /home/app/bundle/cache /usr/local/bundle/cache
|
23
|
-
COPY --chown=app:app --from=builder /home/app/bundle/specifications /usr/local/bundle/specifications
|
24
|
-
COPY --chown=app:app --from=builder /home/app/bundle/bin /usr/local/bundle/bin
|
25
|
-
COPY --chown=app:app --from=builder /home/app/bundle/extensions /usr/local/bundle/extensions
|
26
19
|
|
27
|
-
COPY --chown=app
|
28
|
-
COPY --chown=app ./lib/sinclair/version.rb /home/app/app/lib/sinclair/
|
29
|
-
USER app
|
20
|
+
COPY --chown=app:app --from=builder /home/app/bundle/ /usr/local/bundle/
|
30
21
|
RUN bundle install
|
data/README.md
CHANGED
@@ -4,7 +4,8 @@ Sinclair
|
|
4
4
|
[![Test Coverage](https://codeclimate.com/github/darthjee/sinclair/badges/coverage.svg)](https://codeclimate.com/github/darthjee/sinclair/coverage)
|
5
5
|
[![Issue Count](https://codeclimate.com/github/darthjee/sinclair/badges/issue_count.svg)](https://codeclimate.com/github/darthjee/sinclair)
|
6
6
|
[![Gem Version](https://badge.fury.io/rb/sinclair.svg)](https://badge.fury.io/rb/sinclair)
|
7
|
-
|
7
|
+
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/9836de08612e46b889c7978be2b72a14)](https://www.codacy.com/manual/darthjee/sinclair?utm_source=github.com&utm_medium=referral&utm_content=darthjee/sinclair&utm_campaign=Badge_Grade)
|
8
|
+
[![Inline docs](http://inch-ci.org/github/darthjee/sinclair.svg?branch=master)](http://inch-ci.org/github/darthjee/sinclair)
|
8
9
|
|
9
10
|
![sinclair](https://raw.githubusercontent.com/darthjee/sinclair/master/sinclair.jpg)
|
10
11
|
|
@@ -14,17 +15,18 @@ methods
|
|
14
15
|
|
15
16
|
Yard Documentation
|
16
17
|
-------------------
|
17
|
-
https://www.rubydoc.info/gems/sinclair/1.
|
18
|
+
[https://www.rubydoc.info/gems/sinclair/1.6.0](https://www.rubydoc.info/gems/sinclair/1.6.0)
|
18
19
|
|
19
20
|
Installation
|
20
21
|
---------------
|
21
|
-
|
22
|
+
|
23
|
+
- Install it
|
22
24
|
|
23
25
|
```ruby
|
24
26
|
gem install sinclair
|
25
27
|
```
|
26
28
|
|
27
|
-
|
29
|
+
- Or add Sinclair to your `Gemfile` and `bundle install`:
|
28
30
|
|
29
31
|
```ruby
|
30
32
|
gem 'sinclair'
|
@@ -36,13 +38,12 @@ Installation
|
|
36
38
|
|
37
39
|
Usage
|
38
40
|
---------------
|
39
|
-
|
41
|
+
### Sinclair builder
|
40
42
|
Sinclair can actually be used in several ways, as a stand alone object capable of
|
41
43
|
adding methods to your class on the fly, as a builder inside a class method
|
42
44
|
or by extending it for more complex logics
|
43
45
|
|
44
|
-
|
45
|
-
|
46
|
+
#### Stand Alone usage creating methods on the fly
|
46
47
|
```ruby
|
47
48
|
|
48
49
|
class Clazz
|
@@ -65,7 +66,7 @@ or by extending it for more complex logics
|
|
65
66
|
puts "One Hundred => #{Clazz.one_hundred_twenty}" # One Hundred Twenty => 120
|
66
67
|
```
|
67
68
|
|
68
|
-
|
69
|
+
#### Builder in class method
|
69
70
|
|
70
71
|
```ruby
|
71
72
|
class HttpJsonModel
|
@@ -162,7 +163,7 @@ or by extending it for more complex logics
|
|
162
163
|
MyServerConfig.port # returns '9090'
|
163
164
|
```
|
164
165
|
|
165
|
-
|
166
|
+
#### Extending the builder
|
166
167
|
|
167
168
|
```ruby
|
168
169
|
|
@@ -255,7 +256,7 @@ or by extending it for more complex logics
|
|
255
256
|
invalid_object.valid? # returns false
|
256
257
|
```
|
257
258
|
|
258
|
-
|
259
|
+
#### Caching the result
|
259
260
|
If wanted, the result of the method can be stored in an
|
260
261
|
instance variable with the same name.
|
261
262
|
|
@@ -344,7 +345,7 @@ values are cached
|
|
344
345
|
server.url # return 'http://server.com'
|
345
346
|
```
|
346
347
|
|
347
|
-
|
348
|
+
### Sinclair::Configurable
|
348
349
|
|
349
350
|
Configurable is a module that, when used, can add configurations
|
350
351
|
to your classes/modules.
|
@@ -408,7 +409,7 @@ Configurations can also be done through custom classes
|
|
408
409
|
Client.config.url # returns 'http://interstella.com:8080'
|
409
410
|
```
|
410
411
|
|
411
|
-
|
412
|
+
### Sinclair::Settable
|
412
413
|
|
413
414
|
Settable allows classes to extract configuration from environments through
|
414
415
|
a simple meta-programable way
|
@@ -527,5 +528,4 @@ Sinclair::Matchers
|
|
527
528
|
Projects Using
|
528
529
|
---------------
|
529
530
|
|
530
|
-
-
|
531
|
-
|
531
|
+
- [Arstotzka](https://github.com/darthjee/arstotzka)
|
data/lib/sinclair.rb
CHANGED
@@ -88,10 +88,12 @@ class Sinclair
|
|
88
88
|
autoload :ConfigClass, 'sinclair/config_class'
|
89
89
|
autoload :ConfigFactory, 'sinclair/config_factory'
|
90
90
|
autoload :Configurable, 'sinclair/configurable'
|
91
|
+
autoload :EnvSettable, 'sinclair/env_settable'
|
92
|
+
autoload :Exception, 'sinclair/exception'
|
91
93
|
autoload :MethodBuilder, 'sinclair/method_builder'
|
92
94
|
autoload :MethodDefinition, 'sinclair/method_definition'
|
93
95
|
autoload :MethodDefinitions, 'sinclair/method_definitions'
|
94
|
-
autoload :
|
96
|
+
autoload :Options, 'sinclair/options'
|
95
97
|
|
96
98
|
include OptionsParser
|
97
99
|
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Sinclair
|
4
|
+
# @api private
|
5
|
+
# @author Darthjee
|
6
|
+
#
|
7
|
+
# Excaptions raised by sinclair
|
8
|
+
class Exception < StandardError
|
9
|
+
# @api private
|
10
|
+
# @author Darthjee
|
11
|
+
#
|
12
|
+
# Exception raised when invalid options are given
|
13
|
+
#
|
14
|
+
# @example Usage
|
15
|
+
# exception = Sinclair::Exception::InvalidOptions.new(%i[invalid options])
|
16
|
+
# exception.message
|
17
|
+
# # return 'Invalid keys on options initialization (invalid options)'
|
18
|
+
class InvalidOptions < Sinclair::Exception
|
19
|
+
# @param invalid_keys [Array<Symbol>] list of invalid keys
|
20
|
+
def initialize(invalid_keys = [])
|
21
|
+
@invalid_keys = invalid_keys
|
22
|
+
end
|
23
|
+
|
24
|
+
# Exception string showing invalid keys
|
25
|
+
#
|
26
|
+
# @return [String]
|
27
|
+
#
|
28
|
+
# @example (see InvalidOptions)
|
29
|
+
def message
|
30
|
+
keys = invalid_keys.join(' ')
|
31
|
+
"Invalid keys on options initialization (#{keys})"
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
attr_reader :invalid_keys
|
37
|
+
# @method invalid_keys
|
38
|
+
# @api private
|
39
|
+
# @private
|
40
|
+
#
|
41
|
+
# invalid keys on options initialization
|
42
|
+
#
|
43
|
+
# @return [Array<Symbol>]
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Sinclair
|
4
|
+
class Options
|
5
|
+
autoload :Builder, 'sinclair/options/builder'
|
6
|
+
|
7
|
+
class << self
|
8
|
+
def options
|
9
|
+
@options ||= []
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def with_options(*options)
|
15
|
+
Builder.new(self, *options).build
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
# @param options [Hash] hash with options (see {.options}, {.with_options})
|
20
|
+
def initialize(options = {})
|
21
|
+
check_options(options)
|
22
|
+
|
23
|
+
options.each do |key, value|
|
24
|
+
instance_variable_set("@#{key}", value)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
# @private
|
31
|
+
#
|
32
|
+
# check if given options are allowed
|
33
|
+
#
|
34
|
+
# @raise Sinclair::Exception::InvalidOptions
|
35
|
+
#
|
36
|
+
# @return [NilClass]
|
37
|
+
def check_options(options)
|
38
|
+
invalid_keys = options.keys - self.class.options
|
39
|
+
|
40
|
+
return if invalid_keys.empty?
|
41
|
+
|
42
|
+
raise Sinclair::Exception::InvalidOptions, invalid_keys
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Sinclair
|
4
|
+
class Options
|
5
|
+
class Builder < Sinclair
|
6
|
+
def initialize(klass, *options, **defaults)
|
7
|
+
super(klass)
|
8
|
+
|
9
|
+
@attributes = Hash[options.map { |name| [name] }]
|
10
|
+
@attributes.merge!(defaults)
|
11
|
+
|
12
|
+
add_all_methods
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
attr_reader :attributes
|
18
|
+
|
19
|
+
def add_all_methods
|
20
|
+
attributes.each do |option, value|
|
21
|
+
add_method(option, cached: true) { value }
|
22
|
+
klass.options.push(option)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/lib/sinclair/version.rb
CHANGED
data/sinclair.gemspec
CHANGED
@@ -21,20 +21,20 @@ Gem::Specification.new do |gem|
|
|
21
21
|
|
22
22
|
gem.add_runtime_dependency 'activesupport', '~> 5.2.0'
|
23
23
|
|
24
|
-
gem.add_development_dependency 'bundler', '
|
24
|
+
gem.add_development_dependency 'bundler', '1.16.1'
|
25
25
|
gem.add_development_dependency 'pry', '0.12.2'
|
26
26
|
gem.add_development_dependency 'pry-nav', '0.3.0'
|
27
|
-
gem.add_development_dependency 'rake', '
|
28
|
-
gem.add_development_dependency 'reek', '5.
|
29
|
-
gem.add_development_dependency 'rspec', '3.
|
30
|
-
gem.add_development_dependency 'rspec-core', '3.
|
31
|
-
gem.add_development_dependency 'rspec-expectations', '3.
|
32
|
-
gem.add_development_dependency 'rspec-mocks', '3.
|
33
|
-
gem.add_development_dependency 'rspec-support', '3.
|
34
|
-
gem.add_development_dependency 'rubocop', '0.
|
35
|
-
gem.add_development_dependency 'rubocop-rspec', '1.
|
36
|
-
gem.add_development_dependency 'rubycritic', '4.1
|
37
|
-
gem.add_development_dependency 'simplecov', '0.17.
|
38
|
-
gem.add_development_dependency 'yard', '0.9.
|
27
|
+
gem.add_development_dependency 'rake', '13.0.1'
|
28
|
+
gem.add_development_dependency 'reek', '5.6.0'
|
29
|
+
gem.add_development_dependency 'rspec', '3.9.0'
|
30
|
+
gem.add_development_dependency 'rspec-core', '3.9.1'
|
31
|
+
gem.add_development_dependency 'rspec-expectations', '3.9.1'
|
32
|
+
gem.add_development_dependency 'rspec-mocks', '3.9.1'
|
33
|
+
gem.add_development_dependency 'rspec-support', '3.9.2'
|
34
|
+
gem.add_development_dependency 'rubocop', '0.80.1'
|
35
|
+
gem.add_development_dependency 'rubocop-rspec', '1.38.1'
|
36
|
+
gem.add_development_dependency 'rubycritic', '4.4.1'
|
37
|
+
gem.add_development_dependency 'simplecov', '0.17.1'
|
38
|
+
gem.add_development_dependency 'yard', '0.9.24'
|
39
39
|
gem.add_development_dependency 'yardstick', '0.9.9'
|
40
40
|
end
|
@@ -58,12 +58,14 @@ describe Sinclair::ConfigFactory do
|
|
58
58
|
expect(factory.config).to be_a(DummyConfig)
|
59
59
|
end
|
60
60
|
|
61
|
+
# rubocop:disable RSpec/SubjectStub
|
61
62
|
it 'warns about class use' do
|
62
63
|
factory.config
|
63
64
|
|
64
65
|
expect(factory).to have_received(:warn)
|
65
66
|
.with described_class::CONFIG_CLASS_WARNING
|
66
67
|
end
|
68
|
+
# rubocop:enable RSpec/SubjectStub
|
67
69
|
|
68
70
|
context 'when calling after reset_config' do
|
69
71
|
before { factory.reset_config }
|
@@ -171,12 +173,14 @@ describe Sinclair::ConfigFactory do
|
|
171
173
|
expect(factory.config.name).to be_nil
|
172
174
|
end
|
173
175
|
|
176
|
+
# rubocop:disable RSpec/SubjectStub
|
174
177
|
it 'warns about class use' do
|
175
178
|
code_block.call
|
176
179
|
|
177
180
|
expect(factory).to have_received(:warn)
|
178
181
|
.with described_class::CONFIG_CLASS_WARNING
|
179
182
|
end
|
183
|
+
# rubocop:enable RSpec/SubjectStub
|
180
184
|
end
|
181
185
|
|
182
186
|
context 'when passing a hash' do
|
@@ -189,12 +193,14 @@ describe Sinclair::ConfigFactory do
|
|
189
193
|
expect(factory.config.name).to eq('Bobby')
|
190
194
|
end
|
191
195
|
|
196
|
+
# rubocop:disable RSpec/SubjectStub
|
192
197
|
it 'warns about class use' do
|
193
198
|
code_block.call
|
194
199
|
|
195
200
|
expect(factory).to have_received(:warn)
|
196
201
|
.with described_class::CONFIG_CLASS_WARNING
|
197
202
|
end
|
203
|
+
# rubocop:enable RSpec/SubjectStub
|
198
204
|
end
|
199
205
|
end
|
200
206
|
end
|
@@ -123,13 +123,13 @@ describe Sinclair::Configurable do
|
|
123
123
|
end
|
124
124
|
end
|
125
125
|
|
126
|
+
# rubocop:disable RSpec/SubjectStub
|
126
127
|
before do
|
127
|
-
# rubocop:disable RSpec/SubjectStub
|
128
128
|
allow(configurable)
|
129
129
|
.to receive(:warn)
|
130
130
|
.with(described_class::CONFIG_CLASS_WARNING)
|
131
|
-
# rubocop:enable RSpec/SubjectStub
|
132
131
|
end
|
132
|
+
# rubocop:enable RSpec/SubjectStub
|
133
133
|
|
134
134
|
it 'does not add symbol methods config object' do
|
135
135
|
expect(&block)
|
@@ -141,10 +141,12 @@ describe Sinclair::Configurable do
|
|
141
141
|
.not_to add_method(:port).to(configurable.config)
|
142
142
|
end
|
143
143
|
|
144
|
+
# rubocop:disable RSpec/SubjectStub
|
144
145
|
it 'sends deprecation warning' do
|
145
146
|
block.call
|
146
147
|
expect(configurable).to have_received(:warn)
|
147
148
|
end
|
149
|
+
# rubocop:enable RSpec/SubjectStub
|
148
150
|
|
149
151
|
it 'does not raises error on configuration of given symbol attributes' do
|
150
152
|
block.call
|
@@ -220,6 +222,7 @@ describe Sinclair::Configurable do
|
|
220
222
|
.to receive(:warn)
|
221
223
|
.with(described_class::CONFIG_CLASS_WARNING)
|
222
224
|
# rubocop:enable RSpec/SubjectStub
|
225
|
+
|
223
226
|
configurable.send(
|
224
227
|
:configurable_by, config_class, with: [:host, 'port']
|
225
228
|
)
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Sinclair::Exception::InvalidOptions do
|
6
|
+
describe '#message' do
|
7
|
+
let(:exception) { described_class.new(%i[invalid options]) }
|
8
|
+
let(:expected_message) do
|
9
|
+
'Invalid keys on options initialization (invalid options)'
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'shows invalid keys' do
|
13
|
+
expect(exception.message).to eq(expected_message)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -34,18 +34,18 @@ describe Sinclair::MethodBuilder do
|
|
34
34
|
end
|
35
35
|
|
36
36
|
context 'when building a class method' do
|
37
|
-
let(:type) { described_class::
|
37
|
+
let(:type) { described_class::CLASS_METHOD }
|
38
38
|
|
39
39
|
it do
|
40
40
|
expect { builder.build_methods(definitions, type) }
|
41
|
-
.to
|
41
|
+
.to add_class_method(method_name).to(klass)
|
42
42
|
end
|
43
43
|
|
44
44
|
context 'when the method is called' do
|
45
45
|
before { builder.build_methods(definitions, type) }
|
46
46
|
|
47
47
|
it do
|
48
|
-
expect(
|
48
|
+
expect(klass.the_method).to eq(value)
|
49
49
|
end
|
50
50
|
end
|
51
51
|
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Sinclair::Options do
|
6
|
+
subject(:options) { klass.new }
|
7
|
+
|
8
|
+
let(:klass) { Class.new(described_class) }
|
9
|
+
|
10
|
+
describe '.with_options' do
|
11
|
+
context 'when calling with keys' do
|
12
|
+
it 'add first method' do
|
13
|
+
expect { klass.send(:with_options, :timeout, :retries) }
|
14
|
+
.to add_method(:timeout).to(klass)
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'add second method' do
|
18
|
+
expect { klass.send(:with_options, :timeout, :retries) }
|
19
|
+
.to add_method(:retries).to(klass)
|
20
|
+
end
|
21
|
+
|
22
|
+
context 'when when calling method after building' do
|
23
|
+
before { klass.send(:with_options, :timeout, :retries) }
|
24
|
+
|
25
|
+
it { expect(options.timeout).to be_nil }
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context 'when calling with a hash' do
|
30
|
+
it 'adds method' do
|
31
|
+
expect { klass.send(:with_options, timeout: 10) }
|
32
|
+
.to add_method(:timeout).to(klass)
|
33
|
+
end
|
34
|
+
|
35
|
+
context 'when when calling method after building' do
|
36
|
+
before { klass.send(:with_options, timeout: 10) }
|
37
|
+
|
38
|
+
it { expect(options.timeout).not_to be_nil }
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe '#initialize' do
|
44
|
+
let(:klass) { ConnectionOptions }
|
45
|
+
|
46
|
+
context 'when initializing with no args' do
|
47
|
+
it do
|
48
|
+
expect { klass.new }.not_to raise_error
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'initializes methods with default values' do
|
52
|
+
expect(options.port).to eq(443)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
context 'when initializing with valid args' do
|
57
|
+
subject(:options) do
|
58
|
+
klass.new(timeout: timeout, protocol: 'http')
|
59
|
+
end
|
60
|
+
|
61
|
+
let(:timeout) { Random.rand(10..19) }
|
62
|
+
|
63
|
+
it 'sets value of options attribute' do
|
64
|
+
expect(options.timeout).to eq(timeout)
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'sets value of options attribute that has default' do
|
68
|
+
expect(options.protocol).to eq('http')
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'does not mess with non initialized attributes' do
|
72
|
+
expect(options.retries).to be_nil
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'does not mess with non initialized attributes with defaults' do
|
76
|
+
expect(options.port).to eq(443)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
context 'when initializing with invalid args' do
|
81
|
+
it do
|
82
|
+
expect { klass.new(invalid: 10) }
|
83
|
+
.to raise_error(Sinclair::Exception::InvalidOptions)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
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: 1.
|
4
|
+
version: 1.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- DarthJee
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-05-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -28,14 +28,14 @@ dependencies:
|
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - '='
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: 1.16.1
|
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
40
|
version: 1.16.1
|
41
41
|
- !ruby/object:Gem::Dependency
|
@@ -72,168 +72,168 @@ dependencies:
|
|
72
72
|
requirements:
|
73
73
|
- - '='
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
75
|
+
version: 13.0.1
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - '='
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
82
|
+
version: 13.0.1
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: reek
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
87
|
- - '='
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: 5.
|
89
|
+
version: 5.6.0
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - '='
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: 5.
|
96
|
+
version: 5.6.0
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: rspec
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
101
|
- - '='
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version: 3.
|
103
|
+
version: 3.9.0
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
108
|
- - '='
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version: 3.
|
110
|
+
version: 3.9.0
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
112
|
name: rspec-core
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
115
|
- - '='
|
116
116
|
- !ruby/object:Gem::Version
|
117
|
-
version: 3.
|
117
|
+
version: 3.9.1
|
118
118
|
type: :development
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
122
|
- - '='
|
123
123
|
- !ruby/object:Gem::Version
|
124
|
-
version: 3.
|
124
|
+
version: 3.9.1
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
126
|
name: rspec-expectations
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|
128
128
|
requirements:
|
129
129
|
- - '='
|
130
130
|
- !ruby/object:Gem::Version
|
131
|
-
version: 3.
|
131
|
+
version: 3.9.1
|
132
132
|
type: :development
|
133
133
|
prerelease: false
|
134
134
|
version_requirements: !ruby/object:Gem::Requirement
|
135
135
|
requirements:
|
136
136
|
- - '='
|
137
137
|
- !ruby/object:Gem::Version
|
138
|
-
version: 3.
|
138
|
+
version: 3.9.1
|
139
139
|
- !ruby/object:Gem::Dependency
|
140
140
|
name: rspec-mocks
|
141
141
|
requirement: !ruby/object:Gem::Requirement
|
142
142
|
requirements:
|
143
143
|
- - '='
|
144
144
|
- !ruby/object:Gem::Version
|
145
|
-
version: 3.
|
145
|
+
version: 3.9.1
|
146
146
|
type: :development
|
147
147
|
prerelease: false
|
148
148
|
version_requirements: !ruby/object:Gem::Requirement
|
149
149
|
requirements:
|
150
150
|
- - '='
|
151
151
|
- !ruby/object:Gem::Version
|
152
|
-
version: 3.
|
152
|
+
version: 3.9.1
|
153
153
|
- !ruby/object:Gem::Dependency
|
154
154
|
name: rspec-support
|
155
155
|
requirement: !ruby/object:Gem::Requirement
|
156
156
|
requirements:
|
157
157
|
- - '='
|
158
158
|
- !ruby/object:Gem::Version
|
159
|
-
version: 3.
|
159
|
+
version: 3.9.2
|
160
160
|
type: :development
|
161
161
|
prerelease: false
|
162
162
|
version_requirements: !ruby/object:Gem::Requirement
|
163
163
|
requirements:
|
164
164
|
- - '='
|
165
165
|
- !ruby/object:Gem::Version
|
166
|
-
version: 3.
|
166
|
+
version: 3.9.2
|
167
167
|
- !ruby/object:Gem::Dependency
|
168
168
|
name: rubocop
|
169
169
|
requirement: !ruby/object:Gem::Requirement
|
170
170
|
requirements:
|
171
171
|
- - '='
|
172
172
|
- !ruby/object:Gem::Version
|
173
|
-
version: 0.
|
173
|
+
version: 0.80.1
|
174
174
|
type: :development
|
175
175
|
prerelease: false
|
176
176
|
version_requirements: !ruby/object:Gem::Requirement
|
177
177
|
requirements:
|
178
178
|
- - '='
|
179
179
|
- !ruby/object:Gem::Version
|
180
|
-
version: 0.
|
180
|
+
version: 0.80.1
|
181
181
|
- !ruby/object:Gem::Dependency
|
182
182
|
name: rubocop-rspec
|
183
183
|
requirement: !ruby/object:Gem::Requirement
|
184
184
|
requirements:
|
185
185
|
- - '='
|
186
186
|
- !ruby/object:Gem::Version
|
187
|
-
version: 1.
|
187
|
+
version: 1.38.1
|
188
188
|
type: :development
|
189
189
|
prerelease: false
|
190
190
|
version_requirements: !ruby/object:Gem::Requirement
|
191
191
|
requirements:
|
192
192
|
- - '='
|
193
193
|
- !ruby/object:Gem::Version
|
194
|
-
version: 1.
|
194
|
+
version: 1.38.1
|
195
195
|
- !ruby/object:Gem::Dependency
|
196
196
|
name: rubycritic
|
197
197
|
requirement: !ruby/object:Gem::Requirement
|
198
198
|
requirements:
|
199
199
|
- - '='
|
200
200
|
- !ruby/object:Gem::Version
|
201
|
-
version: 4.1
|
201
|
+
version: 4.4.1
|
202
202
|
type: :development
|
203
203
|
prerelease: false
|
204
204
|
version_requirements: !ruby/object:Gem::Requirement
|
205
205
|
requirements:
|
206
206
|
- - '='
|
207
207
|
- !ruby/object:Gem::Version
|
208
|
-
version: 4.1
|
208
|
+
version: 4.4.1
|
209
209
|
- !ruby/object:Gem::Dependency
|
210
210
|
name: simplecov
|
211
211
|
requirement: !ruby/object:Gem::Requirement
|
212
212
|
requirements:
|
213
213
|
- - '='
|
214
214
|
- !ruby/object:Gem::Version
|
215
|
-
version: 0.17.
|
215
|
+
version: 0.17.1
|
216
216
|
type: :development
|
217
217
|
prerelease: false
|
218
218
|
version_requirements: !ruby/object:Gem::Requirement
|
219
219
|
requirements:
|
220
220
|
- - '='
|
221
221
|
- !ruby/object:Gem::Version
|
222
|
-
version: 0.17.
|
222
|
+
version: 0.17.1
|
223
223
|
- !ruby/object:Gem::Dependency
|
224
224
|
name: yard
|
225
225
|
requirement: !ruby/object:Gem::Requirement
|
226
226
|
requirements:
|
227
227
|
- - '='
|
228
228
|
- !ruby/object:Gem::Version
|
229
|
-
version: 0.9.
|
229
|
+
version: 0.9.24
|
230
230
|
type: :development
|
231
231
|
prerelease: false
|
232
232
|
version_requirements: !ruby/object:Gem::Requirement
|
233
233
|
requirements:
|
234
234
|
- - '='
|
235
235
|
- !ruby/object:Gem::Version
|
236
|
-
version: 0.9.
|
236
|
+
version: 0.9.24
|
237
237
|
- !ruby/object:Gem::Dependency
|
238
238
|
name: yardstick
|
239
239
|
requirement: !ruby/object:Gem::Requirement
|
@@ -280,6 +280,7 @@ files:
|
|
280
280
|
- lib/sinclair/configurable.rb
|
281
281
|
- lib/sinclair/env_settable.rb
|
282
282
|
- lib/sinclair/env_settable/builder.rb
|
283
|
+
- lib/sinclair/exception.rb
|
283
284
|
- lib/sinclair/matchers.rb
|
284
285
|
- lib/sinclair/matchers/add_class_method.rb
|
285
286
|
- lib/sinclair/matchers/add_class_method_to.rb
|
@@ -296,6 +297,8 @@ files:
|
|
296
297
|
- lib/sinclair/method_definition/block_helper.rb
|
297
298
|
- lib/sinclair/method_definition/string_definition.rb
|
298
299
|
- lib/sinclair/method_definitions.rb
|
300
|
+
- lib/sinclair/options.rb
|
301
|
+
- lib/sinclair/options/builder.rb
|
299
302
|
- lib/sinclair/options_parser.rb
|
300
303
|
- lib/sinclair/version.rb
|
301
304
|
- sinclair.gemspec
|
@@ -327,6 +330,7 @@ files:
|
|
327
330
|
- spec/lib/sinclair/configurable_spec.rb
|
328
331
|
- spec/lib/sinclair/env_settable/builder_spec.rb
|
329
332
|
- spec/lib/sinclair/env_settable_spec.rb
|
333
|
+
- spec/lib/sinclair/exception/invalid_options_spec.rb
|
330
334
|
- spec/lib/sinclair/matchers/add_class_method_spec.rb
|
331
335
|
- spec/lib/sinclair/matchers/add_class_method_to_spec.rb
|
332
336
|
- spec/lib/sinclair/matchers/add_instance_method_spec.rb
|
@@ -341,12 +345,14 @@ files:
|
|
341
345
|
- spec/lib/sinclair/method_definition_spec.rb
|
342
346
|
- spec/lib/sinclair/method_definitions_spec.rb
|
343
347
|
- spec/lib/sinclair/options_parser_spec.rb
|
348
|
+
- spec/lib/sinclair/options_spec.rb
|
344
349
|
- spec/lib/sinclair_spec.rb
|
345
350
|
- spec/spec_helper.rb
|
346
351
|
- spec/support/fixture_helpers.rb
|
347
352
|
- spec/support/models/app_client.rb
|
348
353
|
- spec/support/models/app_config.rb
|
349
354
|
- spec/support/models/client.rb
|
355
|
+
- spec/support/models/connection_options.rb
|
350
356
|
- spec/support/models/default_value.rb
|
351
357
|
- spec/support/models/default_value_builder.rb
|
352
358
|
- spec/support/models/default_valueable.rb
|