typed_data 0.1.2 → 0.1.3
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/README.md +1 -1
- data/lib/typed_data/schema.rb +1 -3
- data/lib/typed_data/schema/errors.rb +9 -0
- data/lib/typed_data/schema/record_type.rb +4 -0
- data/lib/typed_data/schema/union_type.rb +3 -1
- data/lib/typed_data/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5df15430a1bf5265d31d956adc4fe9e7abfcd751ba46d02954e1b8ae0d1f69bb
|
4
|
+
data.tar.gz: d390207587ca466f1f749c346fe4cde529f04b4b97243fc39bdcd876af5ff894
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ab86b6fe3d69ce3f46d96b81334635b6993d78e9a4ac253df5c68deba23d6389e246b3c21c0945c24d0a7b8a255f861408f04b2fe3ef0d2738a17a17b1c710da
|
7
|
+
data.tar.gz: 2623997c39731114615c7a9bd4610759f63fcd18c8b4d9945e15c932edea6a1c0741c65b884e48d65783f9cb166924f2d60cb1005cf95148a9863b853f95b207
|
data/README.md
CHANGED
@@ -126,7 +126,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
126
126
|
|
127
127
|
## Contributing
|
128
128
|
|
129
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
129
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/abicky/typed_data.
|
130
130
|
|
131
131
|
|
132
132
|
## License
|
data/lib/typed_data/schema.rb
CHANGED
@@ -11,12 +11,10 @@ require "typed_data/schema/null_type"
|
|
11
11
|
require "typed_data/schema/record_type"
|
12
12
|
require "typed_data/schema/string_type"
|
13
13
|
require "typed_data/schema/union_type"
|
14
|
+
require "typed_data/schema/errors"
|
14
15
|
|
15
16
|
module TypedData
|
16
17
|
class Schema
|
17
|
-
class UnknownField < StandardError; end
|
18
|
-
class UnsupportedType < StandardError; end
|
19
|
-
|
20
18
|
class << self
|
21
19
|
def build_type(type, logical_type = nil)
|
22
20
|
type = type.first if type.is_a?(Array) && type.size == 1
|
@@ -22,6 +22,10 @@ module TypedData
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
+
def find_match(value)
|
26
|
+
raise InvalidValue, %Q{the value #{value.inspect} doesn't match the type #{self}}
|
27
|
+
end
|
28
|
+
|
25
29
|
def match?(value)
|
26
30
|
value.is_a?(Hash) && value.all? { |k, v| @field_to_type[k]&.match?(v) }
|
27
31
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
require "typed_data/schema/errors"
|
2
3
|
|
3
4
|
module TypedData
|
4
5
|
class Schema
|
@@ -19,7 +20,8 @@ module TypedData
|
|
19
20
|
end
|
20
21
|
|
21
22
|
def find_match(value)
|
22
|
-
@types.find { |t| t.match?(value) }
|
23
|
+
@types.find { |t| t.match?(value) } or
|
24
|
+
raise InvalidValue, %Q{the value #{value.inspect} doesn't match the type #{@types.map(&:to_s)}}
|
23
25
|
end
|
24
26
|
|
25
27
|
def match?(value)
|
data/lib/typed_data/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: typed_data
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- abicky
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-04-
|
11
|
+
date: 2020-04-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: avro
|
@@ -63,6 +63,7 @@ files:
|
|
63
63
|
- lib/typed_data/schema/boolean_type.rb
|
64
64
|
- lib/typed_data/schema/bytes_type.rb
|
65
65
|
- lib/typed_data/schema/enum_type.rb
|
66
|
+
- lib/typed_data/schema/errors.rb
|
66
67
|
- lib/typed_data/schema/float_type.rb
|
67
68
|
- lib/typed_data/schema/int_type.rb
|
68
69
|
- lib/typed_data/schema/long_type.rb
|