smart_initializer 0.11.1 → 0.12.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: 8fe201fc92a2d434aa3b1172e41d9087198d77e63282a9e98ed1da9a9aab6668
4
- data.tar.gz: 23898d45402508f8baba6f377f60833c0388a269fbef4ab25a31e11f48578f12
3
+ metadata.gz: 8922071ca9c220e11db62245ad51d3fbf4d5f7e1a50d8177aab85c6ece63c88f
4
+ data.tar.gz: 34c3c45abfd4f574946579445022c707b386faf95e31356411b5b9cf38dbc9a5
5
5
  SHA512:
6
- metadata.gz: 8df5d054733685007a706f980e5f2fb4e7a6155d617c6726f6bcb977a7833af4850c8e69b187870dd02330fbe9a821587c8ee40270f225f0324aa75b02bcfdb6
7
- data.tar.gz: 2796450e1c53a909d692916d5087bcb3059bfd1165078d3758d79aa372f62cdbde7c7b6d6bbe97a41c811239e7595d2a49b76b9ef675e6186b10ef3f907ba5a9
6
+ metadata.gz: 2f3d0002ef6c50389675207c17e7b8ff21cadeab73dd28d22b6bbc5dc903caf717f6990ffb1e6c168ab42617e16e4a5c4fad435ad7d419ed547603cafb462e6c
7
+ data.tar.gz: 14f0fb464ca7bde0e50720d960959ad648851b9c91e8b3aed7bda4c05ad89d6e785976bd3dbea2845408611a72801e0ab0e87053f92c45f12c267721ba705e8f
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- smart_initializer (0.11.1)
4
+ smart_initializer (0.12.0)
5
5
  qonfig (~> 0.24)
6
6
  smart_engine (~> 0.16)
7
7
  smart_types (~> 0.8)
@@ -21,6 +21,7 @@ GEM
21
21
  rubocop-rake (= 0.6.0)
22
22
  rubocop-rspec (= 2.13.2)
23
23
  ast (2.4.2)
24
+ bigdecimal (3.1.8)
24
25
  coderay (1.1.3)
25
26
  concurrent-ruby (1.1.10)
26
27
  diff-lcs (1.5.0)
@@ -30,6 +31,7 @@ GEM
30
31
  json (2.6.2)
31
32
  method_source (1.0.0)
32
33
  minitest (5.16.3)
34
+ ostruct (0.6.0)
33
35
  parallel (1.22.1)
34
36
  parser (3.1.2.1)
35
37
  ast (~> 2.4.1)
@@ -94,10 +96,13 @@ GEM
94
96
 
95
97
  PLATFORMS
96
98
  arm64-darwin-21
99
+ arm64-darwin-23
97
100
 
98
101
  DEPENDENCIES
99
102
  armitage-rubocop (~> 1.30)
103
+ bigdecimal
100
104
  bundler (~> 2.3)
105
+ ostruct
101
106
  pry (~> 0.14)
102
107
  rake (~> 13.0)
103
108
  rspec (~> 3.11)
@@ -105,4 +110,4 @@ DEPENDENCIES
105
110
  smart_initializer!
106
111
 
107
112
  BUNDLED WITH
108
- 2.3.17
113
+ 2.5.19
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2020-2021 Rustam Ibragimov
3
+ Copyright (c) 2020-2024 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
@@ -527,6 +527,7 @@ User.new(123, 'test', { admin: true, age: 22 })
527
527
 
528
528
  ## Roadmap
529
529
 
530
+ - an ability to re-define existing options and parameters in children classes;
530
531
  - More semantic attribute declaration errors (more domain-related attribute error objects);
531
532
  - incorrect `:finalize` argument type: `ArgumentError` => `FinalizeArgumentError`;
532
533
  - incorrect `:as` argument type: `ArguemntError` => `AsArgumentError`;
@@ -535,6 +536,7 @@ User.new(123, 'test', { admin: true, age: 22 })
535
536
  - Specs restructuring;
536
537
  - Migrate from `TravisCI` to `GitHub Actions`;
537
538
  - Extract `Type Interop` system to `smart_type-system`;
539
+ - an ability to define nested-`option` (or `param`) for structure-like object (for object with "nested" nature like `a.b.c` or `a[:b][:c]`) with data type validaitons and with a support of (almost) full attribute DSL;
538
540
 
539
541
  ---
540
542
 
@@ -132,7 +132,7 @@ class SmartCore::Initializer::Attribute::Factory::Base
132
132
  #
133
133
  # @api private
134
134
  # @since 0.4.0
135
- def preapre_as_param(as)
135
+ def prepare_as_param(as)
136
136
  unless as.is_a?(::NilClass) || as.is_a?(::String) || as.is_a?(::Symbol)
137
137
  raise(SmartCore::Initializer::ArgumentError, <<~ERROR_MESSAGE)
138
138
  Attribute alias should be a type of String or Symbol
@@ -5,6 +5,7 @@ module SmartCore::Initializer::Attribute::Factory
5
5
  # @since 0.8.0
6
6
  class Option < Base
7
7
  class << self
8
+ # @param klass [Class]
8
9
  # @param name [String, Symbol]
9
10
  # @param type [String, Symbol, Any]
10
11
  # @param type_system [String, Symbol]
@@ -19,7 +20,7 @@ module SmartCore::Initializer::Attribute::Factory
19
20
  #
20
21
  # @api private
21
22
  # @since 0.8.0
22
- def create(name, type, type_system, privacy, finalize, cast, mutable, as, default, optional)
23
+ def create(klass, name, type, type_system, privacy, finalize, cast, mutable, as, default, optional)
23
24
  prepared_name = prepare_name_param(name)
24
25
  prepared_privacy = prepare_privacy_param(privacy)
25
26
  prepared_finalize = prepare_finalize_param(finalize)
@@ -27,11 +28,12 @@ module SmartCore::Initializer::Attribute::Factory
27
28
  prepared_type_system = prepare_type_system_param(type_system)
28
29
  prepared_type = prepare_type_param(type, prepared_type_system)
29
30
  prepared_mutable = prepare_mutable_param(mutable)
30
- prepared_as = preapre_as_param(as)
31
+ prepared_as = prepare_as_param(as)
31
32
  prepared_default = prepare_default_param(default)
32
33
  prepared_optional = prepare_optional_param(optional)
33
34
 
34
35
  create_attribute(
36
+ klass,
35
37
  prepared_name,
36
38
  prepared_type,
37
39
  prepared_type_system,
@@ -47,6 +49,7 @@ module SmartCore::Initializer::Attribute::Factory
47
49
 
48
50
  private
49
51
 
52
+ # @param klass [Class]
50
53
  # @param name [String]
51
54
  # @param type [SmartCore::Initializer::TypeSystem::Interop]
52
55
  # @param type_system [Class<SmartCore::Initializer::TypeSystem::Interop>]
@@ -62,6 +65,7 @@ module SmartCore::Initializer::Attribute::Factory
62
65
  # @api private
63
66
  # @since 0.8.0
64
67
  def create_attribute(
68
+ klass,
65
69
  name,
66
70
  type,
67
71
  type_system,
@@ -74,7 +78,7 @@ module SmartCore::Initializer::Attribute::Factory
74
78
  optional
75
79
  )
76
80
  SmartCore::Initializer::Attribute::Value::Option.new(
77
- name, type, type_system, privacy, finalize, cast, mutable, as, default, optional
81
+ klass, name, type, type_system, privacy, finalize, cast, mutable, as, default, optional
78
82
  )
79
83
  end
80
84
 
@@ -5,6 +5,7 @@ module SmartCore::Initializer::Attribute::Factory
5
5
  # @since 0.8.0
6
6
  class Param < Base
7
7
  class << self
8
+ # @param klass [Class]
8
9
  # @param name [String, Symbol]
9
10
  # @param type [String, Symbol, Any]
10
11
  # @param type_system [String, Symbol]
@@ -17,7 +18,7 @@ module SmartCore::Initializer::Attribute::Factory
17
18
  #
18
19
  # @api private
19
20
  # @since 0.8.0
20
- def create(name, type, type_system, privacy, finalize, cast, mutable, as)
21
+ def create(klass, name, type, type_system, privacy, finalize, cast, mutable, as)
21
22
  prepared_name = prepare_name_param(name)
22
23
  prepared_privacy = prepare_privacy_param(privacy)
23
24
  prepared_finalize = prepare_finalize_param(finalize)
@@ -25,9 +26,10 @@ module SmartCore::Initializer::Attribute::Factory
25
26
  prepared_type_system = prepare_type_system_param(type_system)
26
27
  prepared_type = prepare_type_param(type, prepared_type_system)
27
28
  prepared_mutable = prepare_mutable_param(mutable)
28
- prepared_as = preapre_as_param(as)
29
+ prepared_as = prepare_as_param(as)
29
30
 
30
31
  create_attribute(
32
+ klass,
31
33
  prepared_name,
32
34
  prepared_type,
33
35
  prepared_type_system,
@@ -53,9 +55,9 @@ module SmartCore::Initializer::Attribute::Factory
53
55
  #
54
56
  # @api private
55
57
  # @since 0.8.0
56
- def create_attribute(name, type, type_system, privacy, finalize, cast, mutable, as)
58
+ def create_attribute(klass, name, type, type_system, privacy, finalize, cast, mutable, as)
57
59
  SmartCore::Initializer::Attribute::Value::Param.new(
58
- name, type, type_system, privacy, finalize, cast, mutable, as
60
+ klass, name, type, type_system, privacy, finalize, cast, mutable, as
59
61
  )
60
62
  end
61
63
  end
@@ -38,6 +38,12 @@ class SmartCore::Initializer::Attribute::Value::Base
38
38
  # @since 0.8.0
39
39
  DEFAULT_MUTABLE = false
40
40
 
41
+ # @return [Class]
42
+ #
43
+ # @api private
44
+ # @since 0.12.0
45
+ attr_reader :klass
46
+
41
47
  # @return [Symbol]
42
48
  #
43
49
  # @api private
@@ -89,6 +95,7 @@ class SmartCore::Initializer::Attribute::Value::Base
89
95
  # @since 0.8.0
90
96
  attr_reader :as
91
97
 
98
+ # @param klass [Class]
92
99
  # @param name [Symbol]
93
100
  # @param type [SmartCore::Initializer::TypeSystem::Interop]
94
101
  # @param type_system [Class<SmartCore::Initializer::TypeSystem::Interop>]
@@ -101,7 +108,8 @@ class SmartCore::Initializer::Attribute::Value::Base
101
108
  #
102
109
  # @api private
103
110
  # @since 0.8.0
104
- def initialize(name, type, type_system, privacy, finalizer, cast, mutable, as)
111
+ def initialize(klass, name, type, type_system, privacy, finalizer, cast, mutable, as)
112
+ @klass = klass
105
113
  @name = name
106
114
  @type = type
107
115
  @type_system = type_system
@@ -121,10 +129,20 @@ class SmartCore::Initializer::Attribute::Value::Base
121
129
  # @since 0.8.0
122
130
  # @version 0.11.0
123
131
  def validate!(value)
124
- raise(
125
- SmartCore::Initializer::IncorrectTypeError,
126
- "Validation of attribute `#{name}` failed:" \
127
- "(expected: #{type.identifier}, got: #{value.class})"
128
- ) unless type.valid?(value)
132
+ unless type.valid?(value)
133
+ raise(
134
+ SmartCore::Initializer::IncorrectTypeError,
135
+ "Validation of attribute `#{klass}##{name}` failed. " \
136
+ "Expected: #{type.identifier}, got: #{truncate(value.inspect, 100)}",
137
+ )
138
+ end
139
+ end
140
+
141
+ private
142
+
143
+ def truncate(string, max_length)
144
+ return string unless string.size > max_length
145
+ omission = "..."
146
+ "#{string[0, max_length - omission.size]}#{omission}"
129
147
  end
130
148
  end
@@ -23,6 +23,7 @@ module SmartCore::Initializer::Attribute::Value
23
23
  attr_reader :optional
24
24
  alias_method :optional?, :optional
25
25
 
26
+ # @param klass [Class]
26
27
  # @param name [Symbol]
27
28
  # @param type [SmartCore::Initializer::TypeSystem::Interop]
28
29
  # @param type_system [Class<SmartCore::Initializer::TypeSystem::Interop>]
@@ -38,6 +39,7 @@ module SmartCore::Initializer::Attribute::Value
38
39
  # @api private
39
40
  # @since 0.8.0
40
41
  def initialize(
42
+ klass,
41
43
  name,
42
44
  type,
43
45
  type_system,
@@ -49,7 +51,7 @@ module SmartCore::Initializer::Attribute::Value
49
51
  default,
50
52
  optional
51
53
  )
52
- super(name, type, type_system, privacy, finalizer, cast, mutable, as)
54
+ super(klass, name, type, type_system, privacy, finalizer, cast, mutable, as)
53
55
  @default = default
54
56
  @optional = optional
55
57
  end
@@ -85,6 +87,7 @@ module SmartCore::Initializer::Attribute::Value
85
87
  default = @default.equal?(UNDEFINED_DEFAULT) ? @default : @default.dup
86
88
 
87
89
  self.class.new(
90
+ klass,
88
91
  name.dup,
89
92
  type,
90
93
  type_system,
@@ -10,6 +10,7 @@ module SmartCore::Initializer::Attribute::Value
10
10
  # @since 0.8.0
11
11
  def dup
12
12
  self.class.new(
13
+ klass,
13
14
  name.dup,
14
15
  type,
15
16
  type_system,
@@ -204,7 +204,7 @@ class SmartCore::Initializer::Constructor::Definer
204
204
  as
205
205
  )
206
206
  SmartCore::Initializer::Attribute::Factory::Param.create(
207
- name, type, type_system, privacy, finalize, cast, mutable, as
207
+ klass, name, type, type_system, privacy, finalize, cast, mutable, as
208
208
  )
209
209
  end
210
210
 
@@ -236,7 +236,7 @@ class SmartCore::Initializer::Constructor::Definer
236
236
  optional
237
237
  )
238
238
  SmartCore::Initializer::Attribute::Factory::Option.create(
239
- name, type, type_system, privacy, finalize, cast, mutable, as, default, optional
239
+ klass, name, type, type_system, privacy, finalize, cast, mutable, as, default, optional
240
240
  )
241
241
  end
242
242
 
@@ -7,6 +7,6 @@ module SmartCore
7
7
  # @api public
8
8
  # @since 0.1.0
9
9
  # @version 0.11.1
10
- VERSION = '0.11.1'
10
+ VERSION = '0.12.0'
11
11
  end
12
12
  end
@@ -40,4 +40,6 @@ Gem::Specification.new do |spec|
40
40
  spec.add_development_dependency 'armitage-rubocop', '~> 1.30'
41
41
  spec.add_development_dependency 'simplecov', '~> 0.21'
42
42
  spec.add_development_dependency 'pry', '~> 0.14'
43
+ spec.add_development_dependency 'ostruct'
44
+ spec.add_development_dependency 'bigdecimal'
43
45
  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.11.1
4
+ version: 0.12.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: 2022-11-25 00:00:00.000000000 Z
11
+ date: 2025-05-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: smart_engine
@@ -136,6 +136,34 @@ dependencies:
136
136
  - - "~>"
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0.14'
139
+ - !ruby/object:Gem::Dependency
140
+ name: ostruct
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: bigdecimal
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
139
167
  description: A simple and convenient way to declare complex constructors
140
168
  email:
141
169
  - iamdaiver@gmail.com
@@ -246,7 +274,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
246
274
  - !ruby/object:Gem::Version
247
275
  version: '0'
248
276
  requirements: []
249
- rubygems_version: 3.3.7
277
+ rubygems_version: 3.5.3
250
278
  signing_key:
251
279
  specification_version: 4
252
280
  summary: Initializer DSL