deimos-ruby 1.12.0 → 1.12.4
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/CHANGELOG.md +19 -0
- data/Gemfile.lock +2 -2
- data/README.md +7 -0
- data/lib/deimos/schema_class/base.rb +4 -9
- data/lib/deimos/schema_class/record.rb +7 -0
- data/lib/deimos/utils/schema_class.rb +1 -1
- data/lib/deimos/utils/schema_controller_mixin.rb +1 -1
- data/lib/deimos/version.rb +1 -1
- data/lib/deimos.rb +18 -0
- data/spec/consumer_spec.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b6868444b14bad26f41d6b9ae08e02b402c33e17131df0db31874551c69b2d2b
|
4
|
+
data.tar.gz: 64d5856bf685c2de06a3fe2124fcbf441953600073a0a1786663877013f52080
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
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.
|
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.
|
36
|
+
comparison = other.as_json
|
37
37
|
end
|
38
38
|
|
39
|
-
comparison == self.
|
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
|
-
|
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 = "
|
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
|
data/lib/deimos/version.rb
CHANGED
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)
|
data/spec/consumer_spec.rb
CHANGED
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.
|
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:
|
11
|
+
date: 2022-01-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: avro_turf
|