dry-initializer 0.11.0 → 2.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.codeclimate.yml +8 -0
- data/.gitignore +1 -0
- data/.rspec +1 -0
- data/.rubocop.yml +14 -62
- data/.travis.yml +15 -11
- data/CHANGELOG.md +538 -158
- data/Gemfile +2 -2
- data/LICENSE.txt +1 -1
- data/README.md +6 -6
- data/Rakefile +2 -41
- data/benchmarks/{several_defaults.rb → compare_several_defaults.rb} +4 -4
- data/benchmarks/{without_options.rb → plain_options.rb} +21 -10
- data/benchmarks/{params.rb → plain_params.rb} +20 -9
- data/benchmarks/{with_types.rb → with_coercion.rb} +23 -16
- data/benchmarks/with_defaults.rb +19 -8
- data/benchmarks/{with_types_and_defaults.rb → with_defaults_and_coercion.rb} +21 -12
- data/dry-initializer.gemspec +4 -4
- data/lib/dry/initializer/builders/attribute.rb +81 -0
- data/lib/dry/initializer/builders/initializer.rb +61 -0
- data/lib/dry/initializer/builders/reader.rb +50 -0
- data/lib/dry/initializer/builders/signature.rb +32 -0
- data/lib/dry/initializer/builders.rb +7 -0
- data/lib/dry/initializer/config.rb +172 -0
- data/lib/dry/initializer/definition.rb +116 -0
- data/lib/dry/initializer/dispatchers.rb +44 -0
- data/lib/dry/initializer/dsl.rb +43 -0
- data/lib/dry/initializer/mixin/local.rb +19 -0
- data/lib/dry/initializer/mixin/root.rb +10 -0
- data/lib/dry/initializer/mixin.rb +8 -70
- data/lib/dry/initializer.rb +49 -12
- data/lib/tasks/benchmark.rake +41 -0
- data/lib/tasks/profile.rake +78 -0
- data/spec/attributes_spec.rb +38 -0
- data/spec/coercion_of_nil_spec.rb +25 -0
- data/spec/custom_dispatchers_spec.rb +35 -0
- data/spec/custom_initializer_spec.rb +1 -1
- data/spec/default_values_spec.rb +8 -8
- data/spec/definition_spec.rb +107 -0
- data/spec/invalid_default_spec.rb +2 -2
- data/spec/missed_default_spec.rb +3 -3
- data/spec/optional_spec.rb +35 -8
- data/spec/options_tolerance_spec.rb +1 -1
- data/spec/public_attributes_utility_spec.rb +22 -0
- data/spec/reader_spec.rb +11 -11
- data/spec/repetitive_definitions_spec.rb +41 -21
- data/spec/several_assignments_spec.rb +41 -0
- data/spec/spec_helper.rb +7 -0
- data/spec/subclassing_spec.rb +7 -3
- data/spec/type_argument_spec.rb +1 -1
- data/spec/type_constraint_spec.rb +38 -7
- data/spec/value_coercion_via_dry_types_spec.rb +12 -4
- metadata +37 -40
- data/benchmarks/options.rb +0 -54
- data/benchmarks/params_vs_options.rb +0 -35
- data/lib/dry/initializer/builder.rb +0 -100
- data/lib/dry/initializer/errors/default_value_error.rb +0 -6
- data/lib/dry/initializer/errors/order_error.rb +0 -7
- data/lib/dry/initializer/errors/plugin_error.rb +0 -6
- data/lib/dry/initializer/errors/redefinition_error.rb +0 -5
- data/lib/dry/initializer/errors/type_constraint_error.rb +0 -5
- data/lib/dry/initializer/errors.rb +0 -10
- data/lib/dry/initializer/plugins/base.rb +0 -47
- data/lib/dry/initializer/plugins/default_proc.rb +0 -28
- data/lib/dry/initializer/plugins/signature.rb +0 -28
- data/lib/dry/initializer/plugins/type_constraint.rb +0 -21
- data/lib/dry/initializer/plugins/variable_setter.rb +0 -30
- data/lib/dry/initializer/plugins.rb +0 -10
- data/lib/dry/initializer/signature.rb +0 -61
- data/spec/base_spec.rb +0 -21
- data/spec/container_spec.rb +0 -45
- data/spec/default_nil_spec.rb +0 -17
- data/spec/plugin_registry_spec.rb +0 -45
- data/spec/renaming_options_spec.rb +0 -20
data/CHANGELOG.md
CHANGED
@@ -1,12 +1,434 @@
|
|
1
|
-
|
1
|
+
# Change Log
|
2
|
+
|
3
|
+
All notable changes to this project will be documented in this file.
|
4
|
+
|
5
|
+
The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
6
|
+
and this project adheres to [Semantic Versioning](http://semver.org/).
|
7
|
+
|
8
|
+
## [2.4.0] [2018-02-01]
|
2
9
|
|
3
10
|
### Added
|
11
|
+
- Dispatchers for adding syntax sugar to `param` and `options` (nepalez)
|
4
12
|
|
5
|
-
|
13
|
+
```ruby
|
14
|
+
# Converts `integer: true` to `type: proc(&:to_i)`
|
15
|
+
dispatcher = ->(op) { op[:integer] ? op.merge(type: proc(&:to_i)) : op }
|
16
|
+
# Register a dispatcher
|
17
|
+
Dry::Initializer::Dispatchers << dispatcher
|
18
|
+
# Use syntax sugar
|
19
|
+
class User
|
20
|
+
param :id, integer: true # same as param :id, proc(&:to_i)
|
21
|
+
end
|
22
|
+
```
|
6
23
|
|
7
|
-
|
24
|
+
## [2.3.0] [2017-09-19]
|
8
25
|
|
9
|
-
|
26
|
+
### Added
|
27
|
+
- Type coercer can take second argument for the initialized instance (nepalez)
|
28
|
+
This allows to wrap assigned value to the object that refers back
|
29
|
+
to the initializer instance. More verbose example:
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
class Location < String
|
33
|
+
attr_reader :parameter # refers back to its parameter
|
34
|
+
|
35
|
+
def initialize(name, parameter)
|
36
|
+
super(name)
|
37
|
+
@parameter = parameter
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
class Parameter
|
42
|
+
extend Dry::Initializer
|
43
|
+
param :name
|
44
|
+
param :location, ->(value, param) { Location.new(value, param) }
|
45
|
+
end
|
46
|
+
|
47
|
+
offset = Parameter.new "offset", location: "query"
|
48
|
+
offset.name # => "offset"
|
49
|
+
offset.location # => "query"
|
50
|
+
offset.location.parameter == offset # true
|
51
|
+
```
|
52
|
+
|
53
|
+
## [2.2.0] [2017-09-13]
|
54
|
+
|
55
|
+
### Added
|
56
|
+
- Option `:desc` for option/param to add a description (nepalez)
|
57
|
+
|
58
|
+
- Methods `Definition#inch` and `Config#inch` to inspect definitions (nepalez)
|
59
|
+
|
60
|
+
```ruby
|
61
|
+
class User
|
62
|
+
extend Dry::Initializer
|
63
|
+
option :name, proc(&:to_s), optional: true, desc: "User name"
|
64
|
+
option :email, optional: true, desc: "user email"
|
65
|
+
end
|
66
|
+
|
67
|
+
User.dry_initializer.inch
|
68
|
+
# @!method initialize(*, **options)
|
69
|
+
# Initializes an instance of User
|
70
|
+
# @option [Object] :name (optional) User name
|
71
|
+
# @option [Object] :email (optional) User email
|
72
|
+
# @return [User]
|
73
|
+
```
|
74
|
+
|
75
|
+
## [2.1.0] [2017-09-11]
|
76
|
+
|
77
|
+
### Added
|
78
|
+
- Method `#options` to param/option definition (nepalez)
|
79
|
+
|
80
|
+
```ruby
|
81
|
+
class User
|
82
|
+
extend Dry::Initializer
|
83
|
+
option :name, proc(&:to_s), optional: true
|
84
|
+
option :email, optional: true
|
85
|
+
end
|
86
|
+
|
87
|
+
User.dry_initializer.options.map do |option|
|
88
|
+
[option.source, option.options]
|
89
|
+
end
|
90
|
+
# => [
|
91
|
+
# [:name, { type: proc(&:to_s), as: :name, optional: true }],
|
92
|
+
# [:email, { as: :email, optional: true }]
|
93
|
+
# ]
|
94
|
+
```
|
95
|
+
|
96
|
+
This method can be helpful for replicating params/options
|
97
|
+
in another class without inheritance.
|
98
|
+
|
99
|
+
## [2.0.0] [2017-08-28]
|
100
|
+
|
101
|
+
The gem has been rewritten under the hood keeping its documented
|
102
|
+
interface about the same (see "Deleted" section below for the only
|
103
|
+
backward-incompatible change).
|
104
|
+
|
105
|
+
The main achievement of this version is fixing an edge case where
|
106
|
+
change in params/options of superclass wasn't reflected in its
|
107
|
+
previously declared subclasses.
|
108
|
+
|
109
|
+
Thanks to @solnic for the idea of class-level container,
|
110
|
+
and to @gzigzigzeo for persuading me to do this refactoring.
|
111
|
+
|
112
|
+
### Deleted
|
113
|
+
- Undocumented variable `@__option__` which was the main reason for refactoring
|
114
|
+
(gzigzigzeo, nepalez).
|
115
|
+
|
116
|
+
### Added
|
117
|
+
- Class method `.dry_initializer` -- a container for `.params` and `.options`
|
118
|
+
`.definitions` along with the `.null` setting (either `nil` or `UNDEFINED`)
|
119
|
+
used for unassigned values (nepalez)
|
120
|
+
|
121
|
+
- `.dry_initializer.attributes` method takes an instance of the same class
|
122
|
+
and returns the hash of assigned options. This provide the same
|
123
|
+
functionality as previously used instance variable `@__options__` (nepalez)
|
124
|
+
|
125
|
+
```ruby
|
126
|
+
object.class.dry_initializer.attributes(object)
|
127
|
+
```
|
128
|
+
|
129
|
+
When you use "Dry::Initializer.define -> { ... }" syntax,
|
130
|
+
the class method `.dry_initializer` is not defined. To access attributes
|
131
|
+
you should use private instance method `#__dry_initializer_config__` instead:
|
132
|
+
|
133
|
+
```ruby
|
134
|
+
object.send(:__dry_initializer_config__).attributes(object)
|
135
|
+
```
|
136
|
+
|
137
|
+
Both methods `.dry_initializer` and `#__dry_initializer_config__` refer
|
138
|
+
to the same object.
|
139
|
+
|
140
|
+
- `.dry_initializer.public_attributes`. This method works differently:
|
141
|
+
it looks through (possibly reloaded) readers instead of variables
|
142
|
+
(gzigzigzeo, nepalez)
|
143
|
+
|
144
|
+
```ruby
|
145
|
+
object.class.dry_initializer.public_attributes(object)
|
146
|
+
```
|
147
|
+
|
148
|
+
You can use the same trick as above mutatis mutandis.
|
149
|
+
|
150
|
+
### Fixed
|
151
|
+
- Definition order dependency bug (nepalez)
|
152
|
+
|
153
|
+
I've found out that if you provided a subclass and then changed params
|
154
|
+
or options of its superclass, these changes woudn't be reflected in
|
155
|
+
subclasses until you change any of it params/options as well.
|
156
|
+
|
157
|
+
Now this bug is fixed: every time you call `param` or `option` at
|
158
|
+
any class, the gem scans through all its descendants to the very bottom
|
159
|
+
of the tree, and reloads their defintitions.
|
160
|
+
|
161
|
+
Being done in load time, the rebuilt makes no effect on runtime performance.
|
162
|
+
|
163
|
+
- Possible misbehavior when you define param and option with the same name (nepalez)
|
164
|
+
|
165
|
+
Doing this will provide `option :name` only, not both:
|
166
|
+
|
167
|
+
```ruby
|
168
|
+
param :name
|
169
|
+
option :name
|
170
|
+
```
|
171
|
+
|
172
|
+
- Attempt to redefine param/option of superclass with option/param in
|
173
|
+
its subclass will cause an exception because it would break
|
174
|
+
Liskov substitute principle with unexpected behaviour (nepalez)
|
175
|
+
|
176
|
+
No, you can do neither these definitions, nor vice versa:
|
177
|
+
|
178
|
+
```ruby
|
179
|
+
class Foo
|
180
|
+
extend Dry::Intitializer
|
181
|
+
param :name
|
182
|
+
end
|
183
|
+
|
184
|
+
class Bar < Foo
|
185
|
+
option :name
|
186
|
+
end
|
187
|
+
```
|
188
|
+
|
189
|
+
- When you reloading previously defined param of superclass, the gem
|
190
|
+
will check all its descendands for whether all required positional params
|
191
|
+
goes before optional ones (nepalez)
|
192
|
+
|
193
|
+
```ruby
|
194
|
+
class Foo
|
195
|
+
param :name
|
196
|
+
# Foo: def initializer(name)
|
197
|
+
end
|
198
|
+
|
199
|
+
class Bar
|
200
|
+
param :email
|
201
|
+
# Bar: def initializer(name, email)
|
202
|
+
end
|
203
|
+
|
204
|
+
class Foo
|
205
|
+
# This raises SyntaxError because in Bar this would cause wrong definition
|
206
|
+
# Foo: def initializer(name = nil)
|
207
|
+
# Bar: def initializer(name = nil, email)
|
208
|
+
param :name, optional: true
|
209
|
+
end
|
210
|
+
```
|
211
|
+
|
212
|
+
### Changed
|
213
|
+
- Under the hood I've separated param/option settings declaration (a container
|
214
|
+
with param/option settings) from code builders for initializer and readers
|
215
|
+
(nepalez)
|
216
|
+
|
217
|
+
You can check both the code for the `__initializer__`:
|
218
|
+
|
219
|
+
```ruby
|
220
|
+
class Foo
|
221
|
+
extend Dry::Initializer
|
222
|
+
# ...
|
223
|
+
end
|
224
|
+
|
225
|
+
Foo.dry_initializer.code
|
226
|
+
```
|
227
|
+
|
228
|
+
and readers:
|
229
|
+
|
230
|
+
```ruby
|
231
|
+
Foo.dry_initializer.params.map(&:code)
|
232
|
+
Foo.dry_initializer.options.map(&:code)
|
233
|
+
|
234
|
+
# or
|
235
|
+
|
236
|
+
Foo.dry_initializer.definitions.values.map(&:code)
|
237
|
+
```
|
238
|
+
|
239
|
+
You can also check settings for every param and option using methods
|
240
|
+
`dry_initializer.params`, `dry_initializer.options` (lists), or
|
241
|
+
`dry_initializer.definitions` (hash).
|
242
|
+
|
243
|
+
You can check null value via `.dry_initializer.null` which is different
|
244
|
+
for `Dry::Initializer` and `Dry::Initializer[undefined: false]` modules.
|
245
|
+
|
246
|
+
- Optimized the code for `__initializer__`-s (the method where all magics occurs)
|
247
|
+
(nepalez)
|
248
|
+
|
249
|
+
Benchmarks remained about the same:
|
250
|
+
|
251
|
+
```shell
|
252
|
+
rake benchmark
|
253
|
+
```
|
254
|
+
|
255
|
+
```
|
256
|
+
Benchmark for instantiation with plain params
|
257
|
+
value_struct: 4317196.9 i/s
|
258
|
+
plain Ruby: 4129803.9 i/s - 1.05x slower
|
259
|
+
dry-initializer: 1710702.1 i/s - 2.52x slower
|
260
|
+
concord: 1372630.4 i/s - 3.15x slower
|
261
|
+
values: 601651.8 i/s - 7.18x slower
|
262
|
+
attr_extras: 535599.5 i/s - 8.06x slower
|
263
|
+
```
|
264
|
+
|
265
|
+
```
|
266
|
+
Benchmark for instantiation with plain options
|
267
|
+
plain Ruby: 1769174.1 i/s
|
268
|
+
dry-initializer: 636634.1 i/s - 2.78x slower
|
269
|
+
kwattr: 423296.5 i/s - 4.18x slower
|
270
|
+
anima: 399415.0 i/s - 4.43x slower
|
271
|
+
```
|
272
|
+
|
273
|
+
```
|
274
|
+
Benchmark for instantiation with coercion
|
275
|
+
plain Ruby: 1565501.0 i/s
|
276
|
+
fast_attributes: 569952.9 i/s - 2.75x slower
|
277
|
+
dry-initializer: 461122.1 i/s - 3.39x slower
|
278
|
+
virtus: 138074.8 i/s - 11.34x slower
|
279
|
+
```
|
280
|
+
|
281
|
+
```
|
282
|
+
Benchmark for instantiation with default values
|
283
|
+
plain Ruby: 3402455.4 i/s
|
284
|
+
kwattr: 586206.5 i/s - 5.80x slower
|
285
|
+
dry-initializer: 528482.2 i/s - 6.44x slower
|
286
|
+
active_attr: 298697.7 i/s - 11.39x slower
|
287
|
+
```
|
288
|
+
|
289
|
+
```
|
290
|
+
Benchmark for instantiation with type constraints and default values
|
291
|
+
plain Ruby: 2881696.1 i/s
|
292
|
+
dry-initializer: 470815.1 i/s - 6.12x slower
|
293
|
+
virtus: 180272.6 i/s - 15.99x slower
|
294
|
+
```
|
295
|
+
|
296
|
+
## [1.4.1] [2017-04-05]
|
297
|
+
|
298
|
+
### Fixed
|
299
|
+
- Warning about redefined `#initialize` in case the method reloaded in a klass
|
300
|
+
that extends the module (nepalez, sergey-chechaev)
|
301
|
+
|
302
|
+
### Changed
|
303
|
+
- Rename `Dry::Initializer::DSL` -> `Dry::Initializer::ClassDSL` (nepalez)
|
304
|
+
- Add `Dry::Initializer::InstanceDSL` (nepalez)
|
305
|
+
|
306
|
+
### Deprecated
|
307
|
+
- `Dry::Initializer::Mixin`. In latest version this was an alias for
|
308
|
+
`Dry::Initializer` that kept for backward compatibility for early versions of the gem.
|
309
|
+
|
310
|
+
This story will come to the end in `v2.1.0`.
|
311
|
+
|
312
|
+
## [1.4.0] [2017-03-08]
|
313
|
+
|
314
|
+
### Changed (backward-incompatible)
|
315
|
+
- The `@__options__` hash now collects all assigned attributes,
|
316
|
+
collected via `#option` (as before), and `#param` (nepalez)
|
317
|
+
|
318
|
+
## [1.3.0] [2017-03-05]
|
319
|
+
|
320
|
+
### Added
|
321
|
+
- No-undefined configuration of the initializer (nepalez, flash-gordon)
|
322
|
+
|
323
|
+
You can either extend or include module `Dry::Initializer` with additional option
|
324
|
+
`[undefined: false]`. This time `nil` will be assigned instead of
|
325
|
+
`Dry::Initializer::UNDEFINED`. Readers becomes faster because there is no need
|
326
|
+
to chech whether a variable was defined or not. At the same time the initializer
|
327
|
+
doesn't distinct cases when a variable was set to `nil` explicitly, and when it wasn's set at all:
|
328
|
+
|
329
|
+
class Foo # old behavior
|
330
|
+
extend Dry::Initializer
|
331
|
+
param :qux, optional: true
|
332
|
+
end
|
333
|
+
|
334
|
+
class Bar # new behavior
|
335
|
+
extend Dry::Initializer[undefined: false]
|
336
|
+
param :qux, optional: true
|
337
|
+
end
|
338
|
+
|
339
|
+
Foo.new.instance_variable_get(:@qux) # => Dry::Initializer::UNDEFINED
|
340
|
+
Bar.new.instance_variable_get(:@qux) # => nil
|
341
|
+
|
342
|
+
### Changed
|
343
|
+
- Fixed method definitions for performance at the load time (nepalez, flash-gordon)
|
344
|
+
|
345
|
+
## [1.2.0] [2017-03-05]
|
346
|
+
|
347
|
+
### Fixed
|
348
|
+
- The `@__options__` variable collects renamed options after default values and coercions were applied (nepalez)
|
349
|
+
|
350
|
+
## [1.1.3] [2017-03-01]
|
351
|
+
|
352
|
+
### Added
|
353
|
+
- Support for lambdas as default values (nepalez, gzigzigzeo)
|
354
|
+
|
355
|
+
## [1.1.2] [2017-02-06]
|
356
|
+
|
357
|
+
### Changed
|
358
|
+
- Remove previously defined methods before redefining them (flash-gordon)
|
359
|
+
|
360
|
+
## [1.1.1] [2017-02-04]
|
361
|
+
|
362
|
+
### Fixed
|
363
|
+
- `@__options__` collects defined options only (nepalez)
|
364
|
+
|
365
|
+
## [1.1.0] [2017-01-28]
|
366
|
+
|
367
|
+
### Added
|
368
|
+
- enhancement via `Dry::Initializer::Attribute.dispatchers` registry (nepalez)
|
369
|
+
|
370
|
+
# Register dispatcher for `:string` option
|
371
|
+
Dry::Initializer::Attribute.dispatchers << ->(string: nil, **op) do
|
372
|
+
string ? op.merge(type: proc(&:to_s)) : op
|
373
|
+
end
|
374
|
+
|
375
|
+
# Now you can use the `:string` key for `param` and `option`
|
376
|
+
class User
|
377
|
+
extend Dry::Initializer
|
378
|
+
param :name, string: true
|
379
|
+
end
|
380
|
+
|
381
|
+
User.new(:Andy).name # => "Andy"
|
382
|
+
|
383
|
+
### Changed
|
384
|
+
- optimize assignments for performance (nepalez)
|
385
|
+
|
386
|
+
## [1.0.0] [2017-01-22]
|
387
|
+
|
388
|
+
In this version the code has been rewritten for simplicity
|
389
|
+
|
390
|
+
### Changed
|
391
|
+
- [BREAKING] when `param` or `option` was not defined, the corresponding **variable** is set to `Dry::Initializer::UNDEFINED`, but the **reader** (when defined) will return `nil` (nepalez)
|
392
|
+
|
393
|
+
- `Dry::Initializer` and `Dry::Initializer::Mixin` became aliases (nepalez)
|
394
|
+
|
395
|
+
### Added
|
396
|
+
- support for reloading `param` and `option` definitions (nepalez)
|
397
|
+
|
398
|
+
class User
|
399
|
+
extend Dry::Initializer
|
400
|
+
param :name
|
401
|
+
param :phone, optional: true
|
402
|
+
end
|
403
|
+
|
404
|
+
User.new # => Boom!
|
405
|
+
|
406
|
+
class Admin < User
|
407
|
+
param :name, default: proc { 'Merlin' }
|
408
|
+
end
|
409
|
+
|
410
|
+
# order of the param not changed
|
411
|
+
Admin.new.name # => "Merlin"
|
412
|
+
|
413
|
+
- support for assignment of attributes via several options (nepalez)
|
414
|
+
|
415
|
+
class User
|
416
|
+
extend Dry::Initializer
|
417
|
+
option :phone
|
418
|
+
option :number, as: :phone
|
419
|
+
end
|
420
|
+
|
421
|
+
# Both ways provide the same result
|
422
|
+
User.new(phone: '1234567890').phone # => '1234567890'
|
423
|
+
User.new(number: '1234567890').phone # => '1234567890'
|
424
|
+
|
425
|
+
## [0.11.0] [2017-01-02]
|
426
|
+
|
427
|
+
### Added
|
428
|
+
- Support of reloading `#initializer` with `super` (nepalez)
|
429
|
+
|
430
|
+
### Internal
|
431
|
+
- Refactor the way [#initializer] method is (re)defined (nepalez)
|
10
432
|
|
11
433
|
When you extend class with `Dry::Initializer::Mixin`, the initializer is
|
12
434
|
defined not "inside" the class per se, but inside the included module. The
|
@@ -31,105 +453,74 @@
|
|
31
453
|
|
32
454
|
See specification `spec/custom_initializer_spec.rb` to see how this works.
|
33
455
|
|
34
|
-
[
|
35
|
-
|
36
|
-
## v0.10.2 2016-12-31
|
456
|
+
## [0.10.2] [2016-12-31]
|
37
457
|
|
38
458
|
### Added
|
39
|
-
|
40
|
-
* Support of Ruby 2.4 (@flas-gordon)
|
459
|
+
- Support of Ruby 2.4 (flas-gordon)
|
41
460
|
|
42
461
|
### Internal
|
462
|
+
- Code clearance for ROM integration (flash-gordon)
|
43
463
|
|
44
|
-
|
45
|
-
|
46
|
-
[Compare v0.10.1...v0.10.2](https://github.com/dry-rb/dry-initializer/compare/v0.10.1...v0.10.2)
|
47
|
-
|
48
|
-
## v0.10.1 2016-12-27
|
464
|
+
## [0.10.1] [2016-12-27]
|
49
465
|
|
50
466
|
### Fixed
|
467
|
+
- Wrong arity when there were no options and the last param had a default (nolith)
|
51
468
|
|
52
|
-
|
53
|
-
|
54
|
-
[Compare v0.10.0...v0.10.1](https://github.com/dry-rb/dry-initializer/compare/v0.10.0...v0.10.1)
|
55
|
-
|
56
|
-
## v0.10.0 2016-11-20
|
469
|
+
## [0.10.0] [2016-11-20]
|
57
470
|
|
58
471
|
### Deleted (BREAKING CHANGE!)
|
472
|
+
- Deprecated method DSL#using (nepalez)
|
59
473
|
|
60
|
-
|
61
|
-
|
62
|
-
[Compare v0.9.3...v0.10.0](https://github.com/dry-rb/dry-initializer/compare/v0.9.3...v0.10.0)
|
63
|
-
|
64
|
-
## v0.9.3 2016-11-20
|
474
|
+
## [0.9.3] [2016-11-20]
|
65
475
|
|
66
476
|
### Deprecated
|
67
|
-
|
68
|
-
* After discussion in [PR #17](https://github.com/dry-rb/dry-initializer/pull/17)
|
477
|
+
- After discussion in [PR #17]: https://github.com/dry-rb/dry-initializer/pull/17)
|
69
478
|
(many thanks to @sahal2080 and @hrom512 for starting that issue and PR),
|
70
|
-
the method `using` is deprecated and will be removed from v0.10.0 (
|
479
|
+
the method `using` is deprecated and will be removed from v0.10.0 (nepalez)
|
71
480
|
|
72
481
|
### Fixed
|
73
|
-
|
74
|
-
* Support of weird option names (@nepalez)
|
482
|
+
- Support of weird option names (nepalez)
|
75
483
|
|
76
484
|
```ruby
|
77
485
|
option :"First name", as: :first_name
|
78
486
|
```
|
79
487
|
|
80
|
-
[
|
81
|
-
|
82
|
-
## v0.9.2 2016-11-10
|
488
|
+
## [0.9.2] [2016-11-10]
|
83
489
|
|
84
490
|
### Fixed
|
491
|
+
- Validation of attributes (params and options) (nepalez)
|
85
492
|
|
86
|
-
|
87
|
-
|
88
|
-
[Compare v0.9.1...v0.9.2](https://github.com/dry-rb/dry-initializer/compare/v0.9.1...v0.9.2)
|
89
|
-
|
90
|
-
## v0.9.1 2016-11-06
|
493
|
+
## [0.9.1] [2016-11-06]
|
91
494
|
|
92
495
|
### Added
|
93
|
-
|
94
|
-
* Support for renaming an option during initialization (@nepalez)
|
496
|
+
- Support for renaming an option during initialization (nepalez)
|
95
497
|
|
96
498
|
option :name, as: :username # to take :name option and create :username attribute
|
97
499
|
|
98
|
-
[
|
99
|
-
|
100
|
-
## v0.9.0 2016-11-06
|
500
|
+
## [0.9.0] [2016-11-06]
|
101
501
|
|
102
502
|
### Added
|
103
|
-
|
104
|
-
* The method `#initialize` is defined when a class extended the module (@nepalez)
|
503
|
+
- The method `#initialize` is defined when a class extended the module (nepalez)
|
105
504
|
|
106
505
|
In previous versions the method was defined only by `param` and `option` calls.
|
107
506
|
|
108
507
|
### Breaking Changes
|
109
|
-
|
110
|
-
* The initializer accepts any option (but skips unknown) from the very beginning (@nepalez)
|
508
|
+
- The initializer accepts any option (but skips unknown) from the very beginning (nepalez)
|
111
509
|
|
112
510
|
### Deleted
|
113
|
-
|
114
|
-
* Deprecated methods `tolerant_to_unknown_options` and `intolerant_to_unknown_options` (@nepalez)
|
511
|
+
- Deprecated methods `tolerant_to_unknown_options` and `intolerant_to_unknown_options` (nepalez)
|
115
512
|
|
116
513
|
### Internal
|
514
|
+
- Refactor scope (`using`) to support methods renaming and aliasing (nepalez)
|
117
515
|
|
118
|
-
|
119
|
-
|
120
|
-
[Compare v0.8.1...v0.9.0](https://github.com/dry-rb/dry-initializer/compare/v0.8.1...v0.9.0)
|
121
|
-
|
122
|
-
## v0.8.1 2016-11-05
|
516
|
+
## [0.8.1] [2016-11-05]
|
123
517
|
|
124
518
|
### Added
|
125
|
-
|
126
|
-
* Support for `dry-struct`ish syntax for constraints (type as a second parameter) (@nepalez)
|
519
|
+
- Support for `dry-struct`ish syntax for constraints (type as a second parameter) (nepalez)
|
127
520
|
|
128
521
|
option :name, Dry::Types['strict.string']
|
129
522
|
|
130
|
-
[
|
131
|
-
|
132
|
-
## v0.8.0 2016-11-05
|
523
|
+
## [0.8.0] [2016-11-05]
|
133
524
|
|
134
525
|
In this version we switched from key arguments to ** to support special keys:
|
135
526
|
|
@@ -157,83 +548,57 @@ Methods `tolerant_to_unknown_options` and `intolerant_to_unknown_options`
|
|
157
548
|
are deprecated and will be removed in the next version of the gem.
|
158
549
|
|
159
550
|
### Added
|
551
|
+
- support for special options like `option :end`, `option :begin` etc. (nepalez)
|
160
552
|
|
161
|
-
|
162
|
-
|
163
|
-
### Internals
|
164
|
-
|
165
|
-
* switched from key arguments to serialized hash argument in the initializer (@nepalez)
|
553
|
+
### Changed
|
554
|
+
- switched from key arguments to serialized hash argument in the initializer (nepalez)
|
166
555
|
|
167
556
|
### Breaking Changes
|
168
|
-
|
169
|
-
* the initializer becomes tolerant to unknown options when any `option` was set,
|
557
|
+
- the initializer becomes tolerant to unknown options when any `option` was set,
|
170
558
|
ignoring `intolerant_to_unknown_options` helper.
|
171
559
|
|
172
|
-
|
560
|
+
- the initializer becomes intolerant to options when no `option` was set,
|
173
561
|
ignoring `tolerant_to_unknown_options` helper.
|
174
562
|
|
175
563
|
### Deprecated
|
564
|
+
- `tolerant_to_unknown_options`
|
565
|
+
- `intolerant_to_unknown_options`
|
176
566
|
|
177
|
-
|
178
|
-
* `intolerant_to_unknown_options`
|
179
|
-
|
180
|
-
[Compare v0.7.0...v0.8.0](https://github.com/dry-rb/dry-initializer/compare/v0.7.0...v0.8.0)
|
181
|
-
|
182
|
-
## v0.7.0 2016-10-11
|
567
|
+
## [0.7.0] [2016-10-11]
|
183
568
|
|
184
569
|
### Added
|
570
|
+
- Shared settings with `#using` method (nepalez)
|
185
571
|
|
186
|
-
|
187
|
-
|
188
|
-
[Compare v0.6.0...v0.7.0](https://github.com/dry-rb/dry-initializer/compare/v0.6.0...v0.7.0)
|
189
|
-
|
190
|
-
## v0.6.0 2016-10-09
|
572
|
+
## [0.6.0] [2016-10-09]
|
191
573
|
|
192
574
|
### Added
|
575
|
+
- Support for private and protected readers in the `reader:` option (jmgarnier)
|
193
576
|
|
194
|
-
|
195
|
-
|
196
|
-
[Compare v0.5.0...v0.6.0](https://github.com/dry-rb/dry-initializer/compare/v0.5.0...v0.6.0)
|
197
|
-
|
198
|
-
## v0.5.0 2016-08-21
|
577
|
+
## [0.5.0] [2016-08-21]
|
199
578
|
|
200
579
|
### Added
|
580
|
+
- Allow `optional` attribute to be left undefined (nepalez)
|
201
581
|
|
202
|
-
|
203
|
-
|
204
|
-
[Compare v0.4.0...v0.5.0](https://github.com/dry-rb/dry-initializer/compare/v0.4.0...v0.5.0)
|
205
|
-
|
206
|
-
## v0.4.0 2016-05-28
|
582
|
+
## [0.4.0] [2016-05-28]
|
207
583
|
|
208
584
|
### Deleted (backward-incompatible changes)
|
585
|
+
- Support of modules and case equality as type constraints (nepalez)
|
209
586
|
|
210
|
-
|
211
|
-
|
212
|
-
[Compare v0.3.3...v0.4.0](https://github.com/dry-rb/dry-initializer/compare/v0.3.3...v0.4.0)
|
213
|
-
|
214
|
-
## v0.3.3 2016-05-28
|
215
|
-
|
216
|
-
* Add deprecation warnings about modules and case equality as type constraints (@nepalez)
|
587
|
+
## [0.3.3] [2016-05-28]
|
217
588
|
|
218
|
-
|
589
|
+
- Add deprecation warnings about modules and case equality as type constraints (nepalez)
|
219
590
|
|
220
|
-
##
|
591
|
+
## [0.3.2] [2016-05-25]
|
221
592
|
|
222
|
-
###
|
223
|
-
|
224
|
-
* Add explicit requirement for ruby 'set' (@rickenharp)
|
225
|
-
|
226
|
-
[Compare v0.3.1...v0.3.2](https://github.com/dry-rb/dry-initializer/compare/v0.3.1...v0.3.2)
|
593
|
+
### Fixed
|
594
|
+
- Add explicit requirement for ruby 'set' (rickenharp)
|
227
595
|
|
228
|
-
##
|
596
|
+
## [0.3.1] [2016-05-22]
|
229
597
|
|
230
598
|
### Added
|
599
|
+
- Support for tolerance to unknown options (nepalez)
|
231
600
|
|
232
|
-
|
233
|
-
|
234
|
-
[Compare v0.3.0...v0.3.1](https://github.com/dry-rb/dry-initializer/compare/v0.3.0...v0.3.1)
|
235
|
-
|
236
|
-
## v0.3.0 2016-05-19
|
601
|
+
## [0.3.0] [2016-05-19]
|
237
602
|
|
238
603
|
Breaks interface for adding new plugins. Register new plugin via:
|
239
604
|
|
@@ -255,39 +620,28 @@ While the private method ##initializer_builder is still accessible
|
|
255
620
|
its method #register doesn't mutate the builder instance.
|
256
621
|
|
257
622
|
### Changed (backward-incompatible changes)
|
623
|
+
- Made Mixin##initializer_builder method private (nepalez)
|
624
|
+
- Add Mixin#register_initializer_plugin(plugin) method (nepalez)
|
258
625
|
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
### Bugs Fixed
|
263
|
-
|
264
|
-
* Prevent plugin's registry from polluting superclass (@nepalez)
|
265
|
-
|
266
|
-
[Compare v0.2.1...v0.3.0](https://github.com/dry-rb/dry-initializer/compare/v0.2.1...v0.3.0)
|
267
|
-
|
268
|
-
### Internals
|
269
|
-
|
270
|
-
* Make all instances (Builder and Signature) immutable (@nepalez)
|
271
|
-
* Decouple mixin from a builder to prevent pollution (@nepalez)
|
272
|
-
* Ensure default value block can use private variables (@jeremyf)
|
273
|
-
|
274
|
-
[Compare v0.2.0...v0.2.1](https://github.com/dry-rb/dry-initializer/compare/v0.2.0...v0.2.1)
|
275
|
-
|
276
|
-
## v0.2.1 2016-05-19
|
277
|
-
|
278
|
-
### Bugs Fixed
|
626
|
+
### Fixed
|
627
|
+
- Prevent plugin's registry from polluting superclass (nepalez)
|
279
628
|
|
280
|
-
|
629
|
+
### Changed
|
630
|
+
- Make all instances (Builder and Signature) immutable (nepalez)
|
631
|
+
- Decouple mixin from a builder to prevent pollution (nepalez)
|
632
|
+
- Ensure default value block can use private variables (jeremyf)
|
281
633
|
|
282
|
-
|
634
|
+
## [0.2.1] [2016-05-19]
|
283
635
|
|
284
|
-
|
285
|
-
|
286
|
-
* Ensure default value block can use private variables (@jeremyf)
|
636
|
+
### Fixed
|
637
|
+
- Fix polluting superclass with declarations from subclass (nepalez)
|
287
638
|
|
288
|
-
|
639
|
+
### Changed
|
640
|
+
- Make all instances (Builder and Signature) immutable (nepalez)
|
641
|
+
- Decouple mixin from a builder to prevent pollution (nepalez)
|
642
|
+
- Ensure default value block can use private variables (jeremyf)
|
289
643
|
|
290
|
-
##
|
644
|
+
## [0.2.0] [2016-05-16]
|
291
645
|
|
292
646
|
The gem internals has been rewritten heavily to make the gem pluggable and fix
|
293
647
|
bugs in "container style". Type constraints were extracted to a plugin
|
@@ -299,15 +653,14 @@ object, and apply value coercion via `dry-types`.
|
|
299
653
|
Default assignments became slower (while plain type constraint are not)!
|
300
654
|
|
301
655
|
### Changed (backward-incompatible changes)
|
302
|
-
|
303
|
-
* Make dry-types constraint to coerce variables (@nepalez)
|
656
|
+
- Make dry-types constraint to coerce variables (nepalez)
|
304
657
|
|
305
658
|
```ruby
|
306
659
|
# This will coerce `name: :foo` to `"foo"`
|
307
660
|
option :name, type: Dry::Types::Coercible::String
|
308
661
|
```
|
309
662
|
|
310
|
-
|
663
|
+
- Stop supporing proc type constraint (nepalez)
|
311
664
|
|
312
665
|
```ruby
|
313
666
|
option :name, type: ->(v) { String === v } # this does NOT work any more
|
@@ -327,20 +680,18 @@ Default assignments became slower (while plain type constraint are not)!
|
|
327
680
|
```
|
328
681
|
|
329
682
|
### Added
|
330
|
-
|
331
|
-
* Support type constraint via every object's case equality (@nepalez)
|
683
|
+
- Support type constraint via every object's case equality (nepalez)
|
332
684
|
|
333
685
|
```ruby
|
334
686
|
option :name, type: /foo/
|
335
687
|
option :name, type: (1...14)
|
336
688
|
```
|
337
689
|
|
338
|
-
|
339
|
-
|
690
|
+
- Support defaults and type constraints for the "container" syntax (nepalez)
|
691
|
+
- Support adding extensions via plugin system (nepalez)
|
340
692
|
|
341
693
|
### Internal
|
342
|
-
|
343
|
-
* Private method `##__after_initialize__` is added by the `Mixin` along with `#initialize` (@nepalez)
|
694
|
+
- Private method `##__after_initialize__` is added by the `Mixin` along with `#initialize` (nepalez)
|
344
695
|
|
345
696
|
The previous implementation required defaults and types to be stored in the class method `.initializer_builder`.
|
346
697
|
That made "container" syntax to support neither defaults nor types.
|
@@ -350,31 +701,60 @@ Default assignments became slower (while plain type constraint are not)!
|
|
350
701
|
They are made inside `##__after_initialize__` callback, that is biult via `default_method(&block)`
|
351
702
|
using instance evals.
|
352
703
|
|
353
|
-
[
|
354
|
-
|
355
|
-
## v0.1.1 2016-04-28
|
704
|
+
## [0.1.1] [2016-04-28]
|
356
705
|
|
357
706
|
### Added
|
707
|
+
- `include Dry::Initializer.define -> do ... end` syntax (flash-gordon)
|
358
708
|
|
359
|
-
|
360
|
-
|
361
|
-
[Compare v0.1.0...v0.1.1](https://github.com/dry-rb/dry-initializer/compare/v0.1.0...v0.1.1)
|
362
|
-
|
363
|
-
## v0.1.0 2016-04-26
|
709
|
+
## [0.1.0] [2016-04-26]
|
364
710
|
|
365
711
|
Class DSL splitted to mixin and container versions (thanks to @AMHOL for the idea).
|
366
712
|
Backward compatibility is broken.
|
367
713
|
|
368
714
|
### Changed (backward-incompatible changes)
|
369
|
-
|
370
|
-
* Use `extend Dry::Initializer::Mixin` instead of `extend Dry::Initializer` (@nepalez)
|
715
|
+
- Use `extend Dry::Initializer::Mixin` instead of `extend Dry::Initializer` (nepalez)
|
371
716
|
|
372
717
|
### Added
|
718
|
+
- Use `include Dry::Initializer.define(&block)` as an alternative to extending the class (nepalez)
|
373
719
|
|
374
|
-
|
375
|
-
|
376
|
-
[Compare v0.0.1...v0.1.0](https://github.com/dry-rb/dry-initializer/compare/v0.0.1...v0.1.0)
|
377
|
-
|
378
|
-
## v0.0.1 2016-04-09
|
720
|
+
## [0.0.1] [2016-04-09]
|
379
721
|
|
380
722
|
First public release
|
723
|
+
|
724
|
+
[0.1.0]: https://github.com/dry-rb/dry-initializer/compare/v0.0.1...v0.1.0
|
725
|
+
[0.1.1]: https://github.com/dry-rb/dry-initializer/compare/v0.1.0...v0.1.1
|
726
|
+
[0.2.0]: https://github.com/dry-rb/dry-initializer/compare/v0.1.1...v0.2.0
|
727
|
+
[0.2.1]: https://github.com/dry-rb/dry-initializer/compare/v0.2.0...v0.2.1
|
728
|
+
[0.2.1]: https://github.com/dry-rb/dry-initializer/compare/v0.2.0...v0.2.1
|
729
|
+
[0.3.0]: https://github.com/dry-rb/dry-initializer/compare/v0.2.1...v0.3.0
|
730
|
+
[0.3.1]: https://github.com/dry-rb/dry-initializer/compare/v0.3.0...v0.3.1
|
731
|
+
[0.3.2]: https://github.com/dry-rb/dry-initializer/compare/v0.3.1...v0.3.2
|
732
|
+
[0.3.3]: https://github.com/dry-rb/dry-initializer/compare/v0.3.2...v0.3.3
|
733
|
+
[0.4.0]: https://github.com/dry-rb/dry-initializer/compare/v0.3.3...v0.4.0
|
734
|
+
[0.5.0]: https://github.com/dry-rb/dry-initializer/compare/v0.4.0...v0.5.0
|
735
|
+
[0.6.0]: https://github.com/dry-rb/dry-initializer/compare/v0.5.0...v0.6.0
|
736
|
+
[0.7.0]: https://github.com/dry-rb/dry-initializer/compare/v0.6.0...v0.7.0
|
737
|
+
[0.8.0]: https://github.com/dry-rb/dry-initializer/compare/v0.7.0...v0.8.0
|
738
|
+
[0.8.1]: https://github.com/dry-rb/dry-initializer/compare/v0.8.0...v0.8.1
|
739
|
+
[0.9.0]: https://github.com/dry-rb/dry-initializer/compare/v0.8.1...v0.9.0
|
740
|
+
[0.9.1]: https://github.com/dry-rb/dry-initializer/compare/v0.9.0...v0.9.1
|
741
|
+
[0.9.2]: https://github.com/dry-rb/dry-initializer/compare/v0.9.1...v0.9.2
|
742
|
+
[0.9.3]: https://github.com/dry-rb/dry-initializer/compare/v0.9.2...v0.9.3
|
743
|
+
[0.10.0]: https://github.com/dry-rb/dry-initializer/compare/v0.9.3...v0.10.0
|
744
|
+
[0.10.1]: https://github.com/dry-rb/dry-initializer/compare/v0.10.0...v0.10.1
|
745
|
+
[0.10.2]: https://github.com/dry-rb/dry-initializer/compare/v0.10.1...v0.10.2
|
746
|
+
[0.11.0]: https://github.com/dry-rb/dry-initializer/compare/v0.10.2...v0.11.0
|
747
|
+
[1.0.0]: https://github.com/dry-rb/dry-initializer/compare/v0.11.0...v1.0.0
|
748
|
+
[1.1.0]: https://github.com/dry-rb/dry-initializer/compare/v1.0.0...v1.1.0
|
749
|
+
[1.1.1]: https://github.com/dry-rb/dry-initializer/compare/v1.1.0...v1.1.1
|
750
|
+
[1.1.2]: https://github.com/dry-rb/dry-initializer/compare/v1.1.1...v1.1.2
|
751
|
+
[1.1.3]: https://github.com/dry-rb/dry-initializer/compare/v1.1.2...v1.1.3
|
752
|
+
[1.2.0]: https://github.com/dry-rb/dry-initializer/compare/v1.1.3...v1.2.0
|
753
|
+
[1.3.0]: https://github.com/dry-rb/dry-initializer/compare/v1.2.0...v1.3.0
|
754
|
+
[1.4.0]: https://github.com/dry-rb/dry-initializer/compare/v1.3.0...v1.4.0
|
755
|
+
[1.4.1]: https://github.com/dry-rb/dry-initializer/compare/v1.4.0...v1.4.1
|
756
|
+
[2.0.0]: https://github.com/dry-rb/dry-initializer/compare/v1.4.1...v2.0.0
|
757
|
+
[2.1.0]: https://github.com/dry-rb/dry-initializer/compare/v2.0.0...v2.1.0
|
758
|
+
[2.2.0]: https://github.com/dry-rb/dry-initializer/compare/v2.1.0...v2.2.0
|
759
|
+
[2.3.0]: https://github.com/dry-rb/dry-initializer/compare/v2.2.0...v2.3.0
|
760
|
+
[2.4.0]: https://github.com/dry-rb/dry-initializer/compare/v2.3.0...v2.4.0
|