File tree Expand file tree Collapse file tree 8 files changed +27
-26
lines changed
Expand file tree Collapse file tree 8 files changed +27
-26
lines changed Original file line number Diff line number Diff line change 1515 strategy :
1616 matrix :
1717 include :
18- - os : ubuntu-latest
19- ruby : " 2.4"
2018 - os : ubuntu-latest
2119 ruby : " 2.5"
2220 - os : ubuntu-latest
Original file line number Diff line number Diff line change @@ -12,7 +12,3 @@ Naming/FileName:
1212 Exclude :
1313 - " examples/*/Gemfile"
1414 - " .toys/**/*.rb"
15- Style/IfUnlessModifier :
16- Enabled : false
17- Style/ModuleFunction :
18- Enabled : false
Original file line number Diff line number Diff line change 11source "https://rubygems.org"
22gemspec
33
4- gem "google-style" , "~> 1.24.0 "
4+ gem "google-style" , "~> 1.25.1 "
55gem "minitest" , "~> 5.14"
66gem "minitest-focus" , "~> 1.1"
77gem "minitest-rg" , "~> 5.2"
Original file line number Diff line number Diff line change @@ -17,7 +17,7 @@ Features:
1717 specifications.
1818 * Extensible to additional formats and protocol bindings, and future
1919 specification versions.
20- * Compatible with Ruby 2.4 or later, or JRuby 9.2.x or later. No runtime gem
20+ * Compatible with Ruby 2.5 or later, or JRuby 9.2.x or later. No runtime gem
2121 dependencies.
2222
2323## Quickstart
@@ -35,7 +35,7 @@ A simple [Sinatra](https://sinatrarb.com) app that receives CloudEvents:
3535``` ruby
3636# examples/server/Gemfile
3737source " https://rubygems.org"
38- gem " cloud_events" , " ~> 0.1 "
38+ gem " cloud_events" , " ~> 0.2 "
3939gem " sinatra" , " ~> 2.0"
4040```
4141
@@ -59,7 +59,7 @@ A simple Ruby script that sends a CloudEvent:
5959``` ruby
6060# examples/client/Gemfile
6161source " https://rubygems.org"
62- gem " cloud_events" , " ~> 0.1 "
62+ gem " cloud_events" , " ~> 0.2 "
6363```
6464
6565``` ruby
Original file line number Diff line number Diff line change @@ -21,7 +21,7 @@ version = ::CloudEvents::VERSION
2121
2222 spec . files = ::Dir . glob ( "lib/**/*.rb" ) + ::Dir . glob ( "*.md" ) + [ ".yardopts" ]
2323 spec . require_paths = [ "lib" ]
24- spec . required_ruby_version = ">= 2.4.0 "
24+ spec . required_ruby_version = ">= 2.5 "
2525
2626 if spec . respond_to? :metadata
2727 spec . metadata [ "changelog_uri" ] = "https://cloudevents.github.io/sdk-ruby/v#{ version } /file.CHANGELOG.html"
Original file line number Diff line number Diff line change @@ -140,7 +140,7 @@ def parse str
140140 end
141141
142142 def consume_token str , downcase : false , error_message : nil
143- match = /^([\w !#\ $ %&'\* \+ \ .\^ `\{ \| \ } -]+)(.*)$/ . match str
143+ match = /^([\w !#$%&'*+ .\^ `{| }-]+)(.*)$/ . match str
144144 raise ParseError , error_message || "Expected token" unless match
145145 token = match [ 1 ]
146146 token . downcase! if downcase
@@ -203,7 +203,7 @@ def consume_comments str
203203 end
204204
205205 def maybe_quote str
206- return str if /^[\w !#\ $ %&'\* \+ \ .\^ `\{ \| \ } -]+$/ =~ str
206+ return str if /^[\w !#$%&'*+ .\^ `{| }-]+$/ =~ str
207207 str = str . gsub ( "\\ " , "\\ \\ \\ \\ " ) . gsub ( "\" " , "\\ \\ \" " )
208208 "\" #{ str } \" "
209209 end
Original file line number Diff line number Diff line change @@ -228,21 +228,19 @@ def encode_binary_content event
228228 headers = { }
229229 body = nil
230230 event . to_h . each do |key , value |
231- if key == "data"
231+ case key
232+ when "data"
232233 body = value
233- elsif key == "datacontenttype"
234+ when "datacontenttype"
234235 headers [ "Content-Type" ] = value
235236 else
236237 headers [ "CE-#{ key } " ] = percent_encode value
237238 end
238239 end
239- if body . is_a? ::String
240- headers [ "Content-Type" ] ||= if body . encoding == ::Encoding . ASCII_8BIT
241- "application/octet-stream"
242- else
243- "text/plain; charset=#{ body . encoding . name . downcase } "
244- end
245- elsif body . nil?
240+ case body
241+ when ::String
242+ headers [ "Content-Type" ] ||= string_content_type body
243+ when nil
246244 headers . delete "Content-Type"
247245 else
248246 body = ::JSON . dump body
@@ -288,5 +286,15 @@ def percent_encode str
288286 end
289287 arr . pack "C*"
290288 end
289+
290+ private
291+
292+ def string_content_type str
293+ if str . encoding == ::Encoding . ASCII_8BIT
294+ "application/octet-stream"
295+ else
296+ "text/plain; charset=#{ str . encoding . name . downcase } "
297+ end
298+ end
291299 end
292300end
Original file line number Diff line number Diff line change @@ -137,10 +137,9 @@ def encode_hash_structure_v0 event
137137 structure = event . to_h
138138 data = event . data
139139 content_type = event . data_content_type
140- if data . is_a? ( ::String ) && !content_type . nil?
141- if content_type . subtype == "json" || content_type . subtype_format == "json"
142- structure [ "data" ] = ::JSON . parse data rescue data
143- end
140+ if data . is_a? ( ::String ) && !content_type . nil? &&
141+ ( content_type . subtype == "json" || content_type . subtype_format == "json" )
142+ structure [ "data" ] = ::JSON . parse data rescue data
144143 end
145144 structure
146145 end
You can’t perform that action at this time.
0 commit comments