dry-interface 1.0.2 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/dry/concrete.rb +9 -5
- data/lib/dry/interface.rb +1 -0
- data/lib/dry/value.rb +21 -0
- data/lib/dry.rb +3 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 843c9c803f7b4120ee153b239ef059412f8b190b30c19035cb40d7b7fc841f43
|
4
|
+
data.tar.gz: 52f0f9948370e76e25c22fba7584c785df511290776dbfdf8ef88f697bd00774
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9720f18422181f581ab0a2a002a85bd3c930ab2882f68f60127365be257318f5a0954edad26dbd07acef26fa010b103f1da90320499a4e1e43dbe2520513a1ce
|
7
|
+
data.tar.gz: 4fef9a25bb9f73606e905ed850db1fff1eb6d2ab0a433b3e43e628d85f8784314f52fdeb4a2cc77f7ce88a164d3147ad94f53a0792b29b3db13e68acad03b6cf
|
data/lib/dry/concrete.rb
CHANGED
@@ -74,7 +74,7 @@ module Dry
|
|
74
74
|
# @return [void]
|
75
75
|
def self.attribute(field, *constrains, **options, &block)
|
76
76
|
alias_fields(field, **options) do |inner_options|
|
77
|
-
super(field, build_type_from(*constrains, **inner_options
|
77
|
+
super(field, *build_type_from(*constrains, **inner_options, &block))
|
78
78
|
end
|
79
79
|
end
|
80
80
|
|
@@ -83,7 +83,7 @@ module Dry
|
|
83
83
|
# @see #attribute
|
84
84
|
def self.attribute?(field, *constrains, **options, &block)
|
85
85
|
alias_fields(field, **options) do |inner_options|
|
86
|
-
super(field, build_type_from(*constrains, **inner_options
|
86
|
+
super(field, *build_type_from(*constrains, **inner_options, &block))
|
87
87
|
end
|
88
88
|
end
|
89
89
|
|
@@ -100,9 +100,13 @@ module Dry
|
|
100
100
|
end
|
101
101
|
|
102
102
|
# @api private
|
103
|
-
def self.build_type_from(*constrains, **options)
|
103
|
+
def self.build_type_from(*constrains, **options, &block)
|
104
|
+
if block_given?
|
105
|
+
return [Class.new(Concrete, &block)]
|
106
|
+
end
|
107
|
+
|
104
108
|
unless (type = constrains.map(&:to_type).reduce(:|))
|
105
|
-
return
|
109
|
+
return EMPTY_ARRAY
|
106
110
|
end
|
107
111
|
|
108
112
|
if options.key?(:default)
|
@@ -112,7 +116,7 @@ module Dry
|
|
112
116
|
end
|
113
117
|
|
114
118
|
if options.empty?
|
115
|
-
return type
|
119
|
+
return [type]
|
116
120
|
end
|
117
121
|
|
118
122
|
build_type_from(type.constrained(**options))
|
data/lib/dry/interface.rb
CHANGED
data/lib/dry/value.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Dry
|
4
|
+
class Value < Dry::Struct
|
5
|
+
schema schema.strict(true)
|
6
|
+
|
7
|
+
def self.new(value, *other, &block)
|
8
|
+
case value
|
9
|
+
in Hash => attributes then super(attributes, *other, &block)
|
10
|
+
in Dry::Struct => instance then instance
|
11
|
+
else
|
12
|
+
case attribute_names
|
13
|
+
in [] then raise ArgumentError, "[#{self}] has no attributes, one is required"
|
14
|
+
in [key] then super({ key => value }, *other, &block)
|
15
|
+
else
|
16
|
+
raise ArgumentError, "[#{self}] has more than one attribute: #{attribute_names.join(', ')}"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/dry.rb
ADDED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dry-interface
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Linus Oleander
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-11-
|
11
|
+
date: 2021-11-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -59,6 +59,7 @@ executables: []
|
|
59
59
|
extensions: []
|
60
60
|
extra_rdoc_files: []
|
61
61
|
files:
|
62
|
+
- lib/dry.rb
|
62
63
|
- lib/dry/concrete.rb
|
63
64
|
- lib/dry/concrete/extensions.rb
|
64
65
|
- lib/dry/concrete/extensions/default.rb
|
@@ -71,6 +72,7 @@ files:
|
|
71
72
|
- lib/dry/interface/interfaces/unit.rb
|
72
73
|
- lib/dry/interface/patch.rb
|
73
74
|
- lib/dry/interface/types.rb
|
75
|
+
- lib/dry/value.rb
|
74
76
|
homepage: https://github.com/oleander/dry-interface
|
75
77
|
licenses:
|
76
78
|
- MIT
|