cloud_events 0.7.0 → 0.8.0
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/.yardopts +1 -1
- data/CHANGELOG.md +13 -0
- data/CONTRIBUTING.md +167 -0
- data/MAINTAINERS.md +5 -0
- data/README.md +8 -38
- data/RELEASING.md +25 -0
- data/lib/cloud_events/content_type.rb +32 -32
- data/lib/cloud_events/event/field_interpreter.rb +46 -38
- data/lib/cloud_events/event/opaque.rb +3 -3
- data/lib/cloud_events/event/utils.rb +9 -9
- data/lib/cloud_events/event/v0.rb +19 -19
- data/lib/cloud_events/event/v1.rb +21 -21
- data/lib/cloud_events/event.rb +4 -4
- data/lib/cloud_events/format.rb +13 -14
- data/lib/cloud_events/http_binding.rb +88 -88
- data/lib/cloud_events/json_format.rb +65 -66
- data/lib/cloud_events/text_format.rb +6 -7
- data/lib/cloud_events/version.rb +1 -1
- metadata +9 -10
- data/LICENSE.md +0 -202
|
@@ -8,37 +8,37 @@ module CloudEvents
|
|
|
8
8
|
#
|
|
9
9
|
module Utils
|
|
10
10
|
class << self
|
|
11
|
-
def deep_freeze
|
|
11
|
+
def deep_freeze(obj)
|
|
12
12
|
case obj
|
|
13
13
|
when ::Hash
|
|
14
14
|
obj.each do |key, val|
|
|
15
|
-
deep_freeze
|
|
16
|
-
deep_freeze
|
|
15
|
+
deep_freeze(key)
|
|
16
|
+
deep_freeze(val)
|
|
17
17
|
end
|
|
18
18
|
when ::Array
|
|
19
19
|
obj.each do |val|
|
|
20
|
-
deep_freeze
|
|
20
|
+
deep_freeze(val)
|
|
21
21
|
end
|
|
22
22
|
else
|
|
23
23
|
obj.instance_variables.each do |iv|
|
|
24
|
-
deep_freeze
|
|
24
|
+
deep_freeze(obj.instance_variable_get(iv))
|
|
25
25
|
end
|
|
26
26
|
end
|
|
27
27
|
obj.freeze
|
|
28
28
|
end
|
|
29
29
|
|
|
30
|
-
def deep_dup
|
|
30
|
+
def deep_dup(obj)
|
|
31
31
|
case obj
|
|
32
32
|
when ::Hash
|
|
33
|
-
obj.each_with_object({}) { |(key, val), hash| hash[deep_dup
|
|
33
|
+
obj.each_with_object({}) { |(key, val), hash| hash[deep_dup(key)] = deep_dup(val) }
|
|
34
34
|
when ::Array
|
|
35
|
-
obj.map { |val| deep_dup
|
|
35
|
+
obj.map { |val| deep_dup(val) }
|
|
36
36
|
else
|
|
37
37
|
obj.dup
|
|
38
38
|
end
|
|
39
39
|
end
|
|
40
40
|
|
|
41
|
-
def keys_to_strings
|
|
41
|
+
def keys_to_strings(hash)
|
|
42
42
|
result = {}
|
|
43
43
|
hash.each do |key, val|
|
|
44
44
|
result[key.to_s] = val
|
|
@@ -75,20 +75,20 @@ module CloudEvents
|
|
|
75
75
|
# (Also available using the deprecated keyword `attributes`.)
|
|
76
76
|
# @param args [keywords] The data and attributes, as keyword arguments.
|
|
77
77
|
#
|
|
78
|
-
def initialize
|
|
79
|
-
interpreter = FieldInterpreter.new
|
|
80
|
-
@spec_version = interpreter.spec_version
|
|
81
|
-
@id = interpreter.string
|
|
82
|
-
@source = interpreter.uri
|
|
83
|
-
@type = interpreter.string
|
|
84
|
-
@data = interpreter.data_object
|
|
78
|
+
def initialize(set_attributes: nil, attributes: nil, **args)
|
|
79
|
+
interpreter = FieldInterpreter.new(set_attributes || attributes || args)
|
|
80
|
+
@spec_version = interpreter.spec_version(["specversion", "spec_version"], accept: /^0\.3$/)
|
|
81
|
+
@id = interpreter.string(["id"], required: true)
|
|
82
|
+
@source = interpreter.uri(["source"], required: true)
|
|
83
|
+
@type = interpreter.string(["type"], required: true)
|
|
84
|
+
@data = interpreter.data_object(["data"])
|
|
85
85
|
@data = nil if @data == FieldInterpreter::UNDEFINED
|
|
86
|
-
@data_content_encoding = interpreter.string
|
|
87
|
-
@data_content_type = interpreter.content_type
|
|
88
|
-
@schema_url = interpreter.uri
|
|
89
|
-
@subject = interpreter.string
|
|
90
|
-
@time = interpreter.rfc3339_date_time
|
|
91
|
-
@attributes = interpreter.finish_attributes
|
|
86
|
+
@data_content_encoding = interpreter.string(["datacontentencoding", "data_content_encoding"])
|
|
87
|
+
@data_content_type = interpreter.content_type(["datacontenttype", "data_content_type"])
|
|
88
|
+
@schema_url = interpreter.uri(["schemaurl", "schema_url"])
|
|
89
|
+
@subject = interpreter.string(["subject"])
|
|
90
|
+
@time = interpreter.rfc3339_date_time(["time"])
|
|
91
|
+
@attributes = interpreter.finish_attributes(requires_lc_start: true)
|
|
92
92
|
freeze
|
|
93
93
|
end
|
|
94
94
|
|
|
@@ -101,9 +101,9 @@ module CloudEvents
|
|
|
101
101
|
# @param changes [keywords] See {#initialize} for a list of arguments.
|
|
102
102
|
# @return [FunctionFramework::CloudEvents::Event]
|
|
103
103
|
#
|
|
104
|
-
def with
|
|
105
|
-
attributes = @attributes.merge
|
|
106
|
-
V0.new
|
|
104
|
+
def with(**changes)
|
|
105
|
+
attributes = @attributes.merge(changes)
|
|
106
|
+
V0.new(set_attributes: attributes)
|
|
107
107
|
end
|
|
108
108
|
|
|
109
109
|
##
|
|
@@ -125,7 +125,7 @@ module CloudEvents
|
|
|
125
125
|
# @param key [String,Symbol] The attribute name.
|
|
126
126
|
# @return [String,nil]
|
|
127
127
|
#
|
|
128
|
-
def []
|
|
128
|
+
def [](key)
|
|
129
129
|
@attributes[key.to_s]
|
|
130
130
|
end
|
|
131
131
|
|
|
@@ -136,7 +136,7 @@ module CloudEvents
|
|
|
136
136
|
# @return [Hash]
|
|
137
137
|
#
|
|
138
138
|
def to_h
|
|
139
|
-
Utils.deep_dup
|
|
139
|
+
Utils.deep_dup(@attributes)
|
|
140
140
|
end
|
|
141
141
|
|
|
142
142
|
##
|
|
@@ -225,7 +225,7 @@ module CloudEvents
|
|
|
225
225
|
attr_reader :time
|
|
226
226
|
|
|
227
227
|
## @private
|
|
228
|
-
def ==
|
|
228
|
+
def ==(other)
|
|
229
229
|
other.is_a?(V0) && @attributes == other.instance_variable_get(:@attributes)
|
|
230
230
|
end
|
|
231
231
|
alias eql? ==
|
|
@@ -136,24 +136,24 @@ module CloudEvents
|
|
|
136
136
|
# (Also available using the deprecated keyword `attributes`.)
|
|
137
137
|
# @param args [keywords] The data and attributes, as keyword arguments.
|
|
138
138
|
#
|
|
139
|
-
def initialize
|
|
140
|
-
interpreter = FieldInterpreter.new
|
|
141
|
-
@spec_version = interpreter.spec_version
|
|
142
|
-
@id = interpreter.string
|
|
143
|
-
@source = interpreter.uri
|
|
144
|
-
@type = interpreter.string
|
|
145
|
-
@data_encoded = interpreter.string
|
|
146
|
-
@data = interpreter.data_object
|
|
139
|
+
def initialize(set_attributes: nil, attributes: nil, **args)
|
|
140
|
+
interpreter = FieldInterpreter.new(set_attributes || attributes || args)
|
|
141
|
+
@spec_version = interpreter.spec_version(["specversion", "spec_version"], accept: /^1(\.|$)/)
|
|
142
|
+
@id = interpreter.string(["id"], required: true)
|
|
143
|
+
@source = interpreter.uri(["source"], required: true)
|
|
144
|
+
@type = interpreter.string(["type"], required: true)
|
|
145
|
+
@data_encoded = interpreter.string(["data_encoded"], allow_empty: true)
|
|
146
|
+
@data = interpreter.data_object(["data"])
|
|
147
147
|
if @data == FieldInterpreter::UNDEFINED
|
|
148
148
|
@data = @data_encoded
|
|
149
149
|
@data_decoded = false
|
|
150
150
|
else
|
|
151
151
|
@data_decoded = true
|
|
152
152
|
end
|
|
153
|
-
@data_content_type = interpreter.content_type
|
|
154
|
-
@data_schema = interpreter.uri
|
|
155
|
-
@subject = interpreter.string
|
|
156
|
-
@time = interpreter.rfc3339_date_time
|
|
153
|
+
@data_content_type = interpreter.content_type(["datacontenttype", "data_content_type"])
|
|
154
|
+
@data_schema = interpreter.uri(["dataschema", "data_schema"])
|
|
155
|
+
@subject = interpreter.string(["subject"])
|
|
156
|
+
@time = interpreter.rfc3339_date_time(["time"])
|
|
157
157
|
@attributes = interpreter.finish_attributes
|
|
158
158
|
freeze
|
|
159
159
|
end
|
|
@@ -167,15 +167,15 @@ module CloudEvents
|
|
|
167
167
|
# @param changes [keywords] See {#initialize} for a list of arguments.
|
|
168
168
|
# @return [FunctionFramework::CloudEvents::Event]
|
|
169
169
|
#
|
|
170
|
-
def with
|
|
171
|
-
changes = Utils.keys_to_strings
|
|
170
|
+
def with(**changes)
|
|
171
|
+
changes = Utils.keys_to_strings(changes)
|
|
172
172
|
attributes = @attributes.dup
|
|
173
173
|
if changes.key?("data") || changes.key?("data_encoded")
|
|
174
|
-
attributes.delete
|
|
175
|
-
attributes.delete
|
|
174
|
+
attributes.delete("data")
|
|
175
|
+
attributes.delete("data_encoded")
|
|
176
176
|
end
|
|
177
|
-
attributes.merge!
|
|
178
|
-
V1.new
|
|
177
|
+
attributes.merge!(changes)
|
|
178
|
+
V1.new(set_attributes: attributes)
|
|
179
179
|
end
|
|
180
180
|
|
|
181
181
|
##
|
|
@@ -197,7 +197,7 @@ module CloudEvents
|
|
|
197
197
|
# @param key [String,Symbol] The attribute name.
|
|
198
198
|
# @return [String,nil]
|
|
199
199
|
#
|
|
200
|
-
def []
|
|
200
|
+
def [](key)
|
|
201
201
|
@attributes[key.to_s]
|
|
202
202
|
end
|
|
203
203
|
|
|
@@ -208,7 +208,7 @@ module CloudEvents
|
|
|
208
208
|
# @return [Hash]
|
|
209
209
|
#
|
|
210
210
|
def to_h
|
|
211
|
-
Utils.deep_dup
|
|
211
|
+
Utils.deep_dup(@attributes)
|
|
212
212
|
end
|
|
213
213
|
|
|
214
214
|
##
|
|
@@ -330,7 +330,7 @@ module CloudEvents
|
|
|
330
330
|
attr_reader :time
|
|
331
331
|
|
|
332
332
|
## @private
|
|
333
|
-
def ==
|
|
333
|
+
def ==(other)
|
|
334
334
|
other.is_a?(V1) && @attributes == other.instance_variable_get(:@attributes)
|
|
335
335
|
end
|
|
336
336
|
alias eql? ==
|
data/lib/cloud_events/event.rb
CHANGED
|
@@ -58,14 +58,14 @@ module CloudEvents
|
|
|
58
58
|
# @param spec_version [String] The required `specversion` field.
|
|
59
59
|
# @param kwargs [keywords] Additional parameters for the event.
|
|
60
60
|
#
|
|
61
|
-
def create
|
|
61
|
+
def create(spec_version:, **kwargs)
|
|
62
62
|
case spec_version
|
|
63
63
|
when "0.3"
|
|
64
|
-
V0.new
|
|
64
|
+
V0.new(spec_version: spec_version, **kwargs)
|
|
65
65
|
when /^1(\.|$)/
|
|
66
|
-
V1.new
|
|
66
|
+
V1.new(spec_version: spec_version, **kwargs)
|
|
67
67
|
else
|
|
68
|
-
raise
|
|
68
|
+
raise(SpecVersionError, "Unrecognized specversion: #{spec_version}")
|
|
69
69
|
end
|
|
70
70
|
end
|
|
71
71
|
alias new create
|
data/lib/cloud_events/format.rb
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require "base64"
|
|
4
3
|
require "json"
|
|
5
4
|
|
|
6
5
|
module CloudEvents
|
|
@@ -80,7 +79,7 @@ module CloudEvents
|
|
|
80
79
|
# @return [Hash] if accepting the request and returning a result
|
|
81
80
|
# @return [nil] if declining the request.
|
|
82
81
|
#
|
|
83
|
-
def decode_event
|
|
82
|
+
def decode_event(**_kwargs)
|
|
84
83
|
nil
|
|
85
84
|
end
|
|
86
85
|
|
|
@@ -117,7 +116,7 @@ module CloudEvents
|
|
|
117
116
|
# @return [Hash] if accepting the request and returning a result
|
|
118
117
|
# @return [nil] if declining the request.
|
|
119
118
|
#
|
|
120
|
-
def encode_event
|
|
119
|
+
def encode_event(**_kwargs)
|
|
121
120
|
nil
|
|
122
121
|
end
|
|
123
122
|
|
|
@@ -156,7 +155,7 @@ module CloudEvents
|
|
|
156
155
|
# @return [Hash] if accepting the request and returning a result
|
|
157
156
|
# @return [nil] if declining the request.
|
|
158
157
|
#
|
|
159
|
-
def decode_data
|
|
158
|
+
def decode_data(**_kwargs)
|
|
160
159
|
nil
|
|
161
160
|
end
|
|
162
161
|
|
|
@@ -195,7 +194,7 @@ module CloudEvents
|
|
|
195
194
|
# @return [Hash] if accepting the request and returning a result
|
|
196
195
|
# @return [nil] if declining the request.
|
|
197
196
|
#
|
|
198
|
-
def encode_data
|
|
197
|
+
def encode_data(**_kwargs)
|
|
199
198
|
nil
|
|
200
199
|
end
|
|
201
200
|
|
|
@@ -213,7 +212,7 @@ module CloudEvents
|
|
|
213
212
|
# format's result as an argument, and returns either the result to
|
|
214
213
|
# indicate acceptability, or `nil` to indicate not.
|
|
215
214
|
#
|
|
216
|
-
def initialize
|
|
215
|
+
def initialize(formats = [], &result_checker)
|
|
217
216
|
@formats = formats
|
|
218
217
|
@result_checker = result_checker
|
|
219
218
|
end
|
|
@@ -228,10 +227,10 @@ module CloudEvents
|
|
|
228
227
|
##
|
|
229
228
|
# Implements {Format#decode_event}
|
|
230
229
|
#
|
|
231
|
-
def decode_event
|
|
230
|
+
def decode_event(**kwargs)
|
|
232
231
|
@formats.each do |elem|
|
|
233
232
|
result = elem.decode_event(**kwargs)
|
|
234
|
-
result = @result_checker.call
|
|
233
|
+
result = @result_checker.call(result) if @result_checker
|
|
235
234
|
return result if result
|
|
236
235
|
end
|
|
237
236
|
nil
|
|
@@ -240,10 +239,10 @@ module CloudEvents
|
|
|
240
239
|
##
|
|
241
240
|
# Implements {Format#encode_event}
|
|
242
241
|
#
|
|
243
|
-
def encode_event
|
|
242
|
+
def encode_event(**kwargs)
|
|
244
243
|
@formats.each do |elem|
|
|
245
244
|
result = elem.encode_event(**kwargs)
|
|
246
|
-
result = @result_checker.call
|
|
245
|
+
result = @result_checker.call(result) if @result_checker
|
|
247
246
|
return result if result
|
|
248
247
|
end
|
|
249
248
|
nil
|
|
@@ -252,10 +251,10 @@ module CloudEvents
|
|
|
252
251
|
##
|
|
253
252
|
# Implements {Format#decode_data}
|
|
254
253
|
#
|
|
255
|
-
def decode_data
|
|
254
|
+
def decode_data(**kwargs)
|
|
256
255
|
@formats.each do |elem|
|
|
257
256
|
result = elem.decode_data(**kwargs)
|
|
258
|
-
result = @result_checker.call
|
|
257
|
+
result = @result_checker.call(result) if @result_checker
|
|
259
258
|
return result if result
|
|
260
259
|
end
|
|
261
260
|
nil
|
|
@@ -264,10 +263,10 @@ module CloudEvents
|
|
|
264
263
|
##
|
|
265
264
|
# Implements {Format#encode_data}
|
|
266
265
|
#
|
|
267
|
-
def encode_data
|
|
266
|
+
def encode_data(**kwargs)
|
|
268
267
|
@formats.each do |elem|
|
|
269
268
|
result = elem.encode_data(**kwargs)
|
|
270
|
-
result = @result_checker.call
|
|
269
|
+
result = @result_checker.call(result) if @result_checker
|
|
271
270
|
return result if result
|
|
272
271
|
end
|
|
273
272
|
nil
|