sinclair 2.1.1 → 3.0.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/.circleci/config.yml +3 -3
- data/.rubocop.yml +33 -1
- data/.rubocop_todo.yml +13 -1
- data/Dockerfile +2 -3
- data/Gemfile +17 -0
- data/Makefile +6 -0
- data/README.md +3 -3
- data/lib/sinclair/caster/class_methods.rb +6 -6
- data/lib/sinclair/chain_settable.rb +1 -1
- data/lib/sinclair/class_methods.rb +3 -3
- data/lib/sinclair/config_builder.rb +4 -4
- data/lib/sinclair/config_class.rb +3 -3
- data/lib/sinclair/config_factory.rb +7 -6
- data/lib/sinclair/configurable.rb +5 -5
- data/lib/sinclair/env_settable.rb +1 -1
- data/lib/sinclair/equals_checker.rb +1 -3
- data/lib/sinclair/exception.rb +1 -0
- data/lib/sinclair/input_hash.rb +3 -2
- data/lib/sinclair/matchers/add_class_method_to.rb +1 -1
- data/lib/sinclair/matchers/add_instance_method_to.rb +1 -1
- data/lib/sinclair/matchers/base.rb +2 -1
- data/lib/sinclair/matchers/change_class_method_on.rb +1 -1
- data/lib/sinclair/matchers/change_instance_method_on.rb +1 -1
- data/lib/sinclair/method_builder/base.rb +2 -1
- data/lib/sinclair/method_definition/block_helper.rb +4 -4
- data/lib/sinclair/method_definition/parameter_builder.rb +2 -2
- data/lib/sinclair/method_definition/parameter_helper.rb +2 -2
- data/lib/sinclair/method_definition.rb +8 -8
- data/lib/sinclair/method_definitions.rb +2 -2
- data/lib/sinclair/model/builder.rb +2 -2
- data/lib/sinclair/model.rb +4 -4
- data/lib/sinclair/options/class_methods.rb +0 -2
- data/lib/sinclair/options.rb +0 -2
- data/lib/sinclair/settable/builder.rb +1 -0
- data/lib/sinclair/settable.rb +1 -1
- data/lib/sinclair/version.rb +1 -1
- data/lib/sinclair.rb +6 -6
- data/sinclair.gemspec +3 -20
- data/spec/integration/readme/my_class_spec.rb +2 -2
- data/spec/integration/readme/sinclair/model_spec.rb +2 -2
- data/spec/integration/readme/sinclair/options_spec.rb +1 -1
- data/spec/integration/yard/sinclair/add_class_method_spec.rb +2 -2
- data/spec/integration/yard/sinclair/caster/cast_spec.rb +2 -2
- data/spec/integration/yard/sinclair/caster/cast_with_spec.rb +1 -1
- data/spec/integration/yard/sinclair/config_factory_spec.rb +4 -4
- data/spec/integration/yard/sinclair/core_ext/object_spec.rb +2 -2
- data/spec/lib/sinclair/chain_settable_spec.rb +1 -1
- data/spec/lib/sinclair/config_factory_spec.rb +1 -1
- data/spec/lib/sinclair/equals_checker/reader_spec.rb +1 -1
- data/spec/lib/sinclair/matchers/add_class_method_spec.rb +1 -1
- data/spec/lib/sinclair/matchers/add_class_method_to_spec.rb +1 -1
- data/spec/lib/sinclair/matchers/add_instance_method_spec.rb +1 -1
- data/spec/lib/sinclair/matchers/add_instance_method_to_spec.rb +1 -1
- data/spec/lib/sinclair/matchers/change_class_method_on_spec.rb +1 -1
- data/spec/lib/sinclair/matchers/change_class_method_spec.rb +1 -1
- data/spec/lib/sinclair/matchers/change_instance_method_on_spec.rb +1 -1
- data/spec/lib/sinclair/matchers/change_instance_method_spec.rb +1 -1
- data/spec/lib/sinclair/method_builder/base_spec.rb +1 -1
- data/spec/lib/sinclair/method_builder/block_method_builder_spec.rb +1 -1
- data/spec/lib/sinclair/method_builder/call_method_builder_spec.rb +1 -1
- data/spec/lib/sinclair/method_builder/string_method_builder_spec.rb +1 -1
- data/spec/lib/sinclair/method_definition_spec.rb +1 -0
- data/spec/lib/sinclair/method_definitions_spec.rb +9 -9
- data/spec/lib/sinclair/model_spec.rb +3 -3
- data/spec/lib/sinclair/options/class_methods_spec.rb +1 -1
- data/spec/lib/sinclair/options_spec.rb +3 -3
- data/spec/lib/sinclair/settable/builder_spec.rb +1 -1
- data/spec/spec_helper.rb +1 -1
- data/spec/support/models/default_valueable.rb +1 -1
- data/spec/support/models/env_settings.rb +1 -1
- data/spec/support/models/random_generator.rb +1 -1
- data/spec/support/shared_examples/model.rb +2 -2
- data/spec/support/shared_examples/settable.rb +2 -2
- metadata +11 -233
- /data/spec/integration/readme/{sinclair/types_of_definition_spec.rb → sinclair_types_of_definition_spec.rb} +0 -0
- /data/spec/integration/yard/sinclair/{class_methods/build_spec.rb → class_methods_build_spec.rb} +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7d9505060c3b7a018a408ea37b59af41203747d280336fd5f1f6bb148f329af6
|
4
|
+
data.tar.gz: 9967733ebc9f4ba73d553816a20530ff9399d3045cf0485f7412b0116924a2c8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 66bf1c943c5b9c9e6facfb8c5eecd92b86de5385f0fbb701715e62329ad5e82912272182baf4dce83f7517c8aae7b340aed8ce12e0315e0aefb805db3cfc90c7
|
7
|
+
data.tar.gz: e1166a305873c0e5184a9d8043166f27e1f2ecae5be57d031fea48f5d7ec0f2c79c0d8f1acefdf1db30d54ad8579ea220d6cd64be160ae5d0f6505379291d96a
|
data/.circleci/config.yml
CHANGED
@@ -22,7 +22,7 @@ workflows:
|
|
22
22
|
jobs:
|
23
23
|
test:
|
24
24
|
docker:
|
25
|
-
- image: darthjee/
|
25
|
+
- image: darthjee/circleci_ruby_331:1.0.1
|
26
26
|
environment:
|
27
27
|
PROJECT: sinclair
|
28
28
|
steps:
|
@@ -41,7 +41,7 @@ jobs:
|
|
41
41
|
command: cc-test-reporter after-build --exit-code $?
|
42
42
|
checks:
|
43
43
|
docker:
|
44
|
-
- image: darthjee/
|
44
|
+
- image: darthjee/circleci_ruby_331:1.0.1
|
45
45
|
environment:
|
46
46
|
PROJECT: sinclair
|
47
47
|
steps:
|
@@ -66,7 +66,7 @@ jobs:
|
|
66
66
|
command: check_specs
|
67
67
|
build-and-release:
|
68
68
|
docker:
|
69
|
-
- image: darthjee/
|
69
|
+
- image: darthjee/circleci_ruby_331:1.0.1
|
70
70
|
environment:
|
71
71
|
PROJECT: sinclair
|
72
72
|
steps:
|
data/.rubocop.yml
CHANGED
@@ -2,7 +2,8 @@ require: rubocop-rspec
|
|
2
2
|
inherit_from: .rubocop_todo.yml
|
3
3
|
|
4
4
|
AllCops:
|
5
|
-
TargetRubyVersion:
|
5
|
+
TargetRubyVersion: 3.3
|
6
|
+
NewCops: enable
|
6
7
|
|
7
8
|
RSpec/DescribeClass:
|
8
9
|
Exclude:
|
@@ -58,3 +59,34 @@ Style/HashTransformKeys:
|
|
58
59
|
|
59
60
|
Style/HashTransformValues:
|
60
61
|
Enabled: true
|
62
|
+
|
63
|
+
RSpec/MultipleMemoizedHelpers:
|
64
|
+
Enabled: false
|
65
|
+
|
66
|
+
Naming/VariableNumber:
|
67
|
+
Enabled: false
|
68
|
+
|
69
|
+
RSpec/IndexedLet:
|
70
|
+
Enabled: false
|
71
|
+
|
72
|
+
RSpec/IdenticalEqualityAssertion:
|
73
|
+
Enabled: false
|
74
|
+
|
75
|
+
RSpec/VerifiedDoubleReference:
|
76
|
+
Enabled: false
|
77
|
+
|
78
|
+
RSpec/RedundantPredicateMatcher:
|
79
|
+
Exclude:
|
80
|
+
- 'spec/integration/yard/sinclair/config_factory_spec.rb'
|
81
|
+
- 'spec/lib/sinclair/equals_checker_spec.rb'
|
82
|
+
|
83
|
+
Gemspec/RequireMFA:
|
84
|
+
Enabled: false
|
85
|
+
|
86
|
+
Lint/EmptyBlock:
|
87
|
+
Exclude:
|
88
|
+
- 'spec/**/*_spec.rb'
|
89
|
+
|
90
|
+
Lint/EmptyClass:
|
91
|
+
Exclude:
|
92
|
+
- 'spec/**/*.rb'
|
data/.rubocop_todo.yml
CHANGED
@@ -1,7 +1,19 @@
|
|
1
1
|
# This configuration was generated by
|
2
2
|
# `rubocop --auto-gen-config`
|
3
|
-
# on
|
3
|
+
# on 2025-05-09 01:27:02 UTC using RuboCop version 1.59.0.
|
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
|
7
7
|
# versions of RuboCop, may require this file to be generated again.
|
8
|
+
|
9
|
+
# Offense count: 1
|
10
|
+
# This cop supports unsafe autocorrection (--autocorrect-all).
|
11
|
+
# Configuration parameters: AllowSplatArgument.
|
12
|
+
Style/HashConversion:
|
13
|
+
Exclude:
|
14
|
+
- 'lib/sinclair/input_hash.rb'
|
15
|
+
|
16
|
+
# Offense count: 1
|
17
|
+
Style/OpenStructUse:
|
18
|
+
Exclude:
|
19
|
+
- 'lib/sinclair/options_parser.rb'
|
data/Dockerfile
CHANGED
data/Gemfile
CHANGED
@@ -3,3 +3,20 @@
|
|
3
3
|
source 'https://rubygems.org'
|
4
4
|
|
5
5
|
gemspec
|
6
|
+
|
7
|
+
gem 'bundler', '>= 2.5.13'
|
8
|
+
gem 'pry', '0.14.2'
|
9
|
+
gem 'pry-nav', '1.0.0'
|
10
|
+
gem 'rake', '13.1.0'
|
11
|
+
gem 'reek', '6.1.4'
|
12
|
+
gem 'rspec', '3.12.0'
|
13
|
+
gem 'rspec-core', '3.12.2'
|
14
|
+
gem 'rspec-expectations', '3.12.3'
|
15
|
+
gem 'rspec-mocks', '3.12.5'
|
16
|
+
gem 'rspec-support', '3.12.0'
|
17
|
+
gem 'rubocop', '1.59.0'
|
18
|
+
gem 'rubocop-rspec', '3.0.0'
|
19
|
+
gem 'rubycritic', '4.9.1'
|
20
|
+
gem 'simplecov', '0.22.0'
|
21
|
+
gem 'yard', '0.9.36'
|
22
|
+
gem 'yardstick', '0.9.9'
|
data/Makefile
ADDED
data/README.md
CHANGED
@@ -15,13 +15,13 @@ create custom comparators, configure your application, create powerfull options,
|
|
15
15
|
|
16
16
|
Employing Sinclair in your applications helps you streamline your development workflow and enhance your development process through more efficient, cleaner code
|
17
17
|
|
18
|
-
Current Release: [
|
18
|
+
Current Release: [3.0.0](https://github.com/darthjee/sinclair/tree/3.0.0)
|
19
19
|
|
20
|
-
[Next release](https://github.com/darthjee/sinclair/compare/
|
20
|
+
[Next release](https://github.com/darthjee/sinclair/compare/3.0.0...master)
|
21
21
|
|
22
22
|
Yard Documentation
|
23
23
|
-------------------
|
24
|
-
[https://www.rubydoc.info/gems/sinclair/
|
24
|
+
[https://www.rubydoc.info/gems/sinclair/3.0.0](https://www.rubydoc.info/gems/sinclair/3.0.0)
|
25
25
|
|
26
26
|
Installation
|
27
27
|
---------------
|
@@ -13,8 +13,8 @@ class Sinclair
|
|
13
13
|
end
|
14
14
|
|
15
15
|
# (see Caster.cast_with)
|
16
|
-
def cast_with(key, method_name = nil, &
|
17
|
-
caster = instance_for(method_name, &
|
16
|
+
def cast_with(key, method_name = nil, &)
|
17
|
+
caster = instance_for(method_name, &)
|
18
18
|
|
19
19
|
return class_casters[key] = caster if key.is_a?(Class)
|
20
20
|
|
@@ -22,8 +22,8 @@ class Sinclair
|
|
22
22
|
end
|
23
23
|
|
24
24
|
# (see Caster.cast)
|
25
|
-
def cast(value, key, **
|
26
|
-
caster_for(key).cast(value, **
|
25
|
+
def cast(value, key, **)
|
26
|
+
caster_for(key).cast(value, **)
|
27
27
|
end
|
28
28
|
|
29
29
|
# (see Caster.caster_for)
|
@@ -93,8 +93,8 @@ class Sinclair
|
|
93
93
|
# @param caster [Caster] instance of caster to be returned
|
94
94
|
#
|
95
95
|
# @return [Caster]
|
96
|
-
def instance_for(method_name, &
|
97
|
-
return new(&
|
96
|
+
def instance_for(method_name, &)
|
97
|
+
return new(&) unless method_name
|
98
98
|
return method_name if method_name.is_a?(Caster)
|
99
99
|
|
100
100
|
new(&method_name)
|
@@ -32,9 +32,9 @@ class Sinclair
|
|
32
32
|
# model = MyPerson.new
|
33
33
|
#
|
34
34
|
# model.random_name # returns 'John 803 Doe'
|
35
|
-
def build(
|
36
|
-
new(
|
37
|
-
builder.instance_eval(&
|
35
|
+
def build(*, **, &)
|
36
|
+
new(*, **).tap do |builder|
|
37
|
+
builder.instance_eval(&) if block_given?
|
38
38
|
end.build
|
39
39
|
end
|
40
40
|
end
|
@@ -49,10 +49,10 @@ class Sinclair
|
|
49
49
|
# @param args [Array<Object>] arguments of the call
|
50
50
|
#
|
51
51
|
# @return [Object]
|
52
|
-
def method_missing(method_name, *
|
52
|
+
def method_missing(method_name, *)
|
53
53
|
return super unless method_included?(method_name)
|
54
54
|
|
55
|
-
@config.instance_variable_set("@#{method_name}", *
|
55
|
+
@config.instance_variable_set("@#{method_name}", *)
|
56
56
|
end
|
57
57
|
|
58
58
|
# @private
|
@@ -78,8 +78,8 @@ class Sinclair
|
|
78
78
|
klass = @config.class
|
79
79
|
|
80
80
|
@config_attributes.include?(method_name) ||
|
81
|
-
klass.is_a?(Sinclair::ConfigClass) &&
|
82
|
-
klass.config_attributes.include?(method_name)
|
81
|
+
(klass.is_a?(Sinclair::ConfigClass) &&
|
82
|
+
klass.config_attributes.include?(method_name))
|
83
83
|
end
|
84
84
|
end
|
85
85
|
end
|
@@ -79,11 +79,11 @@ class Sinclair
|
|
79
79
|
#
|
80
80
|
# config.secret # return '123abc'
|
81
81
|
# config.app_name # return 'MySuperApp'
|
82
|
-
def add_configs(*
|
83
|
-
Config::MethodsBuilder.new(self, *
|
82
|
+
def add_configs(*)
|
83
|
+
Config::MethodsBuilder.new(self, *).tap do |builder|
|
84
84
|
builder.build
|
85
85
|
|
86
|
-
Sinclair::InputHash.input_hash(*
|
86
|
+
Sinclair::InputHash.input_hash(*).each do |name, value|
|
87
87
|
options_class.with_options(name => value)
|
88
88
|
end
|
89
89
|
|
@@ -21,8 +21,8 @@ class Sinclair
|
|
21
21
|
# Deprecation warning message
|
22
22
|
# @see https://github.com/darthjee/sinclair/blob/master/WARNINGS.md#usage-of-custom-config-classes
|
23
23
|
CONFIG_CLASS_WARNING = 'Config class is expected to be ConfigClass. ' \
|
24
|
-
|
25
|
-
|
24
|
+
"In future releases this will be enforced.\n" \
|
25
|
+
'see more on https://github.com/darthjee/sinclair/blob/master/WARNINGS.md#usage-of-custom-config-classes'
|
26
26
|
|
27
27
|
# @param config_class [Class] configuration class to be used
|
28
28
|
# @param config_attributes [Array<Symbol,String>] list of possible configurations
|
@@ -56,11 +56,11 @@ class Sinclair
|
|
56
56
|
#
|
57
57
|
# config.respond_to? :active
|
58
58
|
# # returns true
|
59
|
-
def add_configs(*
|
59
|
+
def add_configs(*)
|
60
60
|
builder = if config_class.is_a?(Sinclair::ConfigClass)
|
61
|
-
config_class.add_configs(*
|
61
|
+
config_class.add_configs(*)
|
62
62
|
else
|
63
|
-
Config::MethodsBuilder.build(config_class, *
|
63
|
+
Config::MethodsBuilder.build(config_class, *)
|
64
64
|
end
|
65
65
|
|
66
66
|
config_attributes.concat(builder.config_names.map(&:to_sym))
|
@@ -138,13 +138,14 @@ class Sinclair
|
|
138
138
|
def child
|
139
139
|
self.class.new(
|
140
140
|
config_class: Class.new(config_class),
|
141
|
-
config_attributes:
|
141
|
+
config_attributes:
|
142
142
|
)
|
143
143
|
end
|
144
144
|
|
145
145
|
private
|
146
146
|
|
147
147
|
attr_reader :config_class, :config_attributes
|
148
|
+
|
148
149
|
# @method config_class
|
149
150
|
# @private
|
150
151
|
# @api private
|
@@ -22,10 +22,10 @@ class Sinclair
|
|
22
22
|
# Deprecation warning message
|
23
23
|
# @see https://github.com/darthjee/sinclair/blob/master/WARNINGS.md#usage-of-custom-config-classes
|
24
24
|
CONFIG_CLASS_WARNING = 'Config classes attributes should ' \
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
25
|
+
'be defined inside the class or through the usage of ' \
|
26
|
+
"configurable_with.\n" \
|
27
|
+
"In future releases this will be enforced.\n" \
|
28
|
+
'see more on https://github.com/darthjee/sinclair/blob/master/WARNINGS.md#usage-of-custom-config-classes'
|
29
29
|
|
30
30
|
# @method config
|
31
31
|
#
|
@@ -202,7 +202,7 @@ class Sinclair
|
|
202
202
|
warn CONFIG_CLASS_WARNING if with.present?
|
203
203
|
|
204
204
|
@config_factory = ConfigFactory.new(
|
205
|
-
config_class
|
205
|
+
config_class:,
|
206
206
|
config_attributes: with.map(&:to_sym)
|
207
207
|
)
|
208
208
|
end
|
@@ -1,7 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'set'
|
4
|
-
|
5
3
|
class Sinclair
|
6
4
|
# @api public
|
7
5
|
# @author darthjee
|
@@ -90,7 +88,7 @@ class Sinclair
|
|
90
88
|
#
|
91
89
|
# @return [TrueClass,FalseClass]
|
92
90
|
def match?(model, other)
|
93
|
-
return false unless model.
|
91
|
+
return false unless model.instance_of?(other.class)
|
94
92
|
|
95
93
|
attributes.all? do |attr|
|
96
94
|
Reader.attributes_match?(attr, model, other)
|
data/lib/sinclair/exception.rb
CHANGED
data/lib/sinclair/input_hash.rb
CHANGED
@@ -34,8 +34,8 @@ class Sinclair
|
|
34
34
|
# # key3: 10,
|
35
35
|
# # 'key4' => 20
|
36
36
|
# # }
|
37
|
-
def self.input_hash(*
|
38
|
-
new(*
|
37
|
+
def self.input_hash(*)
|
38
|
+
new(*).to_h
|
39
39
|
end
|
40
40
|
|
41
41
|
# @api private
|
@@ -51,6 +51,7 @@ class Sinclair
|
|
51
51
|
private
|
52
52
|
|
53
53
|
attr_reader :attributes, :hash
|
54
|
+
|
54
55
|
# @method attributes
|
55
56
|
# @api private
|
56
57
|
# @private
|
@@ -78,7 +78,7 @@ class Sinclair
|
|
78
78
|
# @raise SyntaxError
|
79
79
|
def raise_block_syntax_error
|
80
80
|
raise SyntaxError, 'Block not received by the `add_class_method_to` matcher. ' \
|
81
|
-
|
81
|
+
'Perhaps you want to use `{ ... }` instead of do/end?'
|
82
82
|
end
|
83
83
|
end
|
84
84
|
end
|
@@ -108,7 +108,7 @@ class Sinclair
|
|
108
108
|
# @raise SyntaxError
|
109
109
|
def raise_block_syntax_error
|
110
110
|
raise SyntaxError, 'Block not received by the `add_instance_method_to` matcher. ' \
|
111
|
-
|
111
|
+
'Perhaps you want to use `{ ... }` instead of do/end?'
|
112
112
|
end
|
113
113
|
end
|
114
114
|
end
|
@@ -9,6 +9,7 @@ class Sinclair
|
|
9
9
|
class Base < RSpec::Matchers::BuiltIn::BaseMatcher
|
10
10
|
# @param method_name [String,Symbol] the method, to be checked, name
|
11
11
|
def initialize(method_name)
|
12
|
+
super
|
12
13
|
@method_name = method_name.to_sym
|
13
14
|
end
|
14
15
|
|
@@ -23,7 +24,7 @@ class Sinclair
|
|
23
24
|
#
|
24
25
|
# @return [Boolean]
|
25
26
|
def equal?(other)
|
26
|
-
return unless other.class == self.class
|
27
|
+
return false unless other.class == self.class
|
27
28
|
|
28
29
|
other.method_name == method_name &&
|
29
30
|
other.try(:klass) == try(:klass)
|
@@ -57,7 +57,7 @@ class Sinclair
|
|
57
57
|
# @raise SyntaxError
|
58
58
|
def raise_block_syntax_error
|
59
59
|
raise SyntaxError, 'Block not received by the `change_class_method_on` matcher. ' \
|
60
|
-
|
60
|
+
'Perhaps you want to use `{ ... }` instead of do/end?'
|
61
61
|
end
|
62
62
|
end
|
63
63
|
end
|
@@ -91,7 +91,7 @@ class Sinclair
|
|
91
91
|
# @raise SyntaxError
|
92
92
|
def raise_block_syntax_error
|
93
93
|
raise SyntaxError, 'Block not received by the `change_instance_method_on` matcher. ' \
|
94
|
-
|
94
|
+
'Perhaps you want to use `{ ... }` instead of do/end?'
|
95
95
|
end
|
96
96
|
end
|
97
97
|
end
|
@@ -19,7 +19,7 @@ class Sinclair
|
|
19
19
|
#
|
20
20
|
# @return [Symbol] name of the method built
|
21
21
|
def self.build(klass, definition, type:)
|
22
|
-
new(klass, definition, type:
|
22
|
+
new(klass, definition, type:).build
|
23
23
|
end
|
24
24
|
|
25
25
|
# @param klass [Class] class to receive the method
|
@@ -45,6 +45,7 @@ class Sinclair
|
|
45
45
|
private
|
46
46
|
|
47
47
|
attr_reader :klass, :definition, :type
|
48
|
+
|
48
49
|
# @method klass
|
49
50
|
# @private
|
50
51
|
# @api private
|
@@ -14,12 +14,12 @@ class Sinclair
|
|
14
14
|
# Returns proc block when {#cached?} as simple
|
15
15
|
#
|
16
16
|
# @return [Proc]
|
17
|
-
def cached_method_proc(method_name, &
|
17
|
+
def cached_method_proc(method_name, &)
|
18
18
|
proc do
|
19
19
|
instance_variable_get("@#{method_name}") ||
|
20
20
|
instance_variable_set(
|
21
21
|
"@#{method_name}",
|
22
|
-
instance_eval(&
|
22
|
+
instance_eval(&)
|
23
23
|
)
|
24
24
|
end
|
25
25
|
end
|
@@ -29,14 +29,14 @@ class Sinclair
|
|
29
29
|
# Returns proc block when {#cached?} as full
|
30
30
|
#
|
31
31
|
# @return [Proc]
|
32
|
-
def full_cached_method_proc(method_name, &
|
32
|
+
def full_cached_method_proc(method_name, &)
|
33
33
|
proc do
|
34
34
|
if instance_variable_defined?("@#{method_name}")
|
35
35
|
instance_variable_get("@#{method_name}")
|
36
36
|
else
|
37
37
|
instance_variable_set(
|
38
38
|
"@#{method_name}",
|
39
|
-
instance_eval(&
|
39
|
+
instance_eval(&)
|
40
40
|
)
|
41
41
|
end
|
42
42
|
end
|
@@ -49,11 +49,11 @@ class Sinclair
|
|
49
49
|
# returns a {StringDefinition} otherwise
|
50
50
|
#
|
51
51
|
# @return [Base]
|
52
|
-
def from(name, code = nil,
|
52
|
+
def from(name, code = nil, **, &block)
|
53
53
|
if block
|
54
|
-
BlockDefinition.new(name,
|
54
|
+
BlockDefinition.new(name, **, &block)
|
55
55
|
else
|
56
|
-
StringDefinition.new(name, code, **
|
56
|
+
StringDefinition.new(name, code, **)
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
@@ -68,11 +68,11 @@ class Sinclair
|
|
68
68
|
# @param type [Symbol] the method definition type
|
69
69
|
#
|
70
70
|
# @return [Sinclair::MethodDefinition] an instance of a subclass
|
71
|
-
def for(type,
|
72
|
-
return from(
|
71
|
+
def for(type, ...)
|
72
|
+
return from(...) unless type
|
73
73
|
|
74
74
|
klass = const_get("#{type}_definition".camelize)
|
75
|
-
klass.new(
|
75
|
+
klass.new(...)
|
76
76
|
end
|
77
77
|
|
78
78
|
# Defines builder for a definition class
|
@@ -100,7 +100,7 @@ class Sinclair
|
|
100
100
|
# @return [Symbol] the name of the method built
|
101
101
|
def build_with(builder_class)
|
102
102
|
define_method(:build) do |klass, type|
|
103
|
-
builder_class.build(klass, self, type:
|
103
|
+
builder_class.build(klass, self, type:)
|
104
104
|
end
|
105
105
|
end
|
106
106
|
end
|
@@ -131,7 +131,7 @@ class Sinclair
|
|
131
131
|
# @raise NotImplementedError
|
132
132
|
def build(_klass, _type)
|
133
133
|
raise NotImplementedError, 'Build is implemented in subclasses. ' \
|
134
|
-
|
134
|
+
"Use #{self.class}.from to initialize a proper object"
|
135
135
|
end
|
136
136
|
|
137
137
|
delegate :cached, to: :options_object
|
@@ -40,8 +40,8 @@ class Sinclair
|
|
40
40
|
# @see MethodDefinition.from
|
41
41
|
#
|
42
42
|
# @return [Array<MethodDefinition>]
|
43
|
-
def add(
|
44
|
-
definitions << MethodDefinition.for(type,
|
43
|
+
def add(*, type: nil, **, &)
|
44
|
+
definitions << MethodDefinition.for(type, *, **, &)
|
45
45
|
end
|
46
46
|
|
47
47
|
private
|
@@ -26,10 +26,10 @@ class Sinclair
|
|
26
26
|
# method should be added
|
27
27
|
# @param comparable [TrueClass,FalseClass] flag to make the class {Comparable}
|
28
28
|
# by the fields
|
29
|
-
def initialize(klass, *attributes, **
|
29
|
+
def initialize(klass, *attributes, **)
|
30
30
|
super(klass)
|
31
31
|
@attributes = attributes.flatten
|
32
|
-
@options = BuilderOptions.new(**
|
32
|
+
@options = BuilderOptions.new(**)
|
33
33
|
|
34
34
|
add_methods
|
35
35
|
change_equals
|
data/lib/sinclair/model.rb
CHANGED
@@ -51,9 +51,9 @@ class Sinclair
|
|
51
51
|
# job.state # returns :done
|
52
52
|
#
|
53
53
|
# @return [Class<Model>] a new class with the chosen attributes
|
54
|
-
def for(*attributes, **
|
54
|
+
def for(*attributes, **)
|
55
55
|
Class.new(self) do |klass|
|
56
|
-
Builder.new(klass, *attributes, **
|
56
|
+
Builder.new(klass, *attributes, **).build
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
@@ -100,8 +100,8 @@ class Sinclair
|
|
100
100
|
# job.state # returns :done
|
101
101
|
#
|
102
102
|
# @return [Array<MethodDefinition>]
|
103
|
-
def initialize_with(*attributes, **
|
104
|
-
Builder.new(self, *attributes, **
|
103
|
+
def initialize_with(*attributes, **)
|
104
|
+
Builder.new(self, *attributes, **).build
|
105
105
|
end
|
106
106
|
end
|
107
107
|
end
|
data/lib/sinclair/options.rb
CHANGED