Skip to content

Commit 8f0ac6b

Browse files
authored
feat: Require Ruby 2.5 or later
Signed-off-by: Daniel Azuma <dazuma@google.com>
1 parent 2855c15 commit 8f0ac6b

File tree

8 files changed

+27
-26
lines changed

8 files changed

+27
-26
lines changed

.github/workflows/ci.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ jobs:
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

.rubocop.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff 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

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
source "https://rubygems.org"
22
gemspec
33

4-
gem "google-style", "~> 1.24.0"
4+
gem "google-style", "~> 1.25.1"
55
gem "minitest", "~> 5.14"
66
gem "minitest-focus", "~> 1.1"
77
gem "minitest-rg", "~> 5.2"

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff 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
3737
source "https://rubygems.org"
38-
gem "cloud_events", "~> 0.1"
38+
gem "cloud_events", "~> 0.2"
3939
gem "sinatra", "~> 2.0"
4040
```
4141

@@ -59,7 +59,7 @@ A simple Ruby script that sends a CloudEvent:
5959
```ruby
6060
# examples/client/Gemfile
6161
source "https://rubygems.org"
62-
gem "cloud_events", "~> 0.1"
62+
gem "cloud_events", "~> 0.2"
6363
```
6464

6565
```ruby

cloud_events.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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"

lib/cloud_events/content_type.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff 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

lib/cloud_events/http_binding.rb

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff 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
292300
end

lib/cloud_events/json_format.rb

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)