avro_turf 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0845fc0e81baaa72df5abd34b47a0ce6d06a853f
4
- data.tar.gz: 434aaa74efb2f96437045a8705c7889348bec9c3
3
+ metadata.gz: 6babda857fb94d0703569d4091d0431ca143728f
4
+ data.tar.gz: debd3b5581b00744308dc7bf3f531184dc94a895
5
5
  SHA512:
6
- metadata.gz: ef023ba8d9fb413e69a467c1ecb4a4ef73c6c1f1bb86f1f362b6f351abcd6ed8b2fae965d7b50b4d3ba6e81513c30dcffbe1e5d688044efa872f4b65f85ff39a
7
- data.tar.gz: e095b79ce3f37a69efac8537e6d59fcb5c8d66350604eba7f00166911801699eccf945552fcbc5c950223f7c14ddfddd2f58157b70aff2466e6d2ea157485eab
6
+ metadata.gz: 26051349a7d90ee51a521099eaffa02c6cd2778d4be2a2832c3c4e8afd3892158eef68658d209ff06315d05ded7ebfecb7bdceaffae56a43077127c704c2f932
7
+ data.tar.gz: 305e8af7c8adc7483c86596109c5f3bbd807e95bbafb66439574c254637ac1b0e6fa59e4635b59dbb4c226744d0bf0abbade5f752d3d9df7a40eda78c946feeb
data/lib/avro_turf.rb CHANGED
@@ -2,12 +2,20 @@ require 'avro_turf/version'
2
2
  require 'avro'
3
3
  require 'json'
4
4
  require 'avro_turf/schema_store'
5
+ require 'avro_turf/core_ext'
5
6
 
6
7
  class AvroTurf
7
8
  class Error < StandardError; end
8
9
  class SchemaError < Error; end
9
10
  class SchemaNotFoundError < Error; end
10
11
 
12
+ # Create a new AvroTurf instance with the specified configuration.
13
+ #
14
+ # schemas_path - The String path to the root directory containing Avro schemas.
15
+ # namespace - The String namespace that should be used to qualify schema names (optional).
16
+ # codec - The String name of a codec that should be used to compress messages (optional).
17
+ #
18
+ # Currently, the only valid codec name is `deflate`.
11
19
  def initialize(schemas_path:, namespace: nil, codec: nil)
12
20
  @namespace = namespace
13
21
  @schema_store = SchemaStore.new(path: schemas_path)
@@ -34,9 +42,6 @@ class AvroTurf
34
42
  # data - The data that should be encoded.
35
43
  # schema_name - The name of a schema in the `schemas_path`.
36
44
  # stream - An IO object that the encoded data should be written to (optional).
37
- # codec - The String name of a codec that should be used to compress messages (optional).
38
- #
39
- # Currently, the only valid codec name is `deflate`.
40
45
  #
41
46
  # Returns nothing.
42
47
  def encode_to_stream(data, schema_name:, stream:, namespace: @namespace)
@@ -44,7 +49,7 @@ class AvroTurf
44
49
  writer = Avro::IO::DatumWriter.new(schema)
45
50
 
46
51
  dw = Avro::DataFile::Writer.new(stream, writer, schema, @codec)
47
- dw << data
52
+ dw << data.as_avro
48
53
  dw.close
49
54
  end
50
55
 
@@ -0,0 +1,7 @@
1
+ require 'avro_turf/core_ext/string'
2
+ require 'avro_turf/core_ext/numeric'
3
+ require 'avro_turf/core_ext/enumerable'
4
+ require 'avro_turf/core_ext/hash'
5
+ require 'avro_turf/core_ext/time'
6
+ require 'avro_turf/core_ext/date'
7
+ require 'avro_turf/core_ext/symbol'
@@ -0,0 +1,5 @@
1
+ class Date
2
+ def as_avro
3
+ iso8601
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module Enumerable
2
+ def as_avro
3
+ map(&:as_avro)
4
+ end
5
+ end
@@ -0,0 +1,7 @@
1
+ class Hash
2
+ def as_avro
3
+ hsh = Hash.new
4
+ each {|k, v| hsh[k.as_avro] = v.as_avro }
5
+ hsh
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ class Numeric
2
+ def as_avro
3
+ self
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ class String
2
+ def as_avro
3
+ self
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ class Symbol
2
+ def as_avro
3
+ to_s
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ class Time
2
+ def as_avro
3
+ iso8601
4
+ end
5
+ end
@@ -1,3 +1,3 @@
1
1
  class AvroTurf
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  end
@@ -0,0 +1,6 @@
1
+ describe Date, "#as_avro" do
2
+ it "returns an ISO8601 string describing the time" do
3
+ date = Date.today
4
+ expect(date.as_avro).to eq(date.iso8601)
5
+ end
6
+ end
@@ -0,0 +1,12 @@
1
+ describe Enumerable, "#as_avro" do
2
+ it "returns an array" do
3
+ expect(Set.new.as_avro).to eq []
4
+ end
5
+
6
+ it "coerces the items to Avro" do
7
+ x = double(as_avro: "x")
8
+ y = double(as_avro: "y")
9
+
10
+ expect([x, y].as_avro).to eq ["x", "y"]
11
+ end
12
+ end
@@ -0,0 +1,8 @@
1
+ describe Hash, "#as_avro" do
2
+ it "coerces the keys and values to Avro" do
3
+ x = double(as_avro: "x")
4
+ y = double(as_avro: "y")
5
+
6
+ expect({ x => y }.as_avro).to eq({ "x" => "y" })
7
+ end
8
+ end
@@ -0,0 +1,6 @@
1
+ describe Numeric, "#as_avro" do
2
+ it "returns the number itself" do
3
+ expect(42.as_avro).to eq 42
4
+ expect(4.2.as_avro).to eq 4.2
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ describe String, "#as_avro" do
2
+ it "returns itself" do
3
+ expect("hello".as_avro).to eq "hello"
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ describe Symbol, "#as_avro" do
2
+ it "returns the String representation of the Symbol" do
3
+ expect(:hello.as_avro).to eq("hello")
4
+ end
5
+ end
@@ -0,0 +1,6 @@
1
+ describe Time, "#as_avro" do
2
+ it "returns an ISO8601 string describing the time" do
3
+ time = Time.now
4
+ expect(time.as_avro).to eq(time.iso8601)
5
+ end
6
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: avro_turf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Schierbeck
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-08 00:00:00.000000000 Z
11
+ date: 2015-06-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: avro
@@ -96,6 +96,14 @@ files:
96
96
  - avro_turf.gemspec
97
97
  - circle.yml
98
98
  - lib/avro_turf.rb
99
+ - lib/avro_turf/core_ext.rb
100
+ - lib/avro_turf/core_ext/date.rb
101
+ - lib/avro_turf/core_ext/enumerable.rb
102
+ - lib/avro_turf/core_ext/hash.rb
103
+ - lib/avro_turf/core_ext/numeric.rb
104
+ - lib/avro_turf/core_ext/string.rb
105
+ - lib/avro_turf/core_ext/symbol.rb
106
+ - lib/avro_turf/core_ext/time.rb
99
107
  - lib/avro_turf/schema_store.rb
100
108
  - lib/avro_turf/version.rb
101
109
  - perf/address.avsc
@@ -103,6 +111,13 @@ files:
103
111
  - perf/encoding_speed.rb
104
112
  - perf/person.avsc
105
113
  - spec/avro_turf_spec.rb
114
+ - spec/core_ext/date_spec.rb
115
+ - spec/core_ext/enumerable_spec.rb
116
+ - spec/core_ext/hash_spec.rb
117
+ - spec/core_ext/numeric_spec.rb
118
+ - spec/core_ext/string_spec.rb
119
+ - spec/core_ext/symbol_spec.rb
120
+ - spec/core_ext/time_spec.rb
106
121
  - spec/schema_store_spec.rb
107
122
  - spec/spec_helper.rb
108
123
  homepage: https://github.com/dasch/avro_turf
@@ -132,6 +147,13 @@ summary: A library that makes it easier to use the Avro serialization format fro
132
147
  Ruby
133
148
  test_files:
134
149
  - spec/avro_turf_spec.rb
150
+ - spec/core_ext/date_spec.rb
151
+ - spec/core_ext/enumerable_spec.rb
152
+ - spec/core_ext/hash_spec.rb
153
+ - spec/core_ext/numeric_spec.rb
154
+ - spec/core_ext/string_spec.rb
155
+ - spec/core_ext/symbol_spec.rb
156
+ - spec/core_ext/time_spec.rb
135
157
  - spec/schema_store_spec.rb
136
158
  - spec/spec_helper.rb
137
159
  has_rdoc: