smart_initializer 0.7.0 → 0.9.1

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.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +1 -1
  3. data/CHANGELOG.md +46 -3
  4. data/Gemfile.lock +40 -39
  5. data/README.md +286 -41
  6. data/bin/console +2 -2
  7. data/gemfiles/with_external_deps.gemfile.lock +40 -39
  8. data/gemfiles/without_external_deps.gemfile.lock +39 -40
  9. data/lib/smart_core/initializer/attribute/factory/base.rb +154 -0
  10. data/lib/smart_core/initializer/attribute/factory/option.rb +107 -0
  11. data/lib/smart_core/initializer/attribute/factory/param.rb +63 -0
  12. data/lib/smart_core/initializer/attribute/factory.rb +5 -199
  13. data/lib/smart_core/initializer/attribute/finalizer/abstract.rb +2 -0
  14. data/lib/smart_core/initializer/attribute/finalizer/instance_method.rb +1 -1
  15. data/lib/smart_core/initializer/attribute/finalizer.rb +5 -5
  16. data/lib/smart_core/initializer/attribute/list.rb +20 -0
  17. data/lib/smart_core/initializer/attribute/{parameters.rb → value/base.rb} +35 -65
  18. data/lib/smart_core/initializer/attribute/value/option.rb +101 -0
  19. data/lib/smart_core/initializer/attribute/value/param.rb +24 -0
  20. data/lib/smart_core/initializer/attribute/value.rb +9 -0
  21. data/lib/smart_core/initializer/attribute.rb +3 -125
  22. data/lib/smart_core/initializer/configuration.rb +7 -3
  23. data/lib/smart_core/initializer/constructor/definer.rb +135 -46
  24. data/lib/smart_core/initializer/constructor.rb +28 -14
  25. data/lib/smart_core/initializer/dsl.rb +38 -24
  26. data/lib/smart_core/initializer/errors.rb +20 -4
  27. data/lib/smart_core/initializer/functionality.rb +7 -8
  28. data/lib/smart_core/initializer/settings/auto_cast.rb +40 -0
  29. data/lib/smart_core/initializer/settings/base.rb +49 -0
  30. data/lib/smart_core/initializer/settings/duplicator.rb +5 -0
  31. data/lib/smart_core/initializer/settings/strict_options.rb +40 -0
  32. data/lib/smart_core/initializer/settings/type_system.rb +10 -28
  33. data/lib/smart_core/initializer/settings.rb +40 -0
  34. data/lib/smart_core/initializer/type_system/registry.rb +2 -1
  35. data/lib/smart_core/initializer/type_system/smart_types.rb +2 -2
  36. data/lib/smart_core/initializer/version.rb +2 -2
  37. data/lib/smart_core/initializer.rb +14 -4
  38. data/smart_initializer.gemspec +2 -2
  39. metadata +16 -7
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- smart_initializer (0.5.0)
4
+ smart_initializer (0.9.1)
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.7.0.1)
19
- rubocop (= 1.7.0)
20
- rubocop-performance (= 1.9.1)
21
- rubocop-rails (= 2.9.1)
22
- rubocop-rake (= 0.5.1)
23
- rubocop-rspec (= 2.1.0)
24
- ast (2.4.1)
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.7)
26
+ concurrent-ruby (1.1.9)
27
27
  diff-lcs (1.4.4)
28
28
  docile (1.3.5)
29
- i18n (1.8.7)
29
+ i18n (1.8.11)
30
30
  concurrent-ruby (~> 1.0)
31
31
  method_source (1.0.0)
32
- minitest (5.14.3)
33
- parallel (1.20.1)
34
- parser (3.0.0.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.13.1)
36
+ pry (0.14.1)
37
37
  coderay (~> 1.1)
38
38
  method_source (~> 1.0)
39
- qonfig (0.25.0)
39
+ qonfig (0.27.0)
40
40
  rack (2.2.3)
41
41
  rainbow (3.0.0)
42
42
  rake (13.0.3)
43
- regexp_parser (2.0.3)
44
- rexml (3.2.4)
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.7.0)
58
+ rubocop (1.23.0)
59
59
  parallel (~> 1.10)
60
- parser (>= 2.7.1.5)
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.2.0, < 2.0)
64
+ rubocop-ast (>= 1.12.0, < 2.0)
65
65
  ruby-progressbar (~> 1.7)
66
- unicode-display_width (>= 1.4.0, < 2.0)
67
- rubocop-ast (1.4.0)
68
- parser (>= 2.7.1.5)
69
- rubocop-performance (1.9.1)
70
- rubocop (>= 0.90.0, < 2.0)
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.9.1)
72
+ rubocop-rails (2.12.4)
73
73
  activesupport (>= 4.2.0)
74
74
  rack (>= 1.1)
75
- rubocop (>= 0.90.0, < 2.0)
76
- rubocop-rake (0.5.1)
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
- rubocop-ast (>= 1.1.0)
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)
@@ -85,22 +84,24 @@ GEM
85
84
  simplecov_json_formatter (~> 0.1)
86
85
  simplecov-html (0.12.3)
87
86
  simplecov_json_formatter (0.1.2)
88
- smart_engine (0.11.0)
89
- smart_types (0.4.0)
87
+ smart_engine (0.12.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.7.0)
95
- zeitwerk (2.4.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
+ x86_64-linux
99
100
 
100
101
  DEPENDENCIES
101
- armitage-rubocop (~> 1.7)
102
+ armitage-rubocop (~> 1.23)
102
103
  bundler (~> 2.2)
103
- pry (~> 0.13)
104
+ pry (~> 0.14)
104
105
  rake (~> 13.0)
105
106
  rspec (~> 3.10)
106
107
  simplecov (~> 0.21)
@@ -108,4 +109,4 @@ DEPENDENCIES
108
109
  thy (~> 0.1.4)
109
110
 
110
111
  BUNDLED WITH
111
- 2.2.3
112
+ 2.2.32
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- smart_initializer (0.5.0)
4
+ smart_initializer (0.9.1)
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 (6.1.1)
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
- zeitwerk (~> 2.3)
18
- armitage-rubocop (1.7.0.1)
19
- rubocop (= 1.7.0)
20
- rubocop-performance (= 1.9.1)
21
- rubocop-rails (= 2.9.1)
22
- rubocop-rake (= 0.5.1)
23
- rubocop-rspec (= 2.1.0)
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.7)
25
+ concurrent-ruby (1.1.9)
27
26
  diff-lcs (1.4.4)
28
27
  docile (1.3.5)
29
- i18n (1.8.7)
28
+ i18n (1.8.11)
30
29
  concurrent-ruby (~> 1.0)
31
30
  method_source (1.0.0)
32
- minitest (5.14.3)
33
- parallel (1.20.1)
34
- parser (3.0.0.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.13.1)
35
+ pry (0.14.1)
37
36
  coderay (~> 1.1)
38
37
  method_source (~> 1.0)
39
- qonfig (0.25.0)
38
+ qonfig (0.27.0)
40
39
  rack (2.2.3)
41
40
  rainbow (3.0.0)
42
41
  rake (13.0.3)
43
- regexp_parser (2.0.3)
44
- rexml (3.2.4)
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.7.0)
57
+ rubocop (1.23.0)
59
58
  parallel (~> 1.10)
60
- parser (>= 2.7.1.5)
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.2.0, < 2.0)
63
+ rubocop-ast (>= 1.12.0, < 2.0)
65
64
  ruby-progressbar (~> 1.7)
66
- unicode-display_width (>= 1.4.0, < 2.0)
67
- rubocop-ast (1.4.0)
68
- parser (>= 2.7.1.5)
69
- rubocop-performance (1.9.1)
70
- rubocop (>= 0.90.0, < 2.0)
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.9.1)
71
+ rubocop-rails (2.12.4)
73
72
  activesupport (>= 4.2.0)
74
73
  rack (>= 1.1)
75
- rubocop (>= 0.90.0, < 2.0)
76
- rubocop-rake (0.5.1)
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
- rubocop-ast (>= 1.1.0)
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,26 @@ 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.11.0)
89
- smart_types (0.4.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.7.0)
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
96
+ x86_64-linux
98
97
 
99
98
  DEPENDENCIES
100
- armitage-rubocop (~> 1.7)
99
+ armitage-rubocop (~> 1.23)
101
100
  bundler (~> 2.2)
102
- pry (~> 0.13)
101
+ pry (~> 0.14)
103
102
  rake (~> 13.0)
104
103
  rspec (~> 3.10)
105
104
  simplecov (~> 0.21)
106
105
  smart_initializer!
107
106
 
108
107
  BUNDLED WITH
109
- 2.2.3
108
+ 2.2.32
@@ -0,0 +1,154 @@
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
+ # @version 0.9.1
85
+ def prepare_finalize_param(finalize)
86
+ unless finalize.is_a?(::String) || finalize.is_a?(::Symbol) || finalize.is_a?(::Proc)
87
+ raise(SmartCore::Initializer::ArgumentError, <<~ERROR_MESSAGE)
88
+ Attribute finalizer should be a type of String, Symbol or Proc
89
+ ERROR_MESSAGE
90
+ end
91
+
92
+ # rubocop:disable Style/SoleNestedConditional
93
+ if finalize.is_a?(::Proc) && finalize.lambda?
94
+ unless allowed_lambda_arity.bsearch { |element| finalize.arity <=> element }
95
+ raise(
96
+ SmartCore::Initializer::ArgumentError,
97
+ "Lambda-based finalizer should have arity " \
98
+ "equal to #{allowed_lambda_arity.join(', ')} " \
99
+ "(your lambda object should require one attribute)"
100
+ ) # TODO: show the name of attribute in error message (if the name is a valid, of course)
101
+ end
102
+ end
103
+ # rubocop:enable Style/SoleNestedConditional
104
+
105
+ SmartCore::Initializer::Attribute::Finalizer.create(finalize)
106
+ end
107
+
108
+ # return [Array<Integer>]
109
+ # @api private
110
+ # @since 0.9.1
111
+ def allowed_lambda_arity
112
+ @allowed_lambda_arity ||= [-2, -1, 1].freeze
113
+ end
114
+
115
+ # @param mutable [Boolean]
116
+ # @return [Boolean]
117
+ #
118
+ # @api private
119
+ # @since 0.4.0
120
+ def prepare_mutable_param(mutable)
121
+ unless mutable.is_a?(::FalseClass) || mutable.is_a?(::TrueClass)
122
+ raise(SmartCore::Initializer::ArgumentError, <<~ERROR_MESSAGE)
123
+ :mutable attribute should be a type of boolean
124
+ ERROR_MESSAGE
125
+ end
126
+
127
+ mutable
128
+ end
129
+
130
+ # @param as [String, Symbol, NilClass]
131
+ # @return [String, Symbol, NilClass]
132
+ #
133
+ # @api private
134
+ # @since 0.4.0
135
+ def preapre_as_param(as)
136
+ unless as.is_a?(::NilClass) || as.is_a?(::String) || as.is_a?(::Symbol)
137
+ raise(SmartCore::Initializer::ArgumentError, <<~ERROR_MESSAGE)
138
+ Attribute alias should be a type of String or Symbol
139
+ ERROR_MESSAGE
140
+ end
141
+
142
+ as
143
+ end
144
+
145
+ # @param type_system [String, Symbol]
146
+ # @return [Class<SmartCore::Initializer::TypeSystem::Interop>]
147
+ #
148
+ # @api private
149
+ # @since 0.8.0
150
+ def prepare_type_system_param(type_system)
151
+ SmartCore::Initializer::TypeSystem.resolve(type_system)
152
+ end
153
+ end
154
+ 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