smart_initializer 0.5.0 → 0.6.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e7a9f30c8b223f8e66bc1ac23dfd183cd80d32c0620fd929ecdc42a534381635
4
- data.tar.gz: eee561816ebbacf1a4f583d5038da3bb3478c10790a95e6c01ca8569a065174d
3
+ metadata.gz: 7fe42fb05f82247b924687f18a3eb129d7a49d0e9b071c801adc828c64ae4f93
4
+ data.tar.gz: 3dc7371d09e41172337c2bd98db4b06239f77c624cedcdbf8848503eba946de2
5
5
  SHA512:
6
- metadata.gz: 2e1c9e0b9f6b84cf6ad9fc5e84107fcddcc684ea80fb4c7f4fcf93f388d95cee0d7f36cae96106d19766964b79ae247f24c263ce51df81dabbef482204c04da8
7
- data.tar.gz: 1ecac9ea5d30974515fdc8b3aac16d4b72c922f3d1c837353006200167f203ccb5ee8c94f8b6ea517dad9b86c80deb8818ae18471ad098339595b15d7aa6ee07
6
+ metadata.gz: a76205061e305e24474db7a08c045a9889ca8859d1658fa9df1fca20a94edea83574c5b62bb81daeefa21ba3c5ec70d9cb03b55b1f2910383bbde1735547677b
7
+ data.tar.gz: 3bafdce939b39dd8418dc1baeafecc199b6460b98e25e3eba5c5732f22c62d58df1c29383c31a668edd79782c8c29a18c9359f7ef080b0a4d6716b1dec457207
data/CHANGELOG.md CHANGED
@@ -1,9 +1,14 @@
1
1
  # Changelog
2
2
  All notable changes to this project will be documented in this file.
3
3
 
4
+ ## [0.6.0] - 2021-06-23
5
+ ## Added
6
+ - Validation messages for incorrect attribute types;
7
+
4
8
  ## [0.5.0] - 2021-01-18
5
9
  ## Changed
6
10
  - Updated `smart_types` dependency (`~> 0.4.0`) to guarantee **Ruby@3** compatibility;
11
+ - Updated development dependencies;
7
12
 
8
13
  ## [0.4.0] - 2021-01-18
9
14
  ### Added
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- smart_initializer (0.5.0)
4
+ smart_initializer (0.6.0)
5
5
  qonfig (~> 0.24)
6
6
  smart_engine (~> 0.11)
7
7
  smart_types (~> 0.4)
@@ -9,31 +9,31 @@ PATH
9
9
  GEM
10
10
  remote: https://rubygems.org/
11
11
  specs:
12
- activesupport (6.1.1)
12
+ activesupport (6.1.2)
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)
18
+ armitage-rubocop (1.8.1)
19
+ rubocop (= 1.8.1)
20
+ rubocop-performance (= 1.9.2)
21
21
  rubocop-rails (= 2.9.1)
22
22
  rubocop-rake (= 0.5.1)
23
23
  rubocop-rspec (= 2.1.0)
24
- ast (2.4.1)
24
+ ast (2.4.2)
25
25
  coderay (1.1.3)
26
- concurrent-ruby (1.1.7)
26
+ concurrent-ruby (1.1.8)
27
27
  diff-lcs (1.4.4)
28
28
  docile (1.3.5)
29
- i18n (1.8.7)
29
+ i18n (1.8.8)
30
30
  concurrent-ruby (~> 1.0)
31
31
  method_source (1.0.0)
32
32
  minitest (5.14.3)
33
33
  parallel (1.20.1)
34
34
  parser (3.0.0.0)
35
35
  ast (~> 2.4.1)
36
- pry (0.13.1)
36
+ pry (0.14.0)
37
37
  coderay (~> 1.1)
38
38
  method_source (~> 1.0)
39
39
  qonfig (0.25.0)
@@ -51,22 +51,22 @@ GEM
51
51
  rspec-expectations (3.10.1)
52
52
  diff-lcs (>= 1.2.0, < 2.0)
53
53
  rspec-support (~> 3.10.0)
54
- rspec-mocks (3.10.1)
54
+ rspec-mocks (3.10.2)
55
55
  diff-lcs (>= 1.2.0, < 2.0)
56
56
  rspec-support (~> 3.10.0)
57
- rspec-support (3.10.1)
58
- rubocop (1.7.0)
57
+ rspec-support (3.10.2)
58
+ rubocop (1.8.1)
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
64
  rubocop-ast (>= 1.2.0, < 2.0)
65
65
  ruby-progressbar (~> 1.7)
66
- unicode-display_width (>= 1.4.0, < 2.0)
67
- rubocop-ast (1.4.0)
66
+ unicode-display_width (>= 1.4.0, < 3.0)
67
+ rubocop-ast (1.4.1)
68
68
  parser (>= 2.7.1.5)
69
- rubocop-performance (1.9.1)
69
+ rubocop-performance (1.9.2)
70
70
  rubocop (>= 0.90.0, < 2.0)
71
71
  rubocop-ast (>= 0.4.0)
72
72
  rubocop-rails (2.9.1)
@@ -90,20 +90,21 @@ GEM
90
90
  smart_engine (~> 0.11)
91
91
  tzinfo (2.0.4)
92
92
  concurrent-ruby (~> 1.0)
93
- unicode-display_width (1.7.0)
93
+ unicode-display_width (2.0.0)
94
94
  zeitwerk (2.4.2)
95
95
 
96
96
  PLATFORMS
97
+ x86_64-darwin-19
97
98
  x86_64-darwin-20
98
99
 
99
100
  DEPENDENCIES
100
101
  armitage-rubocop (~> 1.7)
101
102
  bundler (~> 2.2)
102
- pry (~> 0.13)
103
+ pry (~> 0.14)
103
104
  rake (~> 13.0)
104
105
  rspec (~> 3.10)
105
106
  simplecov (~> 0.21)
106
107
  smart_initializer!
107
108
 
108
109
  BUNDLED WITH
109
- 2.2.3
110
+ 2.2.11
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2020 Rustam Ibragimov
3
+ Copyright (c) 2020-2021 Rustam Ibragimov
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -293,6 +293,7 @@ User.new(123, 'test', { admin: true, age: 22 })
293
293
  - Support for specifying the attribute accessor type (`read_only` parameter);
294
294
  - Support for attribute aliasing (`as` parameter);
295
295
  - Migrate from `TravisCI` to `GitHub Actions`;
296
+ - Extract `Type Interop` system to `smart_type-system`;
296
297
 
297
298
  ---
298
299
 
@@ -1,10 +1,10 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- smart_initializer (0.3.2)
4
+ smart_initializer (0.5.0)
5
5
  qonfig (~> 0.24)
6
- smart_engine (~> 0.7)
7
- smart_types (~> 0.1.0)
6
+ smart_engine (~> 0.11)
7
+ smart_types (~> 0.4)
8
8
 
9
9
  GEM
10
10
  remote: https://rubygems.org/
@@ -15,22 +15,27 @@ GEM
15
15
  minitest (>= 5.1)
16
16
  tzinfo (~> 2.0)
17
17
  zeitwerk (~> 2.3)
18
- armitage-rubocop (0.93.1)
19
- rubocop (= 0.93.1)
20
- rubocop-performance (= 1.8.1)
21
- rubocop-rails (= 2.8.1)
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
22
  rubocop-rake (= 0.5.1)
23
- rubocop-rspec (= 1.43.2)
23
+ rubocop-rspec (= 2.1.0)
24
24
  ast (2.4.1)
25
+ coderay (1.1.3)
25
26
  concurrent-ruby (1.1.7)
26
27
  diff-lcs (1.4.4)
27
28
  docile (1.3.5)
28
29
  i18n (1.8.7)
29
30
  concurrent-ruby (~> 1.0)
31
+ method_source (1.0.0)
30
32
  minitest (5.14.3)
31
33
  parallel (1.20.1)
32
34
  parser (3.0.0.0)
33
35
  ast (~> 2.4.1)
36
+ pry (0.13.1)
37
+ coderay (~> 1.1)
38
+ method_source (~> 1.0)
34
39
  qonfig (0.25.0)
35
40
  rack (2.2.3)
36
41
  rainbow (3.0.0)
@@ -50,28 +55,29 @@ GEM
50
55
  diff-lcs (>= 1.2.0, < 2.0)
51
56
  rspec-support (~> 3.10.0)
52
57
  rspec-support (3.10.1)
53
- rubocop (0.93.1)
58
+ rubocop (1.7.0)
54
59
  parallel (~> 1.10)
55
60
  parser (>= 2.7.1.5)
56
61
  rainbow (>= 2.2.2, < 4.0)
57
- regexp_parser (>= 1.8)
62
+ regexp_parser (>= 1.8, < 3.0)
58
63
  rexml
59
- rubocop-ast (>= 0.6.0)
64
+ rubocop-ast (>= 1.2.0, < 2.0)
60
65
  ruby-progressbar (~> 1.7)
61
66
  unicode-display_width (>= 1.4.0, < 2.0)
62
67
  rubocop-ast (1.4.0)
63
68
  parser (>= 2.7.1.5)
64
- rubocop-performance (1.8.1)
65
- rubocop (>= 0.87.0)
69
+ rubocop-performance (1.9.1)
70
+ rubocop (>= 0.90.0, < 2.0)
66
71
  rubocop-ast (>= 0.4.0)
67
- rubocop-rails (2.8.1)
72
+ rubocop-rails (2.9.1)
68
73
  activesupport (>= 4.2.0)
69
74
  rack (>= 1.1)
70
- rubocop (>= 0.87.0)
75
+ rubocop (>= 0.90.0, < 2.0)
71
76
  rubocop-rake (0.5.1)
72
77
  rubocop
73
- rubocop-rspec (1.43.2)
74
- rubocop (~> 0.87)
78
+ rubocop-rspec (2.1.0)
79
+ rubocop (~> 1.0)
80
+ rubocop-ast (>= 1.1.0)
75
81
  ruby-progressbar (1.11.0)
76
82
  simplecov (0.21.2)
77
83
  docile (~> 1.1)
@@ -80,8 +86,8 @@ GEM
80
86
  simplecov-html (0.12.3)
81
87
  simplecov_json_formatter (0.1.2)
82
88
  smart_engine (0.11.0)
83
- smart_types (0.1.0)
84
- smart_engine (~> 0.6)
89
+ smart_types (0.4.0)
90
+ smart_engine (~> 0.11)
85
91
  tzinfo (2.0.4)
86
92
  concurrent-ruby (~> 1.0)
87
93
  unicode-display_width (1.7.0)
@@ -91,11 +97,12 @@ PLATFORMS
91
97
  x86_64-darwin-20
92
98
 
93
99
  DEPENDENCIES
94
- armitage-rubocop (~> 0.87)
95
- bundler (~> 2.1)
100
+ armitage-rubocop (~> 1.7)
101
+ bundler (~> 2.2)
102
+ pry (~> 0.13)
96
103
  rake (~> 13.0)
97
- rspec (~> 3.9)
98
- simplecov (~> 0.18)
104
+ rspec (~> 3.10)
105
+ simplecov (~> 0.21)
99
106
  smart_initializer!
100
107
 
101
108
  BUNDLED WITH
@@ -90,6 +90,19 @@ class SmartCore::Initializer::Attribute
90
90
  )
91
91
  end
92
92
 
93
+ # @param value [Any]
94
+ # @return [void]
95
+ #
96
+ # @api private
97
+ # @since 0.5.1
98
+ def validate!(value)
99
+ type.validate!(value)
100
+ rescue => error
101
+ raise SmartCore::Initializer::IncorrectTypeError,
102
+ "Validation of attribute '#{name}' (#{type.identifier}, got #{value.class}) failed: " \
103
+ "#{error.message}"
104
+ end
105
+
93
106
  # @return [SmartCore::Initializer::Attribute]
94
107
  #
95
108
  # @api private
@@ -113,15 +113,16 @@ class SmartCore::Initializer::Constructor
113
113
  #
114
114
  # @api private
115
115
  # @since 0.1.0
116
+ # @version 0.5.1
116
117
  def initialize_parameters(instance)
117
- parameter_definitions = Hash[klass.__params__.zip(parameters)]
118
+ parameter_definitions = klass.__params__.zip(parameters).to_h
118
119
 
119
120
  parameter_definitions.each_pair do |attribute, parameter_value|
120
121
  if !attribute.type.valid?(parameter_value) && attribute.cast?
121
122
  parameter_value = attribute.type.cast(parameter_value)
122
123
  end
123
124
 
124
- attribute.type.validate!(parameter_value)
125
+ attribute.validate!(parameter_value)
125
126
 
126
127
  final_value = attribute.finalizer.call(parameter_value, instance)
127
128
  instance.instance_variable_set("@#{attribute.name}", final_value)
@@ -133,7 +134,7 @@ class SmartCore::Initializer::Constructor
133
134
  #
134
135
  # @api private
135
136
  # @since 0.1.0
136
- # rubocop:disable Metrics/AbcSize
137
+ # @version 0.5.1
137
138
  def initialize_options(instance)
138
139
  klass.__options__.each do |attribute|
139
140
  option_value = options.fetch(attribute.name) { attribute.default }
@@ -142,13 +143,12 @@ class SmartCore::Initializer::Constructor
142
143
  option_value = attribute.type.cast(option_value)
143
144
  end
144
145
 
145
- attribute.type.validate!(option_value)
146
+ attribute.validate!(option_value)
146
147
 
147
148
  final_value = attribute.finalizer.call(option_value, instance)
148
149
  instance.instance_variable_set("@#{attribute.name}", final_value)
149
150
  end
150
151
  end
151
- # rubocop:enable Metrics/AbcSize
152
152
 
153
153
  # @param instance [Any]
154
154
  # @return [void]
@@ -73,6 +73,10 @@ module SmartCore::Initializer
73
73
  # @since 0.1.0
74
74
  UnsupportedTypeOperationError = Class.new(TypeSystemError)
75
75
 
76
+ # @api public
77
+ # @since 0.5.1
78
+ IncorrectTypeError = Class.new(TypeSystemError)
79
+
76
80
  # @api public
77
81
  # @since 0.1.0
78
82
  TypeCastingUnsupportedError = Class.new(UnsupportedTypeOperationError)
@@ -28,6 +28,15 @@ module SmartCore::Initializer::TypeSystem
28
28
  end
29
29
  end
30
30
 
31
+ # @param type [Any]
32
+ # @return [String]
33
+ #
34
+ # @api private
35
+ # @since 0.5.1
36
+ def build_identifier(type)
37
+ type.name
38
+ end
39
+
31
40
  # @param type [Thy::Type, #check]
32
41
  # @return [SmartCore::Initializer::TypeSystem::ThyTypes::Operation::Valid]
33
42
  #
@@ -63,6 +72,7 @@ module SmartCore::Initializer::TypeSystem
63
72
  ThyTypes::Operation::Cast.new(type)
64
73
  end
65
74
 
75
+ # @param identifier [String]
66
76
  # @param valid_op [SmartCore::Initializer::TypeSystem::ThyTypes::Operation::Valid]
67
77
  # @param valid_op [SmartCore::Initializer::TypeSystem::ThyTypes::Operation::Validate]
68
78
  # @param valid_op [SmartCore::Initializer::TypeSystem::ThyTypes::Operation::Cast]
@@ -70,8 +80,9 @@ module SmartCore::Initializer::TypeSystem
70
80
  #
71
81
  # @api private
72
82
  # @since 0.1.0
73
- def build_interop(valid_op, validate_op, cast_op)
74
- ThyTypes.new(valid_op, validate_op, cast_op)
83
+ # @version 0.5.1
84
+ def build_interop(identifier, valid_op, validate_op, cast_op)
85
+ ThyTypes.new(identifier, valid_op, validate_op, cast_op)
75
86
  end
76
87
  end
77
88
  end
@@ -41,6 +41,13 @@ class SmartCore::Initializer::TypeSystem::Interop
41
41
  end
42
42
  end
43
43
 
44
+ # @return [String]
45
+ #
46
+ # @api private
47
+ # @since 0.5.1
48
+ attr_reader :identifier
49
+
50
+ # @param identifier [String]
44
51
  # @param valid_op [SmartCore::Initializer::TypeSystem::Interop::Operation]
45
52
  # @param validate_op [SmartCore::Initializer::TypeSystem::Interop::Operation]
46
53
  # @param cast_op [SmartCore::Initializer::TypeSystem::Interop::Operation]
@@ -48,7 +55,9 @@ class SmartCore::Initializer::TypeSystem::Interop
48
55
  #
49
56
  # @api private
50
57
  # @since 0.1.0
51
- def initialize(valid_op, validate_op, cast_op)
58
+ # @version 0.5.1
59
+ def initialize(identifier, valid_op, validate_op, cast_op)
60
+ @identifier = identifier
52
61
  @valid_op = valid_op
53
62
  @validate_op = validate_op
54
63
  @cast_op = cast_op
@@ -13,11 +13,12 @@ class SmartCore::Initializer::TypeSystem::Interop::AbstractFactory
13
13
  def create(type)
14
14
  prevent_incompatible_type!(type)
15
15
 
16
+ identifier = build_identifier(type)
16
17
  valid_op = build_valid_operation(type)
17
18
  validate_op = build_validate_operation(type)
18
19
  cast_op = build_cast_operation(type)
19
20
 
20
- build_interop(valid_op, validate_op, cast_op)
21
+ build_interop(identifier, valid_op, validate_op, cast_op)
21
22
  end
22
23
 
23
24
  # @return [Any]
@@ -26,6 +27,13 @@ class SmartCore::Initializer::TypeSystem::Interop::AbstractFactory
26
27
  # @since 0.1.0
27
28
  def generic_type_object; end
28
29
 
30
+ # @param type [Any]
31
+ # @return [String]
32
+ #
33
+ # @api private
34
+ # @since 0.5.1
35
+ def build_identifier(type); end
36
+
29
37
  # @param type [Any]
30
38
  # @return [void]
31
39
  #
@@ -58,6 +66,7 @@ class SmartCore::Initializer::TypeSystem::Interop::AbstractFactory
58
66
  # @since 0.1.0
59
67
  def build_cast_operation(type); end
60
68
 
69
+ # @param identifier [String]
61
70
  # @param valid_op [SmartCore::Initializer::TypeSystem::Interop::Operation]
62
71
  # @param validate_op [SmartCore::Initializer::TypeSystem::Interop::Operation]
63
72
  # @param cast_op [SmartCore::Initializer::TypeSystem::Interop::Operation]
@@ -65,6 +74,7 @@ class SmartCore::Initializer::TypeSystem::Interop::AbstractFactory
65
74
  #
66
75
  # @api private
67
76
  # @since 0.1.0
68
- def build_interop(valid_op, validate_op, cast_op); end
77
+ # @version 0.5.1
78
+ def build_interop(identifier, valid_op, validate_op, cast_op); end
69
79
  end
70
80
  end
@@ -22,6 +22,15 @@ module SmartCore::Initializer::TypeSystem
22
22
  end
23
23
  end
24
24
 
25
+ # @param type [Any]
26
+ # @return [String]
27
+ #
28
+ # @api private
29
+ # @since 0.5.1
30
+ def build_identifier(type)
31
+ type.name
32
+ end
33
+
25
34
  # @param type [SmartCore::Types::Primitive]
26
35
  # @return [SmartCore::Initializer::TypeSystem::SmartTypes::Operation::Valid]
27
36
  #
@@ -57,6 +66,7 @@ module SmartCore::Initializer::TypeSystem
57
66
  SmartTypes::Operation::Cast.new(type)
58
67
  end
59
68
 
69
+ # @param identifier [String]
60
70
  # @param valid_op [SmartCore::Initializer::TypeSystem::SmartTypes::Operation::Valid]
61
71
  # @param valid_op [SmartCore::Initializer::TypeSystem::SmartTypes::Operation::Validate]
62
72
  # @param valid_op [SmartCore::Initializer::TypeSystem::SmartTypes::Operation::Cast]
@@ -64,8 +74,9 @@ module SmartCore::Initializer::TypeSystem
64
74
  #
65
75
  # @api private
66
76
  # @since 0.1.0
67
- def build_interop(valid_op, validate_op, cast_op)
68
- SmartTypes.new(valid_op, validate_op, cast_op)
77
+ # @version 0.5.1
78
+ def build_interop(identifier, valid_op, validate_op, cast_op)
79
+ SmartTypes.new(identifier, valid_op, validate_op, cast_op)
69
80
  end
70
81
  end
71
82
  end
@@ -6,7 +6,7 @@ module SmartCore
6
6
  #
7
7
  # @api public
8
8
  # @since 0.1.0
9
- # @version 0.5.0
10
- VERSION = '0.5.0'
9
+ # @version 0.6.0
10
+ VERSION = '0.6.0'
11
11
  end
12
12
  end
@@ -39,5 +39,5 @@ Gem::Specification.new do |spec|
39
39
  spec.add_development_dependency 'rspec', '~> 3.10'
40
40
  spec.add_development_dependency 'armitage-rubocop', '~> 1.7'
41
41
  spec.add_development_dependency 'simplecov', '~> 0.21'
42
- spec.add_development_dependency 'pry', '~> 0.13'
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.5.0
4
+ version: 0.6.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-01-17 00:00:00.000000000 Z
11
+ date: 2021-06-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: smart_engine
@@ -128,14 +128,14 @@ dependencies:
128
128
  requirements:
129
129
  - - "~>"
130
130
  - !ruby/object:Gem::Version
131
- version: '0.13'
131
+ version: '0.14'
132
132
  type: :development
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
136
  - - "~>"
137
137
  - !ruby/object:Gem::Version
138
- version: '0.13'
138
+ version: '0.14'
139
139
  description: A simple and convenient way to declare complex constructors
140
140
  email:
141
141
  - iamdaiver@gmail.com