deimos-ruby 1.12.0 → 1.12.4

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
  SHA256:
3
- metadata.gz: b7d6f4f732c60937fcc4e7c2834e59d7a225defbe930bfc37ac02729ddc7e092
4
- data.tar.gz: e32bbddd1e6d01ebd824b8916fc40c2eac467966e4a154875e90e9f1ab50528e
3
+ metadata.gz: b6868444b14bad26f41d6b9ae08e02b402c33e17131df0db31874551c69b2d2b
4
+ data.tar.gz: 64d5856bf685c2de06a3fe2124fcbf441953600073a0a1786663877013f52080
5
5
  SHA512:
6
- metadata.gz: 1d1b3ba943c5ac49d87f5d4f77d22d88d0e5ff5467eef5e040acb2f5f7af0ae3f4d042d8156e5a8e413c394496a6092c7a691ddb840e366bb23617f48103bd62
7
- data.tar.gz: ba8fe17bed6e62f86d87ae54b81a8a3cb57efe7fc06586166d1a59d92b87640e19f74213724f3b7404846975d77b0b016127fa8a846a4de270a1c8192f9a3344
6
+ metadata.gz: 6e0ff08f0224cf67ccd6361c8e75d30e516acec862edeb233401bfd61ccd2cfd8fe2b38658be1ff6fabfdae396caefa856e22182ed995fd03dc7afa7a644a8c5
7
+ data.tar.gz: 543da676aff990c852f2208a39539650f77255f7aa5e50f3e9651352fb84c9303f78daa51e43b27abdc295175b891cca29b578d2b786773da8184f45ff11439b
data/CHANGELOG.md CHANGED
@@ -7,6 +7,25 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## UNRELEASED
9
9
 
10
+ # 1.12.4 - 2022-01-13
11
+
12
+ - Fix bug where schema controller mixin was using the schema name to register and not the namespaced schema name
13
+
14
+ # 1.12.3 - 2021-12-13
15
+
16
+ - Fix bug with previous release
17
+
18
+ # 1.12.2 - 2021-12-10
19
+
20
+ ### Features :star:
21
+
22
+ - Added `Deimos.encode` and `Deimos.decode` for non-topic-related encoding and decoding.
23
+
24
+ # 1.12.1 - 2021-11-02
25
+
26
+ - ### Fixes :wrench:
27
+ - Fixed issue where Schema Class Consumer/Producer are using `Deimos::` instead of `Schema::` for instances of classes.
28
+
10
29
  # 1.12.0 - 2021-11-01
11
30
 
12
31
  ### Features :star:
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- deimos-ruby (1.11.0)
4
+ deimos-ruby (1.12.3)
5
5
  avro_turf (~> 0.11)
6
6
  fig_tree (~> 0.0.2)
7
7
  phobos (>= 1.9, < 3.0)
@@ -92,7 +92,7 @@ GEM
92
92
  rake (>= 12.0.0, < 14.0.0)
93
93
  dogstatsd-ruby (4.8.3)
94
94
  erubi (1.10.0)
95
- excon (0.85.0)
95
+ excon (0.89.0)
96
96
  exponential-backoff (0.0.4)
97
97
  ffi (1.15.0)
98
98
  fig_tree (0.0.2)
data/README.md CHANGED
@@ -1164,6 +1164,13 @@ backend.validate(my_payload) # throws an error if not valid
1164
1164
  fields = backend.schema_fields # list of fields defined in the schema
1165
1165
  ```
1166
1166
 
1167
+ You can also do an even faster encode/decode:
1168
+
1169
+ ```ruby
1170
+ encoded = Deimos.encode(schema: 'MySchema', namespace: 'com.my-namespace', payload: my_payload)
1171
+ decoded = Deimos.decode(schema: 'MySchema', namespace: 'com.my-namespace', payload: my_encoded_payload)
1172
+ ```
1173
+
1167
1174
  ## Contributing
1168
1175
 
1169
1176
  Bug reports and pull requests are welcome on GitHub at https://github.com/flipp-oss/deimos .
@@ -17,7 +17,7 @@ module Deimos
17
17
  to_h.to_json
18
18
  end
19
19
 
20
- # Converts the object to a hash which can be used for debugging.
20
+ # Converts the object to a hash which can be used for debugging or comparing objects.
21
21
  # @return [Hash] a hash representation of the payload
22
22
  def as_json(_opts={})
23
23
  JSON.parse(to_json)
@@ -33,10 +33,10 @@ module Deimos
33
33
  def ==(other)
34
34
  comparison = other
35
35
  if other.class == self.class
36
- comparison = other.state
36
+ comparison = other.as_json
37
37
  end
38
38
 
39
- comparison == self.state
39
+ comparison == self.as_json
40
40
  end
41
41
 
42
42
  # :nodoc:
@@ -53,14 +53,9 @@ module Deimos
53
53
 
54
54
  protected
55
55
 
56
- # :nodoc:
57
- def state
58
- as_json
59
- end
60
-
61
56
  # :nodoc:
62
57
  def hash
63
- state.hash
58
+ as_json.hash
64
59
  end
65
60
  end
66
61
  end
@@ -7,6 +7,13 @@ module Deimos
7
7
  module SchemaClass
8
8
  # Base Class of Record Classes generated from Avro.
9
9
  class Record < Base
10
+
11
+ # Converts the object to a hash which can be used for debugging or comparing objects.
12
+ # @return [Hash] a hash representation of the payload
13
+ def as_json(_opts={})
14
+ super.except('payload_key')
15
+ end
16
+
10
17
  # Element access method as if this Object were a hash
11
18
  # @param key[String||Symbol]
12
19
  # @return [Object] The value of the attribute if exists, nil otherwise
@@ -10,7 +10,7 @@ module Deimos
10
10
  # @param schema [String]
11
11
  # @return [Deimos::SchemaClass::Record]
12
12
  def instance(payload, schema)
13
- klass = "Deimos::#{schema.underscore.camelize}".safe_constantize
13
+ klass = "Schemas::#{schema.underscore.camelize}".safe_constantize
14
14
  return payload if klass.nil? || payload.nil?
15
15
 
16
16
  klass.new(**payload.symbolize_keys)
@@ -106,7 +106,7 @@ module Deimos
106
106
  def render_schema(payload, schema: nil, namespace: nil)
107
107
  namespace, schema = parse_namespace(:response) if !schema && !namespace
108
108
  encoder = Deimos.schema_backend(schema: schema, namespace: namespace)
109
- encoded = encoder.encode(payload)
109
+ encoded = encoder.encode(payload, topic: "#{namespace}.#{schema}")
110
110
  response.headers['Content-Type'] = encoder.class.content_type
111
111
  send_data(encoded)
112
112
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Deimos
4
- VERSION = '1.12.0'
4
+ VERSION = '1.12.4'
5
5
  end
data/lib/deimos.rb CHANGED
@@ -62,6 +62,24 @@ module Deimos
62
62
  schema_backend_class.new(schema: schema, namespace: namespace)
63
63
  end
64
64
 
65
+ # @param schema [String]
66
+ # @param namespace [String]
67
+ # @param payload [Hash]
68
+ # @param subject [String]
69
+ # @return [String]
70
+ def encode(schema:, namespace:, payload:, subject: nil)
71
+ self.schema_backend(schema: schema, namespace: namespace).
72
+ encode(payload, topic: subject || "#{namespace}.#{schema}" )
73
+ end
74
+
75
+ # @param schema [String]
76
+ # @param namespace [String]
77
+ # @param payload [String]
78
+ # @return [Hash,nil]
79
+ def decode(schema:, namespace:, payload:)
80
+ self.schema_backend(schema: schema, namespace: namespace).decode(payload)
81
+ end
82
+
65
83
  # Start the DB producers to send Kafka messages.
66
84
  # @param thread_count [Integer] the number of threads to start.
67
85
  def start_db_backend!(thread_count: 1)
@@ -12,7 +12,7 @@ module ConsumerTest
12
12
 
13
13
  # :nodoc:
14
14
  def fatal_error?(_exception, payload, _metadata)
15
- payload == 'fatal'
15
+ payload.to_s == 'fatal'
16
16
  end
17
17
 
18
18
  # :nodoc:
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: deimos-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.12.0
4
+ version: 1.12.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Orner
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-11-01 00:00:00.000000000 Z
11
+ date: 2022-01-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: avro_turf