dry-types 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +30 -0
- data/CHANGELOG.md +169 -0
- data/Gemfile +20 -0
- data/LICENSE +20 -0
- data/README.md +29 -0
- data/Rakefile +6 -0
- data/benchmarks/basic.rb +57 -0
- data/benchmarks/constrained.rb +37 -0
- data/bin/console +18 -0
- data/bin/setup +7 -0
- data/dry-types.gemspec +41 -0
- data/lib/dry-types.rb +1 -0
- data/lib/dry/types.rb +115 -0
- data/lib/dry/types/builder.rb +46 -0
- data/lib/dry/types/coercions/form.rb +91 -0
- data/lib/dry/types/compiler.rb +63 -0
- data/lib/dry/types/constrained.rb +47 -0
- data/lib/dry/types/constraints.rb +24 -0
- data/lib/dry/types/constructor.rb +59 -0
- data/lib/dry/types/container.rb +7 -0
- data/lib/dry/types/core.rb +57 -0
- data/lib/dry/types/decorator.rb +48 -0
- data/lib/dry/types/default.rb +43 -0
- data/lib/dry/types/definition.rb +53 -0
- data/lib/dry/types/definition/array.rb +24 -0
- data/lib/dry/types/definition/hash.rb +68 -0
- data/lib/dry/types/enum.rb +30 -0
- data/lib/dry/types/form.rb +53 -0
- data/lib/dry/types/optional.rb +16 -0
- data/lib/dry/types/safe.rb +25 -0
- data/lib/dry/types/struct.rb +64 -0
- data/lib/dry/types/sum.rb +34 -0
- data/lib/dry/types/value.rb +22 -0
- data/lib/dry/types/version.rb +5 -0
- metadata +236 -0
@@ -0,0 +1,34 @@
|
|
1
|
+
module Dry
|
2
|
+
module Types
|
3
|
+
class Sum
|
4
|
+
include Builder
|
5
|
+
|
6
|
+
attr_reader :left
|
7
|
+
|
8
|
+
attr_reader :right
|
9
|
+
|
10
|
+
def initialize(left, right)
|
11
|
+
@left, @right = left, right
|
12
|
+
end
|
13
|
+
|
14
|
+
def name
|
15
|
+
[left, right].map(&:name).join(' | ')
|
16
|
+
end
|
17
|
+
|
18
|
+
def call(input)
|
19
|
+
value = left.try(input)
|
20
|
+
|
21
|
+
if left.valid?(value)
|
22
|
+
value
|
23
|
+
else
|
24
|
+
right[value]
|
25
|
+
end
|
26
|
+
end
|
27
|
+
alias_method :[], :call
|
28
|
+
|
29
|
+
def valid?(input)
|
30
|
+
left.valid?(input) || right.valid?(input)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'dry/types/struct'
|
2
|
+
|
3
|
+
module Dry
|
4
|
+
module Types
|
5
|
+
class Value < Struct
|
6
|
+
def self.inherited(klass)
|
7
|
+
super
|
8
|
+
klass.instance_variable_set('@equalizer', Equalizer.new)
|
9
|
+
klass.send(:include, klass.equalizer)
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.attributes(*args)
|
13
|
+
super
|
14
|
+
equalizer.instance_variable_get('@keys').concat(schema.keys).uniq!
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.equalizer
|
18
|
+
@equalizer
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,236 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dry-types
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.6.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Piotr Solnica
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-03-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: thread_safe
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.3'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: dry-container
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.2'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.2'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: dry-equalizer
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.2'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.2'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: dry-configurable
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.1'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.1'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: dry-logic
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.2'
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: 0.2.0
|
79
|
+
type: :runtime
|
80
|
+
prerelease: false
|
81
|
+
version_requirements: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - "~>"
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0.2'
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: 0.2.0
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
name: inflecto
|
91
|
+
requirement: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - "~>"
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: 0.0.0
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: 0.0.2
|
99
|
+
type: :runtime
|
100
|
+
prerelease: false
|
101
|
+
version_requirements: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - "~>"
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: 0.0.0
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: 0.0.2
|
109
|
+
- !ruby/object:Gem::Dependency
|
110
|
+
name: kleisli
|
111
|
+
requirement: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - "~>"
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '0.2'
|
116
|
+
type: :runtime
|
117
|
+
prerelease: false
|
118
|
+
version_requirements: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - "~>"
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '0.2'
|
123
|
+
- !ruby/object:Gem::Dependency
|
124
|
+
name: bundler
|
125
|
+
requirement: !ruby/object:Gem::Requirement
|
126
|
+
requirements:
|
127
|
+
- - "~>"
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
version: '1.7'
|
130
|
+
type: :development
|
131
|
+
prerelease: false
|
132
|
+
version_requirements: !ruby/object:Gem::Requirement
|
133
|
+
requirements:
|
134
|
+
- - "~>"
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
version: '1.7'
|
137
|
+
- !ruby/object:Gem::Dependency
|
138
|
+
name: rake
|
139
|
+
requirement: !ruby/object:Gem::Requirement
|
140
|
+
requirements:
|
141
|
+
- - "~>"
|
142
|
+
- !ruby/object:Gem::Version
|
143
|
+
version: '10.0'
|
144
|
+
type: :development
|
145
|
+
prerelease: false
|
146
|
+
version_requirements: !ruby/object:Gem::Requirement
|
147
|
+
requirements:
|
148
|
+
- - "~>"
|
149
|
+
- !ruby/object:Gem::Version
|
150
|
+
version: '10.0'
|
151
|
+
- !ruby/object:Gem::Dependency
|
152
|
+
name: rspec
|
153
|
+
requirement: !ruby/object:Gem::Requirement
|
154
|
+
requirements:
|
155
|
+
- - "~>"
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
version: '3.3'
|
158
|
+
type: :development
|
159
|
+
prerelease: false
|
160
|
+
version_requirements: !ruby/object:Gem::Requirement
|
161
|
+
requirements:
|
162
|
+
- - "~>"
|
163
|
+
- !ruby/object:Gem::Version
|
164
|
+
version: '3.3'
|
165
|
+
description: Type system for Ruby supporting coercions, constraints and complex types
|
166
|
+
like structs, value objects, enums etc.
|
167
|
+
email:
|
168
|
+
- piotr.solnica@gmail.com
|
169
|
+
executables: []
|
170
|
+
extensions: []
|
171
|
+
extra_rdoc_files: []
|
172
|
+
files:
|
173
|
+
- ".gitignore"
|
174
|
+
- ".rspec"
|
175
|
+
- ".travis.yml"
|
176
|
+
- CHANGELOG.md
|
177
|
+
- Gemfile
|
178
|
+
- LICENSE
|
179
|
+
- README.md
|
180
|
+
- Rakefile
|
181
|
+
- benchmarks/basic.rb
|
182
|
+
- benchmarks/constrained.rb
|
183
|
+
- bin/console
|
184
|
+
- bin/setup
|
185
|
+
- dry-types.gemspec
|
186
|
+
- lib/dry-types.rb
|
187
|
+
- lib/dry/types.rb
|
188
|
+
- lib/dry/types/builder.rb
|
189
|
+
- lib/dry/types/coercions/form.rb
|
190
|
+
- lib/dry/types/compiler.rb
|
191
|
+
- lib/dry/types/constrained.rb
|
192
|
+
- lib/dry/types/constraints.rb
|
193
|
+
- lib/dry/types/constructor.rb
|
194
|
+
- lib/dry/types/container.rb
|
195
|
+
- lib/dry/types/core.rb
|
196
|
+
- lib/dry/types/decorator.rb
|
197
|
+
- lib/dry/types/default.rb
|
198
|
+
- lib/dry/types/definition.rb
|
199
|
+
- lib/dry/types/definition/array.rb
|
200
|
+
- lib/dry/types/definition/hash.rb
|
201
|
+
- lib/dry/types/enum.rb
|
202
|
+
- lib/dry/types/form.rb
|
203
|
+
- lib/dry/types/optional.rb
|
204
|
+
- lib/dry/types/safe.rb
|
205
|
+
- lib/dry/types/struct.rb
|
206
|
+
- lib/dry/types/sum.rb
|
207
|
+
- lib/dry/types/value.rb
|
208
|
+
- lib/dry/types/version.rb
|
209
|
+
homepage: https://github.com/dryrb/dry-types
|
210
|
+
licenses:
|
211
|
+
- MIT
|
212
|
+
metadata:
|
213
|
+
allowed_push_host: https://rubygems.org
|
214
|
+
post_install_message:
|
215
|
+
rdoc_options: []
|
216
|
+
require_paths:
|
217
|
+
- lib
|
218
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
219
|
+
requirements:
|
220
|
+
- - ">="
|
221
|
+
- !ruby/object:Gem::Version
|
222
|
+
version: '0'
|
223
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
224
|
+
requirements:
|
225
|
+
- - ">="
|
226
|
+
- !ruby/object:Gem::Version
|
227
|
+
version: '0'
|
228
|
+
requirements: []
|
229
|
+
rubyforge_project:
|
230
|
+
rubygems_version: 2.4.5.1
|
231
|
+
signing_key:
|
232
|
+
specification_version: 4
|
233
|
+
summary: Type system for Ruby supporting coercions, constraints and complex types
|
234
|
+
like structs, value objects, enums etc.
|
235
|
+
test_files: []
|
236
|
+
has_rdoc:
|