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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 483f78cdcfb329a0d14f4173fa586f64eae12c8f61dbd78492f1cd85cceadbea
4
- data.tar.gz: 45173313046d5a6dc54d920ed5bee399e64fd8af2a2e710e2b5051b922fcc440
3
+ metadata.gz: 5df15430a1bf5265d31d956adc4fe9e7abfcd751ba46d02954e1b8ae0d1f69bb
4
+ data.tar.gz: d390207587ca466f1f749c346fe4cde529f04b4b97243fc39bdcd876af5ff894
5
5
  SHA512:
6
- metadata.gz: 4041f615dedb5782ce40d15ae80eca87f3e168b988c2d2de4d9d07d0ba05b00bc2a6e8b14b981d65575ab9f2e38b0db50653286c3093ffaa8e7a586eb7a5e5d9
7
- data.tar.gz: 04f2f8e8a86d63e8f5e06066b96e983332107f116694e059e0b06cd14ebb66827cd8bddc2e85c631298518d8387d28452edd856161b412c105f9a9d05d4151fa
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/[USERNAME]/typed_data.
129
+ Bug reports and pull requests are welcome on GitHub at https://github.com/abicky/typed_data.
130
130
 
131
131
 
132
132
  ## License
@@ -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
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TypedData
4
+ class Schema
5
+ class UnknownField < StandardError; end
6
+ class UnsupportedType < StandardError; end
7
+ class InvalidValue < StandardError; end
8
+ end
9
+ end
@@ -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)
@@ -1,3 +1,3 @@
1
1
  module TypedData
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
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.2
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-25 00:00:00.000000000 Z
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