smart_initializer 0.1.0.alpha2 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +1 -1
  3. data/.travis.yml +36 -5
  4. data/CHANGELOG.md +15 -0
  5. data/Gemfile.lock +63 -43
  6. data/README.md +263 -11
  7. data/Rakefile +1 -1
  8. data/bin/rspec +54 -0
  9. data/gemfiles/with_external_deps.gemfile +7 -0
  10. data/gemfiles/with_external_deps.gemfile.lock +102 -0
  11. data/gemfiles/without_external_deps.gemfile +5 -0
  12. data/gemfiles/without_external_deps.gemfile.lock +100 -0
  13. data/lib/smart_core/initializer.rb +44 -28
  14. data/lib/smart_core/initializer/attribute.rb +12 -5
  15. data/lib/smart_core/initializer/attribute/factory.rb +47 -27
  16. data/lib/smart_core/initializer/attribute/parameters.rb +12 -4
  17. data/lib/smart_core/initializer/configuration.rb +33 -0
  18. data/lib/smart_core/initializer/constructor.rb +60 -23
  19. data/lib/smart_core/initializer/{attribute → constructor}/definer.rb +64 -12
  20. data/lib/smart_core/initializer/dsl.rb +47 -10
  21. data/lib/smart_core/initializer/dsl/inheritance.rb +1 -0
  22. data/lib/smart_core/initializer/errors.rb +44 -0
  23. data/lib/smart_core/initializer/extensions.rb +9 -0
  24. data/lib/smart_core/initializer/extensions/abstract.rb +8 -0
  25. data/lib/smart_core/initializer/extensions/ext_init.rb +31 -0
  26. data/lib/smart_core/initializer/extensions/list.rb +74 -0
  27. data/lib/smart_core/initializer/functionality.rb +36 -0
  28. data/lib/smart_core/initializer/instance_attribute_accessing.rb +51 -0
  29. data/lib/smart_core/initializer/plugins.rb +17 -0
  30. data/lib/smart_core/initializer/plugins/abstract.rb +55 -0
  31. data/lib/smart_core/initializer/plugins/access_mixin.rb +47 -0
  32. data/lib/smart_core/initializer/plugins/registry.rb +166 -0
  33. data/lib/smart_core/initializer/plugins/registry_interface.rb +77 -0
  34. data/lib/smart_core/initializer/plugins/thy_types.rb +30 -0
  35. data/lib/smart_core/initializer/plugins/thy_types/errors.rb +11 -0
  36. data/lib/smart_core/initializer/plugins/thy_types/thy_types.rb +23 -0
  37. data/lib/smart_core/initializer/plugins/thy_types/thy_types/abstract_factory.rb +78 -0
  38. data/lib/smart_core/initializer/plugins/thy_types/thy_types/operation.rb +12 -0
  39. data/lib/smart_core/initializer/plugins/thy_types/thy_types/operation/base.rb +9 -0
  40. data/lib/smart_core/initializer/plugins/thy_types/thy_types/operation/cast.rb +21 -0
  41. data/lib/smart_core/initializer/plugins/thy_types/thy_types/operation/valid.rb +16 -0
  42. data/lib/smart_core/initializer/plugins/thy_types/thy_types/operation/validate.rb +19 -0
  43. data/lib/smart_core/initializer/settings.rb +49 -0
  44. data/lib/smart_core/initializer/settings/duplicator.rb +20 -0
  45. data/lib/smart_core/initializer/settings/type_system.rb +69 -0
  46. data/lib/smart_core/initializer/type_system.rb +16 -0
  47. data/lib/smart_core/initializer/type_system/interop.rb +103 -0
  48. data/lib/smart_core/initializer/type_system/interop/abstract_factory.rb +70 -0
  49. data/lib/smart_core/initializer/type_system/interop/aliasing.rb +72 -0
  50. data/lib/smart_core/initializer/type_system/interop/aliasing/alias_list.rb +141 -0
  51. data/lib/smart_core/initializer/type_system/interop/operation.rb +30 -0
  52. data/lib/smart_core/initializer/type_system/registry.rb +174 -0
  53. data/lib/smart_core/initializer/type_system/registry_interface.rb +102 -0
  54. data/lib/smart_core/initializer/type_system/smart_types.rb +48 -0
  55. data/lib/smart_core/initializer/type_system/smart_types/abstract_factory.rb +72 -0
  56. data/lib/smart_core/initializer/type_system/smart_types/operation.rb +13 -0
  57. data/lib/smart_core/initializer/type_system/smart_types/operation/base.rb +8 -0
  58. data/lib/smart_core/initializer/type_system/smart_types/operation/cast.rb +16 -0
  59. data/lib/smart_core/initializer/type_system/smart_types/operation/valid.rb +16 -0
  60. data/lib/smart_core/initializer/type_system/smart_types/operation/validate.rb +16 -0
  61. data/lib/smart_core/initializer/version.rb +2 -1
  62. data/smart_initializer.gemspec +13 -9
  63. metadata +73 -17
  64. data/lib/smart_core/initializer/type_aliasing.rb +0 -50
  65. data/lib/smart_core/initializer/type_aliasing/alias_list.rb +0 -101
@@ -43,12 +43,18 @@ class SmartCore::Initializer::Attribute::Parameters
43
43
  # @since 0.1.0
44
44
  attr_reader :name
45
45
 
46
- # @return [SmartCore::Types::Primitive]
46
+ # @return [SmartCore::Initializer::TypeSystem::Interop]
47
47
  #
48
48
  # @api private
49
49
  # @since 0.1.0
50
50
  attr_reader :type
51
51
 
52
+ # @return [Class<SmartCore::Initilizer::TypeSystem::Interop>]
53
+ #
54
+ # @api private
55
+ # @since 0.1.0
56
+ attr_reader :type_system
57
+
52
58
  # @return [Symbol]
53
59
  #
54
60
  # @api private
@@ -76,7 +82,8 @@ class SmartCore::Initializer::Attribute::Parameters
76
82
  attr_reader :dynamic_options
77
83
 
78
84
  # @param name [Symbol]
79
- # @param type [SmartCore::Types::Primitive]
85
+ # @param type [SmartCore::Initializer::TypeSystem::Interop]
86
+ # @param type_system [Class<SmartCore::Initializer::TypeSystem::Interop>]
80
87
  # @param privacy [Symbol]
81
88
  # @param finalizer [SmartCore::Initializer::Attribute::AnonymousBlock/InstanceMethod]
82
89
  # @param cast [Boolean]
@@ -86,9 +93,10 @@ class SmartCore::Initializer::Attribute::Parameters
86
93
  #
87
94
  # @api private
88
95
  # @since 0.1.0
89
- def initialize(name, type, privacy, finalizer, cast, dynamic_options)
96
+ def initialize(name, type, type_system, privacy, finalizer, cast, dynamic_options)
90
97
  @name = name
91
98
  @type = type
99
+ @type_system = type_system
92
100
  @privacy = privacy
93
101
  @finalizer = finalizer
94
102
  @cast = cast
@@ -116,6 +124,6 @@ class SmartCore::Initializer::Attribute::Parameters
116
124
  ERROR_MESSAGE
117
125
  end
118
126
 
119
- defalut_value.is_a?(Proc) ? default_value.call : default_value
127
+ default_value.is_a?(Proc) ? default_value.call : default_value
120
128
  end
121
129
  end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'qonfig'
4
+
5
+ # @api public
6
+ # @since 0.1.0
7
+ module SmartCore::Initializer::Configuration
8
+ # @since 0.1.0
9
+ include Qonfig::Configurable
10
+
11
+ # @api public
12
+ # @since 0.1.0
13
+ extend SmartCore::Initializer::Plugins::AccessMixin
14
+
15
+ class << self
16
+ # @param setting_key [String, Symbol]
17
+ # @return [Qonfig::Settings, Any]
18
+ #
19
+ # @api private
20
+ # @since 0.1.0
21
+ def [](setting_key)
22
+ config[setting_key]
23
+ end
24
+ end
25
+
26
+ # @since 0.1.0
27
+ configuration do
28
+ setting :default_type_system, :smart_types
29
+ validate :default_type_system do |value|
30
+ SmartCore::Initializer::TypeSystem.resolve(value) rescue false
31
+ end
32
+ end
33
+ end
@@ -3,6 +3,8 @@
3
3
  # @api private
4
4
  # @since 0.1.0
5
5
  class SmartCore::Initializer::Constructor
6
+ require_relative 'constructor/definer'
7
+
6
8
  # @param klass [Class<SmartCore::Initializer>]
7
9
  # @param arguments [Array<Any>]
8
10
  # @param block [Proc, NilClass]
@@ -13,8 +15,8 @@ class SmartCore::Initializer::Constructor
13
15
  def initialize(klass, arguments, block)
14
16
  @klass = klass
15
17
  @arguments = arguments
16
- @passed_parameters, @passed_options = extract_attributes(arguments)
17
- @passed_block = block
18
+ @parameters, @options = extract_attributes(arguments)
19
+ @block = block
18
20
  end
19
21
 
20
22
  # @return [Any]
@@ -26,6 +28,8 @@ class SmartCore::Initializer::Constructor
26
28
  prevent_attribute_insufficiency
27
29
  initialize_parameters(instance)
28
30
  initialize_options(instance)
31
+ process_original_initializer(instance)
32
+ process_init_extensions(instance)
29
33
  end
30
34
  end
31
35
 
@@ -47,19 +51,19 @@ class SmartCore::Initializer::Constructor
47
51
  #
48
52
  # @api private
49
53
  # @since 0.1.0
50
- attr_reader :passed_parameters
54
+ attr_reader :parameters
51
55
 
52
56
  # @return [Hash<Symbol,Any>]
53
57
  #
54
58
  # @api private
55
59
  # @since 0.1.0
56
- attr_reader :passed_options
60
+ attr_reader :options
57
61
 
58
62
  # @return [Proc, NilClass]
59
63
  #
60
64
  # @api private
61
65
  # @since 0.1.0
62
- attr_reader :passed_block
66
+ attr_reader :block
63
67
 
64
68
  # @return [void]
65
69
  #
@@ -68,23 +72,33 @@ class SmartCore::Initializer::Constructor
68
72
  #
69
73
  # @api private
70
74
  # @since 0.1.0
75
+ # rubocop:disable Metrics/AbcSize
71
76
  def prevent_attribute_insufficiency
72
- required_options = klass.__options__.reject(&:has_default?).map(&:name)
73
77
  required_parameter_count = klass.__params__.size
74
78
 
75
79
  raise(
76
80
  SmartCore::Initializer::ParameterArgumentError,
77
81
  "Wrong number of parameters " \
78
- "(given #{passed_parameters.size}, expected #{required_parameter_count})"
79
- ) unless passed_parameters.size == required_parameter_count
82
+ "(given #{parameters.size}, expected #{required_parameter_count})"
83
+ ) unless parameters.size == required_parameter_count
80
84
 
81
- missing_options = required_options.reject { |option| passed_options.key?(option) }
85
+ required_options = klass.__options__.reject(&:has_default?).map(&:name)
86
+ missing_options = required_options.reject { |option| options.key?(option) }
82
87
 
83
88
  raise(
84
89
  SmartCore::Initializer::OptionArgumentError,
85
90
  "Missing options: #{missing_options.join(', ')}"
86
91
  ) if missing_options.any?
92
+
93
+ possible_options = klass.__options__.map(&:name)
94
+ unknown_options = options.keys - possible_options
95
+
96
+ raise(
97
+ SmartCore::Initializer::OptionArgumentError,
98
+ "Unknown options: #{unknown_options.join(', ')}"
99
+ ) if unknown_options.any?
87
100
  end
101
+ # rubocop:enable Metrics/AbcSize
88
102
 
89
103
  # @return [Any]
90
104
  #
@@ -100,13 +114,13 @@ class SmartCore::Initializer::Constructor
100
114
  # @api private
101
115
  # @since 0.1.0
102
116
  def initialize_parameters(instance)
103
- parameter_definitions = Hash[klass.__params__.zip(passed_parameters)]
117
+ parameter_definitions = Hash[klass.__params__.zip(parameters)]
104
118
 
105
119
  parameter_definitions.each_pair do |attribute, parameter_value|
106
- parameter_value = attribute.type.cast(parameter_value) if attribute.cast?
120
+ if !attribute.type.valid?(parameter_value) && attribute.cast?
121
+ parameter_value = attribute.type.cast(parameter_value)
122
+ end
107
123
 
108
- # TODO: fail with SmartCore::Initializer::ArgumentError
109
- # (isntead of SmartCore::Types::TypeError)
110
124
  attribute.type.validate!(parameter_value)
111
125
 
112
126
  final_value = attribute.finalizer.call(parameter_value, instance)
@@ -119,19 +133,42 @@ class SmartCore::Initializer::Constructor
119
133
  #
120
134
  # @api private
121
135
  # @since 0.1.0
136
+ # rubocop:disable Metrics/AbcSize
122
137
  def initialize_options(instance)
123
138
  klass.__options__.each do |attribute|
124
- option_value = passed_options.fetch(attribute.name) { attribute.default }
125
- option_value = attribute.type.cast(option_value) if attribute.cast?
139
+ option_value = options.fetch(attribute.name) { attribute.default }
140
+
141
+ if !attribute.type.valid?(option_value) && attribute.cast?
142
+ option_value = attribute.type.cast(option_value)
143
+ end
126
144
 
127
- # TODO: fail with SmartCore::Initializer::ArgumentError
128
- # (isntead of SmartCore::Types::TypeError)
129
145
  attribute.type.validate!(option_value)
130
146
 
131
147
  final_value = attribute.finalizer.call(option_value, instance)
132
148
  instance.instance_variable_set("@#{attribute.name}", final_value)
133
149
  end
134
150
  end
151
+ # rubocop:enable Metrics/AbcSize
152
+
153
+ # @param instance [Any]
154
+ # @return [void]
155
+ #
156
+ # @api private
157
+ # @since 0.1.0
158
+ def process_original_initializer(instance)
159
+ instance.send(:initialize, *arguments, &block)
160
+ end
161
+
162
+ # @param instance [Any]
163
+ # @return [void]
164
+ #
165
+ # @api private
166
+ # @since 0.1.0
167
+ def process_init_extensions(instance)
168
+ klass.__init_extensions__.each do |extension|
169
+ extension.call(instance)
170
+ end
171
+ end
135
172
 
136
173
  # @param arguments [Array<Any>]
137
174
  # @return [Array<Array<Any>,Hash<Symbol,Any>>]
@@ -139,20 +176,20 @@ class SmartCore::Initializer::Constructor
139
176
  # @api private
140
177
  # @since 0.1.0
141
178
  def extract_attributes(arguments)
142
- parameters = []
143
- options = {}
179
+ extracted_parameters = []
180
+ extracted_options = {}
144
181
 
145
182
  if (
146
183
  klass.__options__.size >= 1 &&
147
184
  arguments.last.is_a?(Hash) &&
148
185
  arguments.last.keys.all? { |key| key.is_a?(Symbol) }
149
186
  )
150
- parameters = arguments[0..-2]
151
- options = arguments.last
187
+ extracted_parameters = arguments[0..-2]
188
+ extracted_options = arguments.last
152
189
  else
153
- parameters = arguments
190
+ extracted_parameters = arguments
154
191
  end
155
192
 
156
- [parameters, options]
193
+ [extracted_parameters, extracted_options]
157
194
  end
158
195
  end
@@ -2,7 +2,8 @@
2
2
 
3
3
  # @api private
4
4
  # @since 0.1.0
5
- class SmartCore::Initializer::Attribute::Definer
5
+ # rubocop:disable Metrics/ClassLength
6
+ class SmartCore::Initializer::Constructor::Definer
6
7
  # @param klass [Class]
7
8
  # @return [void]
8
9
  #
@@ -13,8 +14,20 @@ class SmartCore::Initializer::Attribute::Definer
13
14
  @lock = SmartCore::Engine::Lock.new
14
15
  end
15
16
 
17
+ # @param block [Proc]
18
+ # @return [void]
19
+ #
20
+ # @api private
21
+ # @since 0.1.0
22
+ def define_init_extension(block)
23
+ thread_safe do
24
+ add_init_extension(build_init_extension(block))
25
+ end
26
+ end
27
+
16
28
  # @param name [String, Symbol]
17
- # @param type [String, Symbol, SmartCore::Types::Primitive]
29
+ # @param type [String, Symbol, Any]
30
+ # @param type_system [String, Symbol]
18
31
  # @param privacy [String, Symbol]
19
32
  # @param finalize [String, Symbol, Proc]
20
33
  # @param cast [Boolean]
@@ -23,9 +36,17 @@ class SmartCore::Initializer::Attribute::Definer
23
36
  #
24
37
  # @api private
25
38
  # @since 0.1.0
26
- def define_parameter(name, type, privacy, finalize, cast, dynamic_options)
39
+ def define_parameter(name, type, type_system, privacy, finalize, cast, dynamic_options)
27
40
  thread_safe do
28
- attribute = build_attribute(name, type, privacy, finalize, cast, dynamic_options)
41
+ attribute = build_attribute(
42
+ name,
43
+ type,
44
+ type_system,
45
+ privacy,
46
+ finalize,
47
+ cast,
48
+ dynamic_options
49
+ )
29
50
  prevent_option_overlap(attribute)
30
51
  add_parameter(attribute)
31
52
  end
@@ -41,7 +62,8 @@ class SmartCore::Initializer::Attribute::Definer
41
62
  names.map do |name|
42
63
  build_attribute(
43
64
  name,
44
- SmartCore::Types::Value::Any,
65
+ klass.__initializer_settings__.generic_type_object,
66
+ klass.__initializer_settings__.type_system,
45
67
  SmartCore::Initializer::Attribute::Parameters::DEFAULT_PRIVACY_MODE,
46
68
  SmartCore::Initializer::Attribute::Parameters::DEFAULT_FINALIZER,
47
69
  SmartCore::Initializer::Attribute::Parameters::DEFAULT_CAST_BEHAVIOUR,
@@ -56,7 +78,8 @@ class SmartCore::Initializer::Attribute::Definer
56
78
  end
57
79
 
58
80
  # @param name [String, Symbol]
59
- # @param type [String, Symbol, SmartCore::Types::Primitive]
81
+ # @param type [String, Symbol, Any]
82
+ # @param type_system [String, Symbol]
60
83
  # @param privacy [String, Symbol]
61
84
  # @param finalize [String, Symbol, Proc]
62
85
  # @param cast [Boolean]
@@ -65,9 +88,17 @@ class SmartCore::Initializer::Attribute::Definer
65
88
  #
66
89
  # @api private
67
90
  # @since 0.1.0
68
- def define_option(name, type, privacy, finalize, cast, dynamic_options)
91
+ def define_option(name, type, type_system, privacy, finalize, cast, dynamic_options)
69
92
  thread_safe do
70
- attribute = build_attribute(name, type, privacy, finalize, cast, dynamic_options)
93
+ attribute = build_attribute(
94
+ name,
95
+ type,
96
+ type_system,
97
+ privacy,
98
+ finalize,
99
+ cast,
100
+ dynamic_options
101
+ )
71
102
  prevent_parameter_overlap(attribute)
72
103
  add_option(attribute)
73
104
  end
@@ -83,7 +114,8 @@ class SmartCore::Initializer::Attribute::Definer
83
114
  names.map do |name|
84
115
  build_attribute(
85
116
  name,
86
- SmartCore::Types::Value::Any,
117
+ klass.__initializer_settings__.generic_type_object,
118
+ klass.__initializer_settings__.type_system,
87
119
  SmartCore::Initializer::Attribute::Parameters::DEFAULT_PRIVACY_MODE,
88
120
  SmartCore::Initializer::Attribute::Parameters::DEFAULT_FINALIZER,
89
121
  SmartCore::Initializer::Attribute::Parameters::DEFAULT_CAST_BEHAVIOUR,
@@ -106,7 +138,8 @@ class SmartCore::Initializer::Attribute::Definer
106
138
  attr_reader :klass
107
139
 
108
140
  # @param name [String, Symbol]
109
- # @param type [String, Symbol, SmartCore::Types::Primitive]
141
+ # @param type [String, Symbol, Any]
142
+ # @param type_system [String, Symbol]
110
143
  # @param privacy [String, Symbol]
111
144
  # @param finalize [String, Symbol, Proc]
112
145
  # @param cast [Boolean]
@@ -115,12 +148,21 @@ class SmartCore::Initializer::Attribute::Definer
115
148
  #
116
149
  # @api private
117
150
  # @since 0.1.0
118
- def build_attribute(name, type, privacy, finalize, cast, dynamic_options)
151
+ def build_attribute(name, type, type_system, privacy, finalize, cast, dynamic_options)
119
152
  SmartCore::Initializer::Attribute::Factory.create(
120
- name, type, privacy, finalize, cast, dynamic_options
153
+ name, type, type_system, privacy, finalize, cast, dynamic_options
121
154
  )
122
155
  end
123
156
 
157
+ # @param block [Proc]
158
+ # @return [SmartCore::Initializer::Extensions::ExtInit]
159
+ #
160
+ # @api private
161
+ # @since 0.1.0
162
+ def build_init_extension(block)
163
+ SmartCore::Initializer::Extensions::ExtInit.new(block)
164
+ end
165
+
124
166
  # @param parameter [SmartCore::Initializer::Attribute]
125
167
  # @return [void]
126
168
  #
@@ -143,6 +185,15 @@ class SmartCore::Initializer::Attribute::Definer
143
185
  klass.send(option.privacy, option.name)
144
186
  end
145
187
 
188
+ # @param extension [SmartCore::Initializer::Extensions::ExtInit]
189
+ # @return [void]
190
+ #
191
+ # @api private
192
+ # @since 0.1.0
193
+ def add_init_extension(extension)
194
+ klass.__init_extensions__ << extension
195
+ end
196
+
146
197
  # @param parameter [SmartCore::Initializer::Attribute]
147
198
  # @return [void]
148
199
  #
@@ -178,3 +229,4 @@ class SmartCore::Initializer::Attribute::Definer
178
229
  @lock.synchronize(&block)
179
230
  end
180
231
  end
232
+ # rubocop:enable Metrics/ClassLength
@@ -13,10 +13,12 @@ module SmartCore::Initializer::DSL
13
13
  # @since 0.1.0
14
14
  def extended(base_klass)
15
15
  base_klass.instance_eval do
16
- instance_variable_set(:@__params__, SmartCore::Initializer::Attribute::List.new)
16
+ instance_variable_set(:@__params__, SmartCore::Initializer::Attribute::List.new)
17
17
  instance_variable_set(:@__options__, SmartCore::Initializer::Attribute::List.new)
18
- instance_variable_set(:@__definer__, SmartCore::Initializer::Attribute::Definer.new(self))
18
+ instance_variable_set(:@__init_extensions__, SmartCore::Initializer::Extensions::List.new)
19
+ instance_variable_set(:@__definer__, SmartCore::Initializer::Constructor::Definer.new(self))
19
20
  instance_variable_set(:@__deflock__, SmartCore::Engine::Lock.new)
21
+ instance_variable_set(:@__initializer_settings__, SmartCore::Initializer::Settings.new)
20
22
  end
21
23
  base_klass.extend(ClassMethods)
22
24
  base_klass.singleton_class.prepend(ClassInheritance)
@@ -33,10 +35,12 @@ module SmartCore::Initializer::DSL
33
35
  # @since 0.1.0
34
36
  def inherited(child_klass)
35
37
  child_klass.instance_eval do
36
- instance_variable_set(:@__params__, SmartCore::Initializer::Attribute::List.new)
38
+ instance_variable_set(:@__params__, SmartCore::Initializer::Attribute::List.new)
37
39
  instance_variable_set(:@__options__, SmartCore::Initializer::Attribute::List.new)
38
- instance_variable_set(:@__definer__, SmartCore::Initializer::Attribute::Definer.new(self))
40
+ instance_variable_set(:@__init_extensions__, SmartCore::Initializer::Extensions::List.new)
41
+ instance_variable_set(:@__definer__, SmartCore::Initializer::Constructor::Definer.new(self))
39
42
  instance_variable_set(:@__deflock__, SmartCore::Engine::Lock.new)
43
+ instance_variable_set(:@__initializer_settings__, __initializer_settings__.dup)
40
44
  end
41
45
  child_klass.extend(ClassMethods)
42
46
  SmartCore::Initializer::DSL::Inheritance.inherit(base: self, child: child_klass)
@@ -63,6 +67,14 @@ module SmartCore::Initializer::DSL
63
67
  @__options__
64
68
  end
65
69
 
70
+ # @return [SmartCore::Initializer::Extentions::List]
71
+ #
72
+ # @api private
73
+ # @since 0.1.0
74
+ def __init_extensions__
75
+ @__init_extensions__
76
+ end
77
+
66
78
  # @return [SmartCore::Initializer::Attribute::Definer]
67
79
  #
68
80
  # @api private
@@ -71,6 +83,14 @@ module SmartCore::Initializer::DSL
71
83
  @__definer__
72
84
  end
73
85
 
86
+ # @return [SmartCore::Initializer::Settings]
87
+ #
88
+ # @api private
89
+ # @since 0.1.0
90
+ def __initializer_settings__
91
+ @__initializer_settings__
92
+ end
93
+
74
94
  # @param arguments [Array]
75
95
  # @param block [Block]
76
96
  # @return [Any]
@@ -82,7 +102,7 @@ module SmartCore::Initializer::DSL
82
102
  end
83
103
 
84
104
  # @param name [String, Symbol]
85
- # @param type [String, Symbol, SmartCore::Types::Primitive]
105
+ # @param type [String, Symbol, Any]
86
106
  # @option cast [Boolean]
87
107
  # @option privacy [String, Symbol]
88
108
  # @option finalize [String, Symbol, Proc]
@@ -93,13 +113,16 @@ module SmartCore::Initializer::DSL
93
113
  # @since 0.1.0
94
114
  def param(
95
115
  name,
96
- type = SmartCore::Types::Value::Any,
116
+ type = __initializer_settings__.generic_type_object,
97
117
  privacy: SmartCore::Initializer::Attribute::Parameters::DEFAULT_PRIVACY_MODE,
98
118
  finalize: SmartCore::Initializer::Attribute::Parameters::DEFAULT_FINALIZER,
99
119
  cast: SmartCore::Initializer::Attribute::Parameters::DEFAULT_CAST_BEHAVIOUR,
120
+ type_system: __initializer_settings__.type_system,
100
121
  **dynamic_options
101
122
  )
102
- __definer__.define_parameter(name, type, privacy, finalize, cast, dynamic_options)
123
+ __definer__.define_parameter(
124
+ name, type, type_system, privacy, finalize, cast, dynamic_options
125
+ )
103
126
  end
104
127
 
105
128
  # @param names [Array<String, Symbol>]
@@ -112,10 +135,11 @@ module SmartCore::Initializer::DSL
112
135
  end
113
136
 
114
137
  # @param name [String, Symbol]
115
- # @param type [String, Symbol, SmartCore::Types::Primitive]
138
+ # @param type [String, Symbol, Any]
116
139
  # @option cast [Boolean]
117
140
  # @option privacy [String, Symbol]
118
141
  # @option finalize [String, Symbol, Proc]
142
+ # @option type_system [String, Symbol]
119
143
  # @param dynamic_options [Hash<Symbol,Any>]
120
144
  # @return [void]
121
145
  #
@@ -123,13 +147,16 @@ module SmartCore::Initializer::DSL
123
147
  # @since 0.1.0
124
148
  def option(
125
149
  name,
126
- type = SmartCore::Types::Value::Any,
150
+ type = __initializer_settings__.generic_type_object,
127
151
  privacy: SmartCore::Initializer::Attribute::Parameters::DEFAULT_PRIVACY_MODE,
128
152
  finalize: SmartCore::Initializer::Attribute::Parameters::DEFAULT_FINALIZER,
129
153
  cast: SmartCore::Initializer::Attribute::Parameters::DEFAULT_CAST_BEHAVIOUR,
154
+ type_system: __initializer_settings__.type_system,
130
155
  **dynamic_options
131
156
  )
132
- __definer__.define_option(name, type, privacy, finalize, cast, dynamic_options)
157
+ __definer__.define_option(
158
+ name, type, type_system, privacy, finalize, cast, dynamic_options
159
+ )
133
160
  end
134
161
 
135
162
  # @param names [Array<String, Symbol>]
@@ -140,5 +167,15 @@ module SmartCore::Initializer::DSL
140
167
  def options(*names)
141
168
  __definer__.define_options(*names)
142
169
  end
170
+
171
+ # @param block [Block]
172
+ # @return [void]
173
+ #
174
+ # @api public
175
+ # @since 0.1.0
176
+ def ext_init(&block)
177
+ __definer__.define_init_extension(block)
178
+ end
179
+ alias_method :extend_initialization_flow, :ext_init
143
180
  end
144
181
  end