smart_initializer 0.7.0 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +1 -1
  3. data/CHANGELOG.md +35 -3
  4. data/Gemfile.lock +38 -38
  5. data/README.md +260 -46
  6. data/bin/console +2 -2
  7. data/gemfiles/with_external_deps.gemfile.lock +38 -38
  8. data/lib/smart_core/initializer/attribute/factory/base.rb +145 -0
  9. data/lib/smart_core/initializer/attribute/factory/option.rb +107 -0
  10. data/lib/smart_core/initializer/attribute/factory/param.rb +63 -0
  11. data/lib/smart_core/initializer/attribute/factory.rb +5 -199
  12. data/lib/smart_core/initializer/attribute/finalizer/abstract.rb +2 -0
  13. data/lib/smart_core/initializer/attribute/finalizer/instance_method.rb +1 -1
  14. data/lib/smart_core/initializer/attribute/finalizer.rb +5 -5
  15. data/lib/smart_core/initializer/attribute/list.rb +20 -0
  16. data/lib/smart_core/initializer/attribute/{parameters.rb → value/base.rb} +35 -65
  17. data/lib/smart_core/initializer/attribute/value/option.rb +101 -0
  18. data/lib/smart_core/initializer/attribute/value/param.rb +24 -0
  19. data/lib/smart_core/initializer/attribute/value.rb +9 -0
  20. data/lib/smart_core/initializer/attribute.rb +3 -125
  21. data/lib/smart_core/initializer/configuration.rb +7 -3
  22. data/lib/smart_core/initializer/constructor/definer.rb +135 -46
  23. data/lib/smart_core/initializer/constructor.rb +30 -12
  24. data/lib/smart_core/initializer/dsl.rb +38 -24
  25. data/lib/smart_core/initializer/errors.rb +20 -4
  26. data/lib/smart_core/initializer/functionality.rb +7 -8
  27. data/lib/smart_core/initializer/settings/auto_cast.rb +40 -0
  28. data/lib/smart_core/initializer/settings/base.rb +49 -0
  29. data/lib/smart_core/initializer/settings/duplicator.rb +5 -0
  30. data/lib/smart_core/initializer/settings/strict_options.rb +40 -0
  31. data/lib/smart_core/initializer/settings/type_system.rb +10 -28
  32. data/lib/smart_core/initializer/settings.rb +40 -0
  33. data/lib/smart_core/initializer/type_system/registry.rb +2 -1
  34. data/lib/smart_core/initializer/type_system/smart_types.rb +2 -2
  35. data/lib/smart_core/initializer/version.rb +2 -2
  36. data/lib/smart_core/initializer.rb +14 -4
  37. data/smart_initializer.gemspec +2 -2
  38. metadata +16 -7
@@ -9,11 +9,16 @@ module SmartCore::Initializer::Settings::Duplicator
9
9
  #
10
10
  # @api private
11
11
  # @since 0.1.0
12
+ # @version 0.8.0
12
13
  def duplicate(settings)
13
14
  SmartCore::Initializer::Settings.new.tap do |new_instance|
14
15
  type_system = settings.instance_variable_get(:@type_system).dup
16
+ strict_options = settings.instance_variable_get(:@strict_options).dup
17
+ auto_cast = settings.instance_variable_get(:@auto_cast).dup
15
18
 
16
19
  new_instance.instance_variable_set(:@type_system, type_system)
20
+ new_instance.instance_variable_set(:@strict_options, strict_options)
21
+ new_instance.instance_variable_set(:@auto_cast, auto_cast)
17
22
  end
18
23
  end
19
24
  end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ # @api private
4
+ # @since 0.8.0
5
+ class SmartCore::Initializer::Settings::StrictOptions < SmartCore::Initializer::Settings::Base
6
+ # @return [void]
7
+ #
8
+ # @api private
9
+ # @since 0.8.0
10
+ def initialize
11
+ @value = nil
12
+ @lock = SmartCore::Engine::Lock.new
13
+ end
14
+
15
+ # @return [Boolean]
16
+ #
17
+ # @api private
18
+ # @since 0.8.0
19
+ def resolve
20
+ thread_safe do
21
+ @value == nil ? SmartCore::Initializer::Configuration[:strict_options] : @value
22
+ end
23
+ end
24
+
25
+ # @param value [Boolean]
26
+ # @return [void]
27
+ #
28
+ # @api private
29
+ # @since 0.8.0
30
+ def assign(value)
31
+ thread_safe do
32
+ raise(
33
+ SmartCore::Initializer::SettingArgumentError,
34
+ ":strict_options setting should be a type of boolean (got: `#{value.class}`)"
35
+ ) unless value.is_a?(::TrueClass) || value.is_a?(::FalseClass)
36
+
37
+ @value = value
38
+ end
39
+ end
40
+ end
@@ -2,13 +2,15 @@
2
2
 
3
3
  # @api private
4
4
  # @since 0.1.0
5
- class SmartCore::Initializer::Settings::TypeSystem
5
+ # @version 0.8.0
6
+ class SmartCore::Initializer::Settings::TypeSystem < SmartCore::Initializer::Settings::Base
6
7
  # @return [void]
7
8
  #
8
9
  # @api private
9
10
  # @since 0.1.0
11
+ # @version 0.8.0
10
12
  def initialize
11
- @type_system = nil
13
+ @value = nil
12
14
  @lock = SmartCore::Engine::Lock.new
13
15
  end
14
16
 
@@ -26,9 +28,10 @@ class SmartCore::Initializer::Settings::TypeSystem
26
28
  #
27
29
  # @api private
28
30
  # @since 0.1.0
31
+ # @version 0.8.0
29
32
  def resolve
30
33
  thread_safe do
31
- @type_system || SmartCore::Initializer::Configuration.config[:default_type_system]
34
+ @value == nil ? SmartCore::Initializer::Configuration[:default_type_system] : @value
32
35
  end
33
36
  end
34
37
 
@@ -37,33 +40,12 @@ class SmartCore::Initializer::Settings::TypeSystem
37
40
  #
38
41
  # @api private
39
42
  # @since 0.1.0
43
+ # @version 0.8.0
40
44
  def assign(value)
41
45
  thread_safe do
42
- SmartCore::Initializer::TypeSystem.resolve(value) # NOTE: type system existence validation
43
- @type_system = value
46
+ # NOTE: type system existence validation
47
+ SmartCore::Initializer::TypeSystem.resolve(value)
48
+ @value = value
44
49
  end
45
50
  end
46
-
47
- # @return [SmartCore::Initializer::Settings::TypeSystem]
48
- #
49
- # @api private
50
- # @since 0.1.0
51
- def dup
52
- thread_safe do
53
- self.class.new.tap do |duplicate|
54
- duplicate.instance_variable_set(:@type_system, @type_system)
55
- end
56
- end
57
- end
58
-
59
- private
60
-
61
- # @param block [Block]
62
- # @return [Any]
63
- #
64
- # @api private
65
- # @since 0.1.0
66
- def thread_safe(&block)
67
- @lock.synchronize(&block)
68
- end
69
51
  end
@@ -3,15 +3,21 @@
3
3
  # @api private
4
4
  # @since 0.1.0
5
5
  class SmartCore::Initializer::Settings
6
+ require_relative 'settings/base'
6
7
  require_relative 'settings/type_system'
8
+ require_relative 'settings/strict_options'
9
+ require_relative 'settings/auto_cast'
7
10
  require_relative 'settings/duplicator'
8
11
 
9
12
  # @return [void]
10
13
  #
11
14
  # @api private
12
15
  # @since 0.1.0
16
+ # @version 0.8.0
13
17
  def initialize
14
18
  @type_system = TypeSystem.new
19
+ @strict_options = StrictOptions.new
20
+ @auto_cast = AutoCast.new
15
21
  end
16
22
 
17
23
  # @return [Any]
@@ -30,6 +36,22 @@ class SmartCore::Initializer::Settings
30
36
  @type_system.resolve
31
37
  end
32
38
 
39
+ # @return [Boolean]
40
+ #
41
+ # @api private
42
+ # @since 0.8.0
43
+ def strict_options
44
+ @strict_options.resolve
45
+ end
46
+
47
+ # @return [Boolean]
48
+ #
49
+ # @api private
50
+ # @since 0.8.0
51
+ def auto_cast
52
+ @auto_cast.resolve
53
+ end
54
+
33
55
  # @param value [String, System]
34
56
  # @return [void]
35
57
  #
@@ -39,6 +61,24 @@ class SmartCore::Initializer::Settings
39
61
  @type_system.assign(value)
40
62
  end
41
63
 
64
+ # @param value [Boolean]
65
+ # @return [void]
66
+ #
67
+ # @api private
68
+ # @since 0.8.0
69
+ def strict_options=(value)
70
+ @strict_options.assign(value)
71
+ end
72
+
73
+ # @param value [Boolean]
74
+ # @return [void]
75
+ #
76
+ # @api private
77
+ # @since 0.8.0
78
+ def auto_cast=(value)
79
+ @auto_cast.assign(value)
80
+ end
81
+
42
82
  # @return [SmartCore::Initializer::Settings]
43
83
  #
44
84
  # @api private
@@ -126,6 +126,7 @@ class SmartCore::Initializer::TypeSystem::Registry
126
126
  #
127
127
  # @api private
128
128
  # @since 0.1.0
129
+ # @version 0.8.0
129
130
  def fetch(system_identifier)
130
131
  identifier = indifferently_accessible_identifier(system_identifier)
131
132
 
@@ -133,7 +134,7 @@ class SmartCore::Initializer::TypeSystem::Registry
133
134
  systems.fetch(identifier)
134
135
  rescue ::KeyError
135
136
  raise(SmartCore::Initializer::UnsupportedTypeSystemError, <<~ERROR_MESSAGE)
136
- "#{identifier}" type system is not supported.
137
+ `#{identifier}` type system is not supported.
137
138
  ERROR_MESSAGE
138
139
  end
139
140
  end
@@ -21,7 +21,7 @@ class SmartCore::Initializer::TypeSystem::SmartTypes < SmartCore::Initializer::T
21
21
  type_alias('value.proc', SmartCore::Types::Value::Proc)
22
22
  type_alias('value.class', SmartCore::Types::Value::Class)
23
23
  type_alias('value.module', SmartCore::Types::Value::Module)
24
- type_alias('value.tme', SmartCore::Types::Value::Time)
24
+ type_alias('value.time', SmartCore::Types::Value::Time)
25
25
  type_alias('value.date_time', SmartCore::Types::Value::DateTime)
26
26
  type_alias('value.date', SmartCore::Types::Value::Date)
27
27
  type_alias('value.time_based', SmartCore::Types::Value::TimeBased)
@@ -41,7 +41,7 @@ class SmartCore::Initializer::TypeSystem::SmartTypes < SmartCore::Initializer::T
41
41
  type_alias(:proc, SmartCore::Types::Value::Proc)
42
42
  type_alias(:class, SmartCore::Types::Value::Class)
43
43
  type_alias(:module, SmartCore::Types::Value::Module)
44
- type_alias(:tme, SmartCore::Types::Value::Time)
44
+ type_alias(:time, SmartCore::Types::Value::Time)
45
45
  type_alias(:date_time, SmartCore::Types::Value::DateTime)
46
46
  type_alias(:date, SmartCore::Types::Value::Date)
47
47
  type_alias(:time_based, SmartCore::Types::Value::TimeBased)
@@ -6,7 +6,7 @@ module SmartCore
6
6
  #
7
7
  # @api public
8
8
  # @since 0.1.0
9
- # @version 0.7.0
10
- VERSION = '0.7.0'
9
+ # @version 0.8.0
10
+ VERSION = '0.8.0'
11
11
  end
12
12
  end
@@ -43,15 +43,25 @@ module SmartCore
43
43
  end
44
44
 
45
45
  class << self
46
- # @option type_system [String, Symbol, NilSymbol]
46
+ # @option type_system [String, Symbol]
47
+ # @option strict_options [Boolean]
48
+ # @option auto_cast [Boolean]
47
49
  # @return [Module]
48
50
  #
49
51
  # @api public
50
52
  # @since 0.1.0
51
- # @version 0.3.0
53
+ # @version 0.8.0
52
54
  # rubocop:disable Naming/MethodName
53
- def Initializer(type_system: SmartCore::Initializer::Functionality::INITIAL_TYPE_SYSTEM)
54
- SmartCore::Initializer::Functionality.includable_module(type_system: type_system)
55
+ def Initializer(
56
+ type_system: SmartCore::Initializer::Configuration[:default_type_system],
57
+ strict_options: SmartCore::Initializer::Configuration[:strict_options],
58
+ auto_cast: SmartCore::Initializer::Configuration[:auto_cast]
59
+ )
60
+ SmartCore::Initializer::Functionality.includable_module(
61
+ type_system: type_system,
62
+ strict_options: strict_options,
63
+ auto_cast: auto_cast
64
+ )
55
65
  end
56
66
  # rubocop:enable Naming/MethodName
57
67
  end
@@ -3,7 +3,7 @@
3
3
  require_relative 'lib/smart_core/initializer/version'
4
4
 
5
5
  Gem::Specification.new do |spec|
6
- spec.required_ruby_version = Gem::Requirement.new('>= 2.4.10')
6
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.5')
7
7
 
8
8
  spec.name = 'smart_initializer'
9
9
  spec.version = SmartCore::Initializer::VERSION
@@ -37,7 +37,7 @@ Gem::Specification.new do |spec|
37
37
  spec.add_development_dependency 'bundler', '~> 2.2'
38
38
  spec.add_development_dependency 'rake', '~> 13.0'
39
39
  spec.add_development_dependency 'rspec', '~> 3.10'
40
- spec.add_development_dependency 'armitage-rubocop', '~> 1.7'
40
+ spec.add_development_dependency 'armitage-rubocop', '~> 1.23'
41
41
  spec.add_development_dependency 'simplecov', '~> 0.21'
42
42
  spec.add_development_dependency 'pry', '~> 0.14'
43
43
  end
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.7.0
4
+ version: 0.8.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-06-28 00:00:00.000000000 Z
11
+ date: 2021-12-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: smart_engine
@@ -100,14 +100,14 @@ dependencies:
100
100
  requirements:
101
101
  - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: '1.7'
103
+ version: '1.23'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: '1.7'
110
+ version: '1.23'
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: simplecov
113
113
  requirement: !ruby/object:Gem::Requirement
@@ -163,12 +163,18 @@ files:
163
163
  - lib/smart_core/initializer.rb
164
164
  - lib/smart_core/initializer/attribute.rb
165
165
  - lib/smart_core/initializer/attribute/factory.rb
166
+ - lib/smart_core/initializer/attribute/factory/base.rb
167
+ - lib/smart_core/initializer/attribute/factory/option.rb
168
+ - lib/smart_core/initializer/attribute/factory/param.rb
166
169
  - lib/smart_core/initializer/attribute/finalizer.rb
167
170
  - lib/smart_core/initializer/attribute/finalizer/abstract.rb
168
171
  - lib/smart_core/initializer/attribute/finalizer/anonymous_block.rb
169
172
  - lib/smart_core/initializer/attribute/finalizer/instance_method.rb
170
173
  - lib/smart_core/initializer/attribute/list.rb
171
- - lib/smart_core/initializer/attribute/parameters.rb
174
+ - lib/smart_core/initializer/attribute/value.rb
175
+ - lib/smart_core/initializer/attribute/value/base.rb
176
+ - lib/smart_core/initializer/attribute/value/option.rb
177
+ - lib/smart_core/initializer/attribute/value/param.rb
172
178
  - lib/smart_core/initializer/configuration.rb
173
179
  - lib/smart_core/initializer/constructor.rb
174
180
  - lib/smart_core/initializer/constructor/definer.rb
@@ -196,7 +202,10 @@ files:
196
202
  - lib/smart_core/initializer/plugins/thy_types/thy_types/operation/valid.rb
197
203
  - lib/smart_core/initializer/plugins/thy_types/thy_types/operation/validate.rb
198
204
  - lib/smart_core/initializer/settings.rb
205
+ - lib/smart_core/initializer/settings/auto_cast.rb
206
+ - lib/smart_core/initializer/settings/base.rb
199
207
  - lib/smart_core/initializer/settings/duplicator.rb
208
+ - lib/smart_core/initializer/settings/strict_options.rb
200
209
  - lib/smart_core/initializer/settings/type_system.rb
201
210
  - lib/smart_core/initializer/type_system.rb
202
211
  - lib/smart_core/initializer/type_system/interop.rb
@@ -230,14 +239,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
230
239
  requirements:
231
240
  - - ">="
232
241
  - !ruby/object:Gem::Version
233
- version: 2.4.10
242
+ version: '2.5'
234
243
  required_rubygems_version: !ruby/object:Gem::Requirement
235
244
  requirements:
236
245
  - - ">="
237
246
  - !ruby/object:Gem::Version
238
247
  version: '0'
239
248
  requirements: []
240
- rubygems_version: 3.2.3
249
+ rubygems_version: 3.2.22
241
250
  signing_key:
242
251
  specification_version: 4
243
252
  summary: Initializer DSL