vcdry 1.0.0 → 1.0.1
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 +4 -4
- data/CHANGELOG.md +7 -1
- data/README.md +20 -0
- data/lib/vcdry/config.rb +8 -1
- data/lib/vcdry/dsl.rb +13 -3
- data/lib/vcdry/registry.rb +1 -1
- data/lib/vcdry/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ea70c4d286339f58ec30b1c77ae5ecc1579c52ec511d17aed9ba7afb82b68e36
|
4
|
+
data.tar.gz: 2c0209b85f1175c3f2463b7b8c821eaa30829c88c10ea2b354d5b656079c7391
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3f118fe1853440ed1f5fe649851f7801000cd81787022c5ae0cafdab688330a8a3ac452f82321810dbb9906ecbc68b1b8eb5c763d0e9a256a290d59840ca470b
|
7
|
+
data.tar.gz: b4bfbb7e38542cf36bd28503612e8cc4305e3120328e5b13df0305c24d4325f4f8bad71ebf63d879b497dcaff223537b662c3645c80a09dfeaa4e31a110eea43
|
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,10 @@
|
|
1
|
-
## [
|
1
|
+
## [1.0.1] - 2023-04-28
|
2
|
+
|
3
|
+
- Added initializer callbacks.
|
4
|
+
- Treat `default: nil` and `optional: true` identically.
|
5
|
+
- Fix for `other_keywords` to accept the optional type as intended.
|
6
|
+
- Fix for inheritance issues when including VCDry::DSL on a parent component.
|
7
|
+
- Fix to allow passing `nil` to an optional keyword.
|
2
8
|
|
3
9
|
## [1.0.0] - 2023-04-16
|
4
10
|
|
data/README.md
CHANGED
@@ -40,6 +40,7 @@ end
|
|
40
40
|
- [other_keywords](#other_keywords)
|
41
41
|
- [strict_keywords](#strict_keywords)
|
42
42
|
- [remove_keyword](#remove_keyword)
|
43
|
+
- [Callbacks](#callbacks)
|
43
44
|
- [Types](#types)
|
44
45
|
- [Development](#development)
|
45
46
|
- [Contributing](#contributing)
|
@@ -260,6 +261,25 @@ class MyOtherComponent < MyComponent
|
|
260
261
|
end
|
261
262
|
```
|
262
263
|
|
264
|
+
### Callbacks
|
265
|
+
|
266
|
+
Including `VCDry::DSL` adds support through `ActiveModel::Callbacks` for the
|
267
|
+
`before_initialize`, `after_initialization`, and `around_initialize` callbacks
|
268
|
+
to minimize the need to override the initlialize method.
|
269
|
+
|
270
|
+
```ruby
|
271
|
+
class MyComponent < MyComponent
|
272
|
+
before_initialize ->() { @links = [] }
|
273
|
+
after_intialize :some_method
|
274
|
+
|
275
|
+
private
|
276
|
+
|
277
|
+
def some_method
|
278
|
+
# do something fancy
|
279
|
+
end
|
280
|
+
end
|
281
|
+
```
|
282
|
+
|
263
283
|
## Types
|
264
284
|
|
265
285
|
The following types are built-in to `vcdry`.
|
data/lib/vcdry/config.rb
CHANGED
@@ -13,6 +13,12 @@ module VCDry
|
|
13
13
|
@name = name.to_sym
|
14
14
|
@type = (type.nil? || type.respond_to?(:call)) ? type : VCDry::Types[type]
|
15
15
|
@options = options
|
16
|
+
|
17
|
+
# Translate default: nil to optional: true
|
18
|
+
if @options.key?(:default) && @options[:default].nil?
|
19
|
+
@options.delete(:default)
|
20
|
+
@options[:optional] = true
|
21
|
+
end
|
16
22
|
end
|
17
23
|
|
18
24
|
def array?
|
@@ -48,7 +54,7 @@ module VCDry
|
|
48
54
|
end
|
49
55
|
|
50
56
|
def optional?
|
51
|
-
default? ||
|
57
|
+
default? || @options[:optional]
|
52
58
|
end
|
53
59
|
|
54
60
|
def required?
|
@@ -72,6 +78,7 @@ module VCDry
|
|
72
78
|
def type_cast_value(value)
|
73
79
|
return if value == NOT_DEFINED
|
74
80
|
return value if @type.nil?
|
81
|
+
return if value.nil? && @options[:optional]
|
75
82
|
|
76
83
|
value = @type.call(value)
|
77
84
|
if enum? && enum_values.exclude?(value)
|
data/lib/vcdry/dsl.rb
CHANGED
@@ -10,9 +10,12 @@ module VCDry
|
|
10
10
|
extend ActiveSupport::Concern
|
11
11
|
|
12
12
|
def initialize(**kwargs)
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
run_callbacks :initialize do
|
14
|
+
kwargs = kwargs.symbolize_keys
|
15
|
+
vcdry_parse_keywords(**kwargs)
|
16
|
+
vcdry_parse_unknown_keywords(**kwargs)
|
17
|
+
super
|
18
|
+
end
|
16
19
|
end
|
17
20
|
|
18
21
|
def vcdry_parse_keywords(**kwargs)
|
@@ -35,11 +38,18 @@ module VCDry
|
|
35
38
|
instance_variable_set(config.instance_variable, config.type_cast(unknown_kwargs))
|
36
39
|
end
|
37
40
|
|
41
|
+
included do
|
42
|
+
extend ActiveModel::Callbacks
|
43
|
+
|
44
|
+
define_model_callbacks :initialize
|
45
|
+
end
|
46
|
+
|
38
47
|
class_methods do
|
39
48
|
delegate :other_keywords, :remove_keyword, :strict_keywords, to: :vcdry
|
40
49
|
|
41
50
|
def inherited(subclass)
|
42
51
|
subclass.instance_variable_set(:@vcdry, @vcdry&.dup)
|
52
|
+
super
|
43
53
|
end
|
44
54
|
|
45
55
|
def keyword(name, type = nil, **options)
|
data/lib/vcdry/registry.rb
CHANGED
data/lib/vcdry/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vcdry
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alex Monroe
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-04-
|
11
|
+
date: 2023-04-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|