smart_initializer 0.5.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/.rubocop.yml +1 -1
- data/CHANGELOG.md +46 -1
- data/Gemfile.lock +45 -44
- data/LICENSE.txt +1 -1
- data/README.md +283 -40
- data/bin/console +2 -2
- data/gemfiles/with_external_deps.gemfile.lock +38 -38
- data/gemfiles/without_external_deps.gemfile.lock +50 -45
- data/lib/smart_core/initializer/attribute/factory/base.rb +145 -0
- data/lib/smart_core/initializer/attribute/factory/option.rb +107 -0
- data/lib/smart_core/initializer/attribute/factory/param.rb +63 -0
- data/lib/smart_core/initializer/attribute/factory.rb +5 -199
- data/lib/smart_core/initializer/attribute/finalizer/abstract.rb +2 -0
- data/lib/smart_core/initializer/attribute/finalizer/instance_method.rb +1 -1
- data/lib/smart_core/initializer/attribute/finalizer.rb +5 -5
- data/lib/smart_core/initializer/attribute/list.rb +20 -0
- data/lib/smart_core/initializer/attribute/{parameters.rb → value/base.rb} +35 -65
- data/lib/smart_core/initializer/attribute/value/option.rb +101 -0
- data/lib/smart_core/initializer/attribute/value/param.rb +24 -0
- data/lib/smart_core/initializer/attribute/value.rb +9 -0
- data/lib/smart_core/initializer/attribute.rb +3 -112
- data/lib/smart_core/initializer/configuration.rb +9 -0
- data/lib/smart_core/initializer/constructor/definer.rb +135 -46
- data/lib/smart_core/initializer/constructor.rb +29 -14
- data/lib/smart_core/initializer/dsl.rb +38 -24
- data/lib/smart_core/initializer/errors.rb +20 -0
- data/lib/smart_core/initializer/functionality.rb +7 -8
- data/lib/smart_core/initializer/plugins/thy_types/thy_types/abstract_factory.rb +13 -2
- data/lib/smart_core/initializer/settings/auto_cast.rb +40 -0
- data/lib/smart_core/initializer/settings/base.rb +49 -0
- data/lib/smart_core/initializer/settings/duplicator.rb +5 -0
- data/lib/smart_core/initializer/settings/strict_options.rb +40 -0
- data/lib/smart_core/initializer/settings/type_system.rb +10 -28
- data/lib/smart_core/initializer/settings.rb +40 -0
- data/lib/smart_core/initializer/type_system/interop/abstract_factory.rb +12 -2
- data/lib/smart_core/initializer/type_system/interop.rb +10 -1
- data/lib/smart_core/initializer/type_system/registry.rb +2 -1
- data/lib/smart_core/initializer/type_system/smart_types/abstract_factory.rb +13 -2
- data/lib/smart_core/initializer/type_system/smart_types.rb +2 -2
- data/lib/smart_core/initializer/version.rb +2 -2
- data/lib/smart_core/initializer.rb +14 -4
- data/smart_initializer.gemspec +3 -3
- metadata +18 -9
data/bin/console
CHANGED
@@ -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,39 @@ PATH
|
|
9
9
|
GEM
|
10
10
|
remote: https://rubygems.org/
|
11
11
|
specs:
|
12
|
-
activesupport (6.1.1)
|
12
|
+
activesupport (6.1.4.1)
|
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
17
|
zeitwerk (~> 2.3)
|
18
|
-
armitage-rubocop (1.
|
19
|
-
rubocop (= 1.
|
20
|
-
rubocop-performance (= 1.
|
21
|
-
rubocop-rails (= 2.
|
22
|
-
rubocop-rake (= 0.
|
23
|
-
rubocop-rspec (= 2.
|
24
|
-
ast (2.4.
|
18
|
+
armitage-rubocop (1.23.0.1)
|
19
|
+
rubocop (= 1.23.0)
|
20
|
+
rubocop-performance (= 1.12.0)
|
21
|
+
rubocop-rails (= 2.12.4)
|
22
|
+
rubocop-rake (= 0.6.0)
|
23
|
+
rubocop-rspec (= 2.6.0)
|
24
|
+
ast (2.4.2)
|
25
25
|
coderay (1.1.3)
|
26
|
-
concurrent-ruby (1.1.
|
26
|
+
concurrent-ruby (1.1.9)
|
27
27
|
diff-lcs (1.4.4)
|
28
28
|
docile (1.3.5)
|
29
|
-
i18n (1.8.
|
29
|
+
i18n (1.8.11)
|
30
30
|
concurrent-ruby (~> 1.0)
|
31
31
|
method_source (1.0.0)
|
32
|
-
minitest (5.14.
|
33
|
-
parallel (1.
|
34
|
-
parser (3.0.
|
32
|
+
minitest (5.14.4)
|
33
|
+
parallel (1.21.0)
|
34
|
+
parser (3.0.3.1)
|
35
35
|
ast (~> 2.4.1)
|
36
|
-
pry (0.
|
36
|
+
pry (0.14.1)
|
37
37
|
coderay (~> 1.1)
|
38
38
|
method_source (~> 1.0)
|
39
|
-
qonfig (0.
|
39
|
+
qonfig (0.26.0)
|
40
40
|
rack (2.2.3)
|
41
41
|
rainbow (3.0.0)
|
42
42
|
rake (13.0.3)
|
43
|
-
regexp_parser (2.
|
44
|
-
rexml (3.2.
|
43
|
+
regexp_parser (2.1.1)
|
44
|
+
rexml (3.2.5)
|
45
45
|
rspec (3.10.0)
|
46
46
|
rspec-core (~> 3.10.0)
|
47
47
|
rspec-expectations (~> 3.10.0)
|
@@ -55,29 +55,28 @@ GEM
|
|
55
55
|
diff-lcs (>= 1.2.0, < 2.0)
|
56
56
|
rspec-support (~> 3.10.0)
|
57
57
|
rspec-support (3.10.1)
|
58
|
-
rubocop (1.
|
58
|
+
rubocop (1.23.0)
|
59
59
|
parallel (~> 1.10)
|
60
|
-
parser (>=
|
60
|
+
parser (>= 3.0.0.0)
|
61
61
|
rainbow (>= 2.2.2, < 4.0)
|
62
62
|
regexp_parser (>= 1.8, < 3.0)
|
63
63
|
rexml
|
64
|
-
rubocop-ast (>= 1.
|
64
|
+
rubocop-ast (>= 1.12.0, < 2.0)
|
65
65
|
ruby-progressbar (~> 1.7)
|
66
|
-
unicode-display_width (>= 1.4.0, <
|
67
|
-
rubocop-ast (1.
|
68
|
-
parser (>=
|
69
|
-
rubocop-performance (1.
|
70
|
-
rubocop (>=
|
66
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
67
|
+
rubocop-ast (1.13.0)
|
68
|
+
parser (>= 3.0.1.1)
|
69
|
+
rubocop-performance (1.12.0)
|
70
|
+
rubocop (>= 1.7.0, < 2.0)
|
71
71
|
rubocop-ast (>= 0.4.0)
|
72
|
-
rubocop-rails (2.
|
72
|
+
rubocop-rails (2.12.4)
|
73
73
|
activesupport (>= 4.2.0)
|
74
74
|
rack (>= 1.1)
|
75
|
-
rubocop (>=
|
76
|
-
rubocop-rake (0.
|
77
|
-
rubocop
|
78
|
-
rubocop-rspec (2.1.0)
|
75
|
+
rubocop (>= 1.7.0, < 2.0)
|
76
|
+
rubocop-rake (0.6.0)
|
79
77
|
rubocop (~> 1.0)
|
80
|
-
|
78
|
+
rubocop-rspec (2.6.0)
|
79
|
+
rubocop (~> 1.19)
|
81
80
|
ruby-progressbar (1.11.0)
|
82
81
|
simplecov (0.21.2)
|
83
82
|
docile (~> 1.1)
|
@@ -86,21 +85,22 @@ GEM
|
|
86
85
|
simplecov-html (0.12.3)
|
87
86
|
simplecov_json_formatter (0.1.2)
|
88
87
|
smart_engine (0.11.0)
|
89
|
-
smart_types (0.
|
88
|
+
smart_types (0.7.0)
|
90
89
|
smart_engine (~> 0.11)
|
91
90
|
thy (0.1.4)
|
92
91
|
tzinfo (2.0.4)
|
93
92
|
concurrent-ruby (~> 1.0)
|
94
|
-
unicode-display_width (1.
|
95
|
-
zeitwerk (2.
|
93
|
+
unicode-display_width (2.1.0)
|
94
|
+
zeitwerk (2.5.1)
|
96
95
|
|
97
96
|
PLATFORMS
|
98
97
|
x86_64-darwin-20
|
98
|
+
x86_64-darwin-21
|
99
99
|
|
100
100
|
DEPENDENCIES
|
101
|
-
armitage-rubocop (~> 1.
|
101
|
+
armitage-rubocop (~> 1.23)
|
102
102
|
bundler (~> 2.2)
|
103
|
-
pry (~> 0.
|
103
|
+
pry (~> 0.14)
|
104
104
|
rake (~> 13.0)
|
105
105
|
rspec (~> 3.10)
|
106
106
|
simplecov (~> 0.21)
|
@@ -108,4 +108,4 @@ DEPENDENCIES
|
|
108
108
|
thy (~> 0.1.4)
|
109
109
|
|
110
110
|
BUNDLED WITH
|
111
|
-
2.2.
|
111
|
+
2.2.31
|
@@ -1,42 +1,46 @@
|
|
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
|
-
smart_engine (~> 0.
|
7
|
-
smart_types (~> 0.
|
6
|
+
smart_engine (~> 0.11)
|
7
|
+
smart_types (~> 0.4)
|
8
8
|
|
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 (=
|
20
|
-
rubocop-
|
21
|
-
rubocop-
|
22
|
-
rubocop-
|
23
|
-
|
24
|
-
|
25
|
-
concurrent-ruby (1.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)
|
24
|
+
coderay (1.1.3)
|
25
|
+
concurrent-ruby (1.1.9)
|
26
26
|
diff-lcs (1.4.4)
|
27
27
|
docile (1.3.5)
|
28
|
-
i18n (1.8.
|
28
|
+
i18n (1.8.11)
|
29
29
|
concurrent-ruby (~> 1.0)
|
30
|
-
|
31
|
-
|
32
|
-
|
30
|
+
method_source (1.0.0)
|
31
|
+
minitest (5.15.0)
|
32
|
+
parallel (1.21.0)
|
33
|
+
parser (3.0.3.2)
|
33
34
|
ast (~> 2.4.1)
|
34
|
-
|
35
|
+
pry (0.14.1)
|
36
|
+
coderay (~> 1.1)
|
37
|
+
method_source (~> 1.0)
|
38
|
+
qonfig (0.26.0)
|
35
39
|
rack (2.2.3)
|
36
40
|
rainbow (3.0.0)
|
37
41
|
rake (13.0.3)
|
38
|
-
regexp_parser (2.0
|
39
|
-
rexml (3.2.
|
42
|
+
regexp_parser (2.2.0)
|
43
|
+
rexml (3.2.5)
|
40
44
|
rspec (3.10.0)
|
41
45
|
rspec-core (~> 3.10.0)
|
42
46
|
rspec-expectations (~> 3.10.0)
|
@@ -50,28 +54,28 @@ GEM
|
|
50
54
|
diff-lcs (>= 1.2.0, < 2.0)
|
51
55
|
rspec-support (~> 3.10.0)
|
52
56
|
rspec-support (3.10.1)
|
53
|
-
rubocop (
|
57
|
+
rubocop (1.23.0)
|
54
58
|
parallel (~> 1.10)
|
55
|
-
parser (>=
|
59
|
+
parser (>= 3.0.0.0)
|
56
60
|
rainbow (>= 2.2.2, < 4.0)
|
57
|
-
regexp_parser (>= 1.8)
|
61
|
+
regexp_parser (>= 1.8, < 3.0)
|
58
62
|
rexml
|
59
|
-
rubocop-ast (>=
|
63
|
+
rubocop-ast (>= 1.12.0, < 2.0)
|
60
64
|
ruby-progressbar (~> 1.7)
|
61
|
-
unicode-display_width (>= 1.4.0, <
|
62
|
-
rubocop-ast (1.
|
63
|
-
parser (>=
|
64
|
-
rubocop-performance (1.
|
65
|
-
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)
|
66
70
|
rubocop-ast (>= 0.4.0)
|
67
|
-
rubocop-rails (2.
|
71
|
+
rubocop-rails (2.12.4)
|
68
72
|
activesupport (>= 4.2.0)
|
69
73
|
rack (>= 1.1)
|
70
|
-
rubocop (>=
|
71
|
-
rubocop-rake (0.
|
72
|
-
rubocop
|
73
|
-
rubocop-rspec (
|
74
|
-
rubocop (~>
|
74
|
+
rubocop (>= 1.7.0, < 2.0)
|
75
|
+
rubocop-rake (0.6.0)
|
76
|
+
rubocop (~> 1.0)
|
77
|
+
rubocop-rspec (2.6.0)
|
78
|
+
rubocop (~> 1.19)
|
75
79
|
ruby-progressbar (1.11.0)
|
76
80
|
simplecov (0.21.2)
|
77
81
|
docile (~> 1.1)
|
@@ -79,24 +83,25 @@ GEM
|
|
79
83
|
simplecov_json_formatter (~> 0.1)
|
80
84
|
simplecov-html (0.12.3)
|
81
85
|
simplecov_json_formatter (0.1.2)
|
82
|
-
smart_engine (0.
|
83
|
-
smart_types (0.
|
84
|
-
smart_engine (~> 0.
|
86
|
+
smart_engine (0.12.0)
|
87
|
+
smart_types (0.7.0)
|
88
|
+
smart_engine (~> 0.11)
|
85
89
|
tzinfo (2.0.4)
|
86
90
|
concurrent-ruby (~> 1.0)
|
87
|
-
unicode-display_width (1.
|
88
|
-
zeitwerk (2.4.2)
|
91
|
+
unicode-display_width (2.1.0)
|
89
92
|
|
90
93
|
PLATFORMS
|
91
94
|
x86_64-darwin-20
|
95
|
+
x86_64-darwin-21
|
92
96
|
|
93
97
|
DEPENDENCIES
|
94
|
-
armitage-rubocop (~>
|
95
|
-
bundler (~> 2.
|
98
|
+
armitage-rubocop (~> 1.23)
|
99
|
+
bundler (~> 2.2)
|
100
|
+
pry (~> 0.14)
|
96
101
|
rake (~> 13.0)
|
97
|
-
rspec (~> 3.
|
98
|
-
simplecov (~> 0.
|
102
|
+
rspec (~> 3.10)
|
103
|
+
simplecov (~> 0.21)
|
99
104
|
smart_initializer!
|
100
105
|
|
101
106
|
BUNDLED WITH
|
102
|
-
2.2.
|
107
|
+
2.2.32
|
@@ -0,0 +1,145 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# @api private
|
4
|
+
# @since 0.8.0
|
5
|
+
class SmartCore::Initializer::Attribute::Factory::Base
|
6
|
+
class << self
|
7
|
+
# @!method create(*params)
|
8
|
+
# @param params [Any] List of appropriated attributes for the corresponding factory
|
9
|
+
# @return [SmartCore::Initializer::Attribute::Base]
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
# @param name [String, Symbol]
|
14
|
+
# @return [Symbol]
|
15
|
+
#
|
16
|
+
# @api private
|
17
|
+
# @since 0.8.0
|
18
|
+
def prepare_name_param(name)
|
19
|
+
unless name.is_a?(::String) || name.is_a?(::Symbol)
|
20
|
+
raise(SmartCore::Initializer::ArgumentError, <<~ERROR_MESSAGE)
|
21
|
+
Attribute name should be a type of String or Symbol
|
22
|
+
ERROR_MESSAGE
|
23
|
+
end
|
24
|
+
|
25
|
+
name.to_sym
|
26
|
+
end
|
27
|
+
|
28
|
+
# @param type [String, Symbol, Any]
|
29
|
+
# @param type_system [Class<SmartCore::Initializer::TypeSystem::Interop>]
|
30
|
+
# @return [SmartCore::Initializer::TypeSystem::Interop]
|
31
|
+
#
|
32
|
+
# @api private
|
33
|
+
# @since 0.8.0
|
34
|
+
def prepare_type_param(type, type_system)
|
35
|
+
type_primitive =
|
36
|
+
if type.is_a?(::String) || type.is_a?(::Symbol)
|
37
|
+
type_system.type_from_alias(type)
|
38
|
+
else
|
39
|
+
type
|
40
|
+
end
|
41
|
+
|
42
|
+
type_system.create(type_primitive)
|
43
|
+
end
|
44
|
+
|
45
|
+
# @param cast [Boolean]
|
46
|
+
# @return [Boolean]
|
47
|
+
#
|
48
|
+
# @api private
|
49
|
+
# @since 0.8.0
|
50
|
+
def prepare_cast_param(cast)
|
51
|
+
unless cast.is_a?(::TrueClass) || cast.is_a?(::FalseClass)
|
52
|
+
raise(SmartCore::Initializer::ArgumentError, <<~ERROR_MESSAGE)
|
53
|
+
Attribute cast should be a type of boolean
|
54
|
+
ERROR_MESSAGE
|
55
|
+
end
|
56
|
+
|
57
|
+
cast
|
58
|
+
end
|
59
|
+
|
60
|
+
# @param privacy [String, Symbol]
|
61
|
+
# @return [Symbol]
|
62
|
+
#
|
63
|
+
# @api private
|
64
|
+
# @since 0.8.0
|
65
|
+
def prepare_privacy_param(privacy)
|
66
|
+
unless privacy.is_a?(::String) || privacy.is_a?(::Symbol)
|
67
|
+
raise(SmartCore::Initializer::ArgumentError, <<~ERROR_MESSAGE)
|
68
|
+
Attribute privacy should be a type of String or Symbol
|
69
|
+
ERROR_MESSAGE
|
70
|
+
end
|
71
|
+
|
72
|
+
SmartCore::Initializer::Attribute::Value::Base::PRIVACY_MODES.fetch(privacy.to_sym) do
|
73
|
+
raise(SmartCore::Initializer::ArgumentError, <<~ERROR_MESSAGE)
|
74
|
+
Incorrect attribute privacy identifier "#{privacy}"
|
75
|
+
ERROR_MESSAGE
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
# @param finalize [String, Symbol, Proc]
|
80
|
+
# @return [SmartCore::Initializer::Attribute::Finalizer::AnonymousBlock/InstanceMethod]
|
81
|
+
#
|
82
|
+
# @api private
|
83
|
+
# @since 0.8.0
|
84
|
+
def prepare_finalize_param(finalize)
|
85
|
+
unless finalize.is_a?(::String) || finalize.is_a?(::Symbol) || finalize.is_a?(::Proc)
|
86
|
+
raise(SmartCore::Initializer::ArgumentError, <<~ERROR_MESSAGE)
|
87
|
+
Attribute finalizer should be a type of String, Symbol or Proc
|
88
|
+
ERROR_MESSAGE
|
89
|
+
end
|
90
|
+
|
91
|
+
# rubocop:disable Style/SoleNestedConditional
|
92
|
+
if finalize.is_a?(::Proc) && finalize.lambda?
|
93
|
+
unless (finalize.arity == 1 || finalize.arity == -1)
|
94
|
+
raise(
|
95
|
+
SmartCore::Initializer::ArgumentError,
|
96
|
+
'Lambda-based finalizer should have arity equal to 1 or equal to -1 ' \
|
97
|
+
'(your lambda object should require one attribute)'
|
98
|
+
) # TODO: show the name of attribute in error message (if the name is a valid, of course)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
# rubocop:enable Style/SoleNestedConditional
|
102
|
+
|
103
|
+
SmartCore::Initializer::Attribute::Finalizer.create(finalize)
|
104
|
+
end
|
105
|
+
|
106
|
+
# @param mutable [Boolean]
|
107
|
+
# @return [Boolean]
|
108
|
+
#
|
109
|
+
# @api private
|
110
|
+
# @since 0.4.0
|
111
|
+
def prepare_mutable_param(mutable)
|
112
|
+
unless mutable.is_a?(::FalseClass) || mutable.is_a?(::TrueClass)
|
113
|
+
raise(SmartCore::Initializer::ArgumentError, <<~ERROR_MESSAGE)
|
114
|
+
:mutable attribute should be a type of boolean
|
115
|
+
ERROR_MESSAGE
|
116
|
+
end
|
117
|
+
|
118
|
+
mutable
|
119
|
+
end
|
120
|
+
|
121
|
+
# @param as [String, Symbol, NilClass]
|
122
|
+
# @return [String, Symbol, NilClass]
|
123
|
+
#
|
124
|
+
# @api private
|
125
|
+
# @since 0.4.0
|
126
|
+
def preapre_as_param(as)
|
127
|
+
unless as.is_a?(::NilClass) || as.is_a?(::String) || as.is_a?(::Symbol)
|
128
|
+
raise(SmartCore::Initializer::ArgumentError, <<~ERROR_MESSAGE)
|
129
|
+
Attribute alias should be a type of String or Symbol
|
130
|
+
ERROR_MESSAGE
|
131
|
+
end
|
132
|
+
|
133
|
+
as
|
134
|
+
end
|
135
|
+
|
136
|
+
# @param type_system [String, Symbol]
|
137
|
+
# @return [Class<SmartCore::Initializer::TypeSystem::Interop>]
|
138
|
+
#
|
139
|
+
# @api private
|
140
|
+
# @since 0.8.0
|
141
|
+
def prepare_type_system_param(type_system)
|
142
|
+
SmartCore::Initializer::TypeSystem.resolve(type_system)
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
@@ -0,0 +1,107 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SmartCore::Initializer::Attribute::Factory
|
4
|
+
# @api private
|
5
|
+
# @since 0.8.0
|
6
|
+
class Option < Base
|
7
|
+
class << self
|
8
|
+
# @param name [String, Symbol]
|
9
|
+
# @param type [String, Symbol, Any]
|
10
|
+
# @param type_system [String, Symbol]
|
11
|
+
# @param privacy [String, Symbol]
|
12
|
+
# @param finalize [String, Symbol, Proc]
|
13
|
+
# @param cast [Boolean]
|
14
|
+
# @param mutable [Boolean]
|
15
|
+
# @param as [String, Symbol, NilClass]
|
16
|
+
# @param default [Proc, Any]
|
17
|
+
# @param optional [Boolean]
|
18
|
+
# @return [SmartCore::Initializer::Attribute::Value::Option]
|
19
|
+
#
|
20
|
+
# @api private
|
21
|
+
# @since 0.8.0
|
22
|
+
def create(name, type, type_system, privacy, finalize, cast, mutable, as, default, optional)
|
23
|
+
prepared_name = prepare_name_param(name)
|
24
|
+
prepared_privacy = prepare_privacy_param(privacy)
|
25
|
+
prepared_finalize = prepare_finalize_param(finalize)
|
26
|
+
prepared_cast = prepare_cast_param(cast)
|
27
|
+
prepared_type_system = prepare_type_system_param(type_system)
|
28
|
+
prepared_type = prepare_type_param(type, prepared_type_system)
|
29
|
+
prepared_mutable = prepare_mutable_param(mutable)
|
30
|
+
prepared_as = preapre_as_param(as)
|
31
|
+
prepared_default = prepare_default_param(default)
|
32
|
+
prepared_optional = prepare_optional_param(optional)
|
33
|
+
|
34
|
+
create_attribute(
|
35
|
+
prepared_name,
|
36
|
+
prepared_type,
|
37
|
+
prepared_type_system,
|
38
|
+
prepared_privacy,
|
39
|
+
prepared_finalize,
|
40
|
+
prepared_cast,
|
41
|
+
prepared_mutable,
|
42
|
+
prepared_as,
|
43
|
+
prepared_default,
|
44
|
+
prepared_optional
|
45
|
+
)
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
# @param name [String]
|
51
|
+
# @param type [SmartCore::Initializer::TypeSystem::Interop]
|
52
|
+
# @param type_system [Class<SmartCore::Initializer::TypeSystem::Interop>]
|
53
|
+
# @param privacy [Symbol]
|
54
|
+
# @param finalize [SmartCore::Initializer::Attribute::Finalizer::Abstract]
|
55
|
+
# @param cast [Boolean]
|
56
|
+
# @param mutable [Boolean]
|
57
|
+
# @param as [String, Symbol]
|
58
|
+
# @param default [Proc, Any]
|
59
|
+
# @param optional [Boolean]
|
60
|
+
# @return [SmartCore::Initializer::Attribute::Value::Option]
|
61
|
+
#
|
62
|
+
# @api private
|
63
|
+
# @since 0.8.0
|
64
|
+
def create_attribute(
|
65
|
+
name,
|
66
|
+
type,
|
67
|
+
type_system,
|
68
|
+
privacy,
|
69
|
+
finalize,
|
70
|
+
cast,
|
71
|
+
mutable,
|
72
|
+
as,
|
73
|
+
default,
|
74
|
+
optional
|
75
|
+
)
|
76
|
+
SmartCore::Initializer::Attribute::Value::Option.new(
|
77
|
+
name, type, type_system, privacy, finalize, cast, mutable, as, default, optional
|
78
|
+
)
|
79
|
+
end
|
80
|
+
|
81
|
+
# @param default [Proc, Any]
|
82
|
+
# @return [Proc, Any]
|
83
|
+
#
|
84
|
+
# @api private
|
85
|
+
# @since 0.8.0
|
86
|
+
def prepare_default_param(default)
|
87
|
+
# NOTE: this "strange" approach is used to comply the default Factory methods approach here
|
88
|
+
default
|
89
|
+
end
|
90
|
+
|
91
|
+
# @param optional [Boolean]
|
92
|
+
# @return [Boolean]
|
93
|
+
#
|
94
|
+
# @api private
|
95
|
+
# @since 0.8.0
|
96
|
+
def prepare_optional_param(optional)
|
97
|
+
unless optional.is_a?(::TrueClass) || optional.is_a?(::FalseClass)
|
98
|
+
raise(SmartCore::Initializer::ArgumentError, <<~ERROR_MESSAGE)
|
99
|
+
:optional attribute should be a type of boolean
|
100
|
+
ERROR_MESSAGE
|
101
|
+
end
|
102
|
+
|
103
|
+
optional
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SmartCore::Initializer::Attribute::Factory
|
4
|
+
# @api private
|
5
|
+
# @since 0.8.0
|
6
|
+
class Param < Base
|
7
|
+
class << self
|
8
|
+
# @param name [String, Symbol]
|
9
|
+
# @param type [String, Symbol, Any]
|
10
|
+
# @param type_system [String, Symbol]
|
11
|
+
# @param privacy [String, Symbol]
|
12
|
+
# @param finalize [String, Symbol, Proc]
|
13
|
+
# @param cast [Boolean]
|
14
|
+
# @param mutable [Boolean]
|
15
|
+
# @param as [String, Symbol, NilClass]
|
16
|
+
# @return [SmartCore::Initializer::Attribute::Value::Param]
|
17
|
+
#
|
18
|
+
# @api private
|
19
|
+
# @since 0.8.0
|
20
|
+
def create(name, type, type_system, privacy, finalize, cast, mutable, as)
|
21
|
+
prepared_name = prepare_name_param(name)
|
22
|
+
prepared_privacy = prepare_privacy_param(privacy)
|
23
|
+
prepared_finalize = prepare_finalize_param(finalize)
|
24
|
+
prepared_cast = prepare_cast_param(cast)
|
25
|
+
prepared_type_system = prepare_type_system_param(type_system)
|
26
|
+
prepared_type = prepare_type_param(type, prepared_type_system)
|
27
|
+
prepared_mutable = prepare_mutable_param(mutable)
|
28
|
+
prepared_as = preapre_as_param(as)
|
29
|
+
|
30
|
+
create_attribute(
|
31
|
+
prepared_name,
|
32
|
+
prepared_type,
|
33
|
+
prepared_type_system,
|
34
|
+
prepared_privacy,
|
35
|
+
prepared_finalize,
|
36
|
+
prepared_cast,
|
37
|
+
prepared_mutable,
|
38
|
+
prepared_as
|
39
|
+
)
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
# @param name [String]
|
45
|
+
# @param type [SmartCore::Initializer::TypeSystem::Interop]
|
46
|
+
# @param type_system [Class<SmartCore::Initializer::TypeSystem::Interop>]
|
47
|
+
# @param privacy [Symbol]
|
48
|
+
# @param finalize [SmartCore::Initializer::Attribute::Finalizer::Abstract]
|
49
|
+
# @param cast [Boolean]
|
50
|
+
# @param mutable [Boolean]
|
51
|
+
# @param as [String, Symbol]
|
52
|
+
# @return [SmartCore::Initializer::Attribute::Value::Param]
|
53
|
+
#
|
54
|
+
# @api private
|
55
|
+
# @since 0.8.0
|
56
|
+
def create_attribute(name, type, type_system, privacy, finalize, cast, mutable, as)
|
57
|
+
SmartCore::Initializer::Attribute::Value::Param.new(
|
58
|
+
name, type, type_system, privacy, finalize, cast, mutable, as
|
59
|
+
)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|