smart_initializer 0.8.0 → 0.9.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/CHANGELOG.md +4 -0
- data/Gemfile.lock +3 -3
- data/README.md +36 -10
- data/gemfiles/without_external_deps.gemfile.lock +38 -40
- data/lib/smart_core/initializer/constructor.rb +8 -12
- data/lib/smart_core/initializer/version.rb +2 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9ef704918e8e3d81bfb2dd551b96f4e68f2a0f2cefacfdbced95ae9cce1a6b0b
|
4
|
+
data.tar.gz: 3960c509958efb9a0886d959ff3a55b6965bb916f80bd32bf04e0977d58b7560
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 329ebcfc66cab98ab6e35b392c425df04eb5d03260b3bcefceb6c9cffa8863bad1fafce5d3b822c4fd0d39e0caab36a502b38a8ed15ecba1f0157908a6bbbc0d
|
7
|
+
data.tar.gz: 31f8259c26367c56961dc70cd086dcae7e96f3eafa206b3395b2f4afc0cb25afc3bba6d55a94251d1495bb13fd27c3c590ca67ace17bba1af226b48ceacfb7a9
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
# Changelog
|
2
2
|
All notable changes to this project will be documented in this file.
|
3
3
|
|
4
|
+
## [0.9.0] - 2021-12-19
|
5
|
+
### Changed
|
6
|
+
- `:finalize` block is not invoked on the `option` with `optional: true` flag;
|
7
|
+
|
4
8
|
## [0.8.0] - 2021-12-04
|
5
9
|
### Added
|
6
10
|
- New options for option and param attributes:
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
smart_initializer (0.
|
4
|
+
smart_initializer (0.9.0)
|
5
5
|
qonfig (~> 0.24)
|
6
6
|
smart_engine (~> 0.11)
|
7
7
|
smart_types (~> 0.4)
|
@@ -84,7 +84,7 @@ GEM
|
|
84
84
|
simplecov_json_formatter (~> 0.1)
|
85
85
|
simplecov-html (0.12.3)
|
86
86
|
simplecov_json_formatter (0.1.3)
|
87
|
-
smart_engine (0.
|
87
|
+
smart_engine (0.12.0)
|
88
88
|
smart_types (0.7.0)
|
89
89
|
smart_engine (~> 0.11)
|
90
90
|
tzinfo (2.0.4)
|
@@ -107,4 +107,4 @@ DEPENDENCIES
|
|
107
107
|
smart_initializer!
|
108
108
|
|
109
109
|
BUNDLED WITH
|
110
|
-
2.2.
|
110
|
+
2.2.32
|
data/README.md
CHANGED
@@ -32,19 +32,19 @@ require 'smart_core/initializer'
|
|
32
32
|
- [Synopsis](#synopsis)
|
33
33
|
- [Initialization flow](#initialization-flow)
|
34
34
|
- [Attribute value definition flow](#attribute-value-definition-flow-during-object-allocation-and-construction)
|
35
|
-
- [Constructor definition](#constructor-definition)
|
35
|
+
- [Constructor definition DSL](#constructor-definition-dsl)
|
36
36
|
- [param](#param)
|
37
37
|
- [option](#option)
|
38
38
|
- [params](#params)
|
39
39
|
- [options](#options)
|
40
|
-
- [param and params signature](#param-and-params-
|
40
|
+
- [param and params signature](#param-and-params-signautre)
|
41
41
|
- [option and options signature](#option-and-options-signature)
|
42
42
|
- [Initializer integration](#initializer-integration)
|
43
43
|
- [Basic Example](#basic-example)
|
44
44
|
- [Access to the instance attributes](#access-to-the-instance-attributes)
|
45
45
|
- [Configuration](#configuration)
|
46
46
|
- [Type aliasing](#type-aliasing)
|
47
|
-
- [Type
|
47
|
+
- [Type casting](#type-casting)
|
48
48
|
- [Initialization extension](#initialization-extension)
|
49
49
|
- [Plugins](#plugins)
|
50
50
|
- [thy-types](#plugin-thy-types)
|
@@ -57,11 +57,11 @@ require 'smart_core/initializer'
|
|
57
57
|
|
58
58
|
#### Initialization flow
|
59
59
|
|
60
|
-
1. Parameter + Option definitioning and initialization;
|
60
|
+
1. Parameter + Option definitioning and initialization (custom object allocator and constructor);
|
61
61
|
2. Original **#initialize** invokation;
|
62
62
|
3. Initialization extensions invokation;
|
63
63
|
|
64
|
-
**NOTE!**:
|
64
|
+
**NOTE!**: **SmarteCore::Initializer**'s constructor is invoked first
|
65
65
|
in order to guarantee the validity of the SmartCore::Initializer's functionality
|
66
66
|
(such as `attribute overlap chek`, `instant type checking`, `value post-processing by finalize`, etc)
|
67
67
|
|
@@ -71,7 +71,30 @@ in order to guarantee the validity of the SmartCore::Initializer's functionality
|
|
71
71
|
2. *(if defined)*: `default value` (default value is used when `original value` is not defined)
|
72
72
|
3. *(if defined)*: `finalize`;
|
73
73
|
|
74
|
-
|
74
|
+
**NOTE**: `:finalize` block are not invoked on omitted `optional: true` attributes
|
75
|
+
which has no `:default` definition bock and which are not passed to the constructor. Example:
|
76
|
+
|
77
|
+
```ruby
|
78
|
+
# without :default
|
79
|
+
|
80
|
+
class User
|
81
|
+
include SmartCore::Initializer
|
82
|
+
option :age, :string, optional: true, finalize: -> (val) { "#{val}_years" }
|
83
|
+
end
|
84
|
+
|
85
|
+
User.new.age # => nil
|
86
|
+
```
|
87
|
+
|
88
|
+
```ruby
|
89
|
+
# with :default
|
90
|
+
|
91
|
+
class User
|
92
|
+
include SmartCore::Initializer
|
93
|
+
option :age, :string, optional: true, default: '0', finalize: -> (val) { "#{val}_years" }
|
94
|
+
end
|
95
|
+
|
96
|
+
User.new.age # => '0_years'
|
97
|
+
```
|
75
98
|
|
76
99
|
### Constructor definition DSL
|
77
100
|
|
@@ -90,7 +113,7 @@ in order to guarantee the validity of the SmartCore::Initializer's functionality
|
|
90
113
|
|
91
114
|
#### option
|
92
115
|
|
93
|
-
- `option` -
|
116
|
+
- `option` - defines kwarg-like attribute:
|
94
117
|
- `cast` (optional) - type-cast received value if value has invalid type;
|
95
118
|
- `privacy` (optional) - reader incapsulation level;
|
96
119
|
- `as` (optional) - attribute alias (be careful with naming aliases that overlap the names of other attributes);
|
@@ -106,13 +129,13 @@ in order to guarantee the validity of the SmartCore::Initializer's functionality
|
|
106
129
|
|
107
130
|
#### params
|
108
131
|
|
109
|
-
- `params` -
|
132
|
+
- `params` - defines a series of parameters;
|
110
133
|
- `:mutable` (optional) - (`false` by default);
|
111
134
|
- `:privacy` (optional) - (`:public` by default);
|
112
135
|
|
113
136
|
#### options
|
114
137
|
|
115
|
-
- `options` -
|
138
|
+
- `options` - defines a series of options;
|
116
139
|
- `:mutable` (optional) - (`false` by default);
|
117
140
|
- `:privacy` (optional) - (`:public` by default);
|
118
141
|
|
@@ -499,7 +522,10 @@ User.new(123, 'test', { admin: true, age: 22 })
|
|
499
522
|
|
500
523
|
## Roadmap
|
501
524
|
|
502
|
-
-
|
525
|
+
- More semantic attribute declaration errors (more domain-related attribute error objects);
|
526
|
+
- incorrect `:finalize` argument type: `ArgumentError` => `FinalizeArgumentError`;
|
527
|
+
- incorrect `:as` argument type: `ArguemntError` => `AsArgumentError`;
|
528
|
+
- etc;
|
503
529
|
- Support for `RSpec` doubles and instance_doubles inside the type system integration;
|
504
530
|
- Specs restructuring;
|
505
531
|
- Migrate from `TravisCI` to `GitHub Actions`;
|
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: ..
|
3
3
|
specs:
|
4
|
-
smart_initializer (0.
|
4
|
+
smart_initializer (0.8.0)
|
5
5
|
qonfig (~> 0.24)
|
6
6
|
smart_engine (~> 0.11)
|
7
7
|
smart_types (~> 0.4)
|
@@ -9,39 +9,38 @@ PATH
|
|
9
9
|
GEM
|
10
10
|
remote: https://rubygems.org/
|
11
11
|
specs:
|
12
|
-
activesupport (
|
12
|
+
activesupport (7.0.0)
|
13
13
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
14
14
|
i18n (>= 1.6, < 2)
|
15
15
|
minitest (>= 5.1)
|
16
16
|
tzinfo (~> 2.0)
|
17
|
-
|
18
|
-
|
19
|
-
rubocop (= 1.
|
20
|
-
rubocop-
|
21
|
-
rubocop-
|
22
|
-
rubocop-
|
23
|
-
|
24
|
-
ast (2.4.1)
|
17
|
+
armitage-rubocop (1.23.0.1)
|
18
|
+
rubocop (= 1.23.0)
|
19
|
+
rubocop-performance (= 1.12.0)
|
20
|
+
rubocop-rails (= 2.12.4)
|
21
|
+
rubocop-rake (= 0.6.0)
|
22
|
+
rubocop-rspec (= 2.6.0)
|
23
|
+
ast (2.4.2)
|
25
24
|
coderay (1.1.3)
|
26
|
-
concurrent-ruby (1.1.
|
25
|
+
concurrent-ruby (1.1.9)
|
27
26
|
diff-lcs (1.4.4)
|
28
27
|
docile (1.3.5)
|
29
|
-
i18n (1.8.
|
28
|
+
i18n (1.8.11)
|
30
29
|
concurrent-ruby (~> 1.0)
|
31
30
|
method_source (1.0.0)
|
32
|
-
minitest (5.
|
33
|
-
parallel (1.
|
34
|
-
parser (3.0.
|
31
|
+
minitest (5.15.0)
|
32
|
+
parallel (1.21.0)
|
33
|
+
parser (3.0.3.2)
|
35
34
|
ast (~> 2.4.1)
|
36
|
-
pry (0.
|
35
|
+
pry (0.14.1)
|
37
36
|
coderay (~> 1.1)
|
38
37
|
method_source (~> 1.0)
|
39
|
-
qonfig (0.
|
38
|
+
qonfig (0.26.0)
|
40
39
|
rack (2.2.3)
|
41
40
|
rainbow (3.0.0)
|
42
41
|
rake (13.0.3)
|
43
|
-
regexp_parser (2.0
|
44
|
-
rexml (3.2.
|
42
|
+
regexp_parser (2.2.0)
|
43
|
+
rexml (3.2.5)
|
45
44
|
rspec (3.10.0)
|
46
45
|
rspec-core (~> 3.10.0)
|
47
46
|
rspec-expectations (~> 3.10.0)
|
@@ -55,29 +54,28 @@ GEM
|
|
55
54
|
diff-lcs (>= 1.2.0, < 2.0)
|
56
55
|
rspec-support (~> 3.10.0)
|
57
56
|
rspec-support (3.10.1)
|
58
|
-
rubocop (1.
|
57
|
+
rubocop (1.23.0)
|
59
58
|
parallel (~> 1.10)
|
60
|
-
parser (>=
|
59
|
+
parser (>= 3.0.0.0)
|
61
60
|
rainbow (>= 2.2.2, < 4.0)
|
62
61
|
regexp_parser (>= 1.8, < 3.0)
|
63
62
|
rexml
|
64
|
-
rubocop-ast (>= 1.
|
63
|
+
rubocop-ast (>= 1.12.0, < 2.0)
|
65
64
|
ruby-progressbar (~> 1.7)
|
66
|
-
unicode-display_width (>= 1.4.0, <
|
67
|
-
rubocop-ast (1.
|
68
|
-
parser (>=
|
69
|
-
rubocop-performance (1.
|
70
|
-
rubocop (>=
|
65
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
66
|
+
rubocop-ast (1.15.0)
|
67
|
+
parser (>= 3.0.1.1)
|
68
|
+
rubocop-performance (1.12.0)
|
69
|
+
rubocop (>= 1.7.0, < 2.0)
|
71
70
|
rubocop-ast (>= 0.4.0)
|
72
|
-
rubocop-rails (2.
|
71
|
+
rubocop-rails (2.12.4)
|
73
72
|
activesupport (>= 4.2.0)
|
74
73
|
rack (>= 1.1)
|
75
|
-
rubocop (>=
|
76
|
-
rubocop-rake (0.
|
77
|
-
rubocop
|
78
|
-
rubocop-rspec (2.1.0)
|
74
|
+
rubocop (>= 1.7.0, < 2.0)
|
75
|
+
rubocop-rake (0.6.0)
|
79
76
|
rubocop (~> 1.0)
|
80
|
-
|
77
|
+
rubocop-rspec (2.6.0)
|
78
|
+
rubocop (~> 1.19)
|
81
79
|
ruby-progressbar (1.11.0)
|
82
80
|
simplecov (0.21.2)
|
83
81
|
docile (~> 1.1)
|
@@ -85,25 +83,25 @@ GEM
|
|
85
83
|
simplecov_json_formatter (~> 0.1)
|
86
84
|
simplecov-html (0.12.3)
|
87
85
|
simplecov_json_formatter (0.1.2)
|
88
|
-
smart_engine (0.
|
89
|
-
smart_types (0.
|
86
|
+
smart_engine (0.12.0)
|
87
|
+
smart_types (0.7.0)
|
90
88
|
smart_engine (~> 0.11)
|
91
89
|
tzinfo (2.0.4)
|
92
90
|
concurrent-ruby (~> 1.0)
|
93
|
-
unicode-display_width (1.
|
94
|
-
zeitwerk (2.4.2)
|
91
|
+
unicode-display_width (2.1.0)
|
95
92
|
|
96
93
|
PLATFORMS
|
97
94
|
x86_64-darwin-20
|
95
|
+
x86_64-darwin-21
|
98
96
|
|
99
97
|
DEPENDENCIES
|
100
|
-
armitage-rubocop (~> 1.
|
98
|
+
armitage-rubocop (~> 1.23)
|
101
99
|
bundler (~> 2.2)
|
102
|
-
pry (~> 0.
|
100
|
+
pry (~> 0.14)
|
103
101
|
rake (~> 13.0)
|
104
102
|
rspec (~> 3.10)
|
105
103
|
simplecov (~> 0.21)
|
106
104
|
smart_initializer!
|
107
105
|
|
108
106
|
BUNDLED WITH
|
109
|
-
2.2.
|
107
|
+
2.2.32
|
@@ -145,26 +145,22 @@ class SmartCore::Initializer::Constructor
|
|
145
145
|
attribute.has_default? ? attribute.default : nil
|
146
146
|
end
|
147
147
|
|
148
|
+
# NOTE: (if-block: what if `if` receives `false`?):
|
149
|
+
# For other case passed `attribute` is optional and
|
150
|
+
# should not be type-checked/type-casted/etc.
|
151
|
+
# But optional attributes with defined `default` setting should be
|
152
|
+
# type-checked and type-casted.
|
148
153
|
if options.key?(attribute.name) || attribute.has_default?
|
149
154
|
if !attribute.type.valid?(option_value) && attribute.cast?
|
150
155
|
option_value = attribute.type.cast(option_value)
|
151
156
|
end
|
152
157
|
|
153
158
|
attribute.validate!(option_value)
|
159
|
+
option_value = attribute.finalizer.call(option_value, instance)
|
160
|
+
attribute.validate!(option_value)
|
154
161
|
end
|
155
|
-
# NOTE: (if-block: what if `if` receives `false`?):
|
156
|
-
# For other case passed `attribute` is optional and
|
157
|
-
# should not be type-checked/type-casted/etc.
|
158
|
-
# But optional attributes with defined `default` setting should be
|
159
|
-
# type-checked and type-casted.
|
160
|
-
#
|
161
|
-
# TODO: it should be covered by tests
|
162
|
-
|
163
|
-
final_value = attribute.finalizer.call(option_value, instance)
|
164
|
-
# NOTE: validae `final_value` if only the `option` is provided (passed to constructor)
|
165
|
-
attribute.validate!(final_value) if options.key?(attribute.name)
|
166
162
|
|
167
|
-
instance.instance_variable_set("@#{attribute.name}",
|
163
|
+
instance.instance_variable_set("@#{attribute.name}", option_value)
|
168
164
|
end
|
169
165
|
end
|
170
166
|
# rubocop:enable Metrics/AbcSize
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: smart_initializer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rustam Ibragimov
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-12-
|
11
|
+
date: 2021-12-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: smart_engine
|
@@ -246,7 +246,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
246
246
|
- !ruby/object:Gem::Version
|
247
247
|
version: '0'
|
248
248
|
requirements: []
|
249
|
-
rubygems_version: 3.2.
|
249
|
+
rubygems_version: 3.2.32
|
250
250
|
signing_key:
|
251
251
|
specification_version: 4
|
252
252
|
summary: Initializer DSL
|