Skip to content

Commit

Permalink
Update for Ruby 3 (#63)
Browse files Browse the repository at this point in the history
* Update for Ruby 3

* Fix formatting issues from standardrb

* Adjust tests to Ruby 3

* Fix formatting

* Update README and Gemspec

* Update changelog
  • Loading branch information
Acconut authored Jan 9, 2024
1 parent a7d3d5d commit 0f73dd6
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 33 deletions.
12 changes: 4 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,9 @@ jobs:
strategy:
matrix:
ruby:
- 2.2
- 2.3
- 2.4
- 2.5
- 2.6
- 2.7
- 3.0
- 3.1
- 3.2
- jruby
# - jruby-head
- truffleruby
Expand All @@ -22,6 +19,5 @@ jobs:
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true
- if: ${{ matrix.ruby == '2.5' }}
run: bundle exec standardrb
- run: bundle exec standardrb
- run: COVERAGE=false bundle exec rake test
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
### 3.0.0 / ????-??-?? ###

* BREAKING: Drop support for EOL'd Ruby 2.x
* Prevent duplicate assembly steps [#49](https://github.com/transloadit/ruby-sdk/issues/27) (@ifedapoolarewaju)
* Send "Transloadit-Client" header for every request (@ifedapoolarewaju)

Expand Down
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,6 @@ for the latest [git master](http://rubydoc.info/github/transloadit/ruby-sdk/mast
Please see [ci.yml](https://github.com/transloadit/ruby-sdk/tree/master/.github/workflows/ci.yml) for a list of supported ruby versions. It may also work on older Rubies, but support for those is not guaranteed. If it doesn't work on one of the officially supported Rubies, please file a
[bug report](https://github.com/transloadit/ruby-sdk/issues). Compatibility patches for other Rubies are welcome.

### Ruby 1.9.x & 2.0
### Ruby 2.x

If you still need support for older versions of Ruby, 1.2.0 is the last version that
supports those.
If you still need support for Ruby 2.x, 2.0.1 is the last version that supports it.
18 changes: 9 additions & 9 deletions lib/transloadit/assembly.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def create!(*ios, **params)
# keeping this method for backward compatibility
#
def submit!(*ios)
warn "#{caller(1..1).first}: warning: Transloadit::Assembly#submit!"\
warn "#{caller(1..1).first}: warning: Transloadit::Assembly#submit!" \
" is deprecated. use Transloadit::Assembly#create! instead"
create!(*ios)
end
Expand Down Expand Up @@ -140,14 +140,14 @@ def to_hash
#
def _wrap_steps_in_hash(steps)
case steps
when nil then steps
when Hash then steps
when Transloadit::Step then steps.to_hash
else
if steps.uniq(&:name) != steps
raise ArgumentError, "There are different Assembly steps using the same name"
end
steps.inject({}) { |h, s| h.update s }
when nil then steps
when Hash then steps
when Transloadit::Step then steps.to_hash
else
if steps.uniq(&:name) != steps
raise ArgumentError, "There are different Assembly steps using the same name"
end
steps.inject({}) { |h, s| h.update s }
end
end

Expand Down
7 changes: 3 additions & 4 deletions lib/transloadit/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ def self._hmac(key, message)
#
def api(options = {})
@api ||= case url.host
when String then RestClient::Resource.new(url.host, options)
else RestClient::Resource.new(API_ENDPOINT.host, options)
when String then RestClient::Resource.new(url.host, options)
else RestClient::Resource.new(API_ENDPOINT.host, options)
end
end

Expand Down Expand Up @@ -158,9 +158,8 @@ def to_query(params = nil)
return "" if params.nil?
return "" if params.respond_to?(:empty?) && params.empty?

escape = Regexp.new("[^#{URI::PATTERN::UNRESERVED}]")
params_in_json = MultiJson.dump(params)
uri_params = URI.escape(params_in_json, escape)
uri_params = URI.encode_www_form_component(params_in_json)

params = {
params: uri_params,
Expand Down
6 changes: 3 additions & 3 deletions lib/transloadit/step.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ def use(input)
options.delete(:use) && return if input.nil?

options[:use] = case input
when Symbol then input.inspect
when Array then input.map { |i| i.name }
else [input.name]
when Symbol then input.inspect
when Array then input.map { |i| i.name }
else [input.name]
end
end

Expand Down
8 changes: 4 additions & 4 deletions test/unit/transloadit/test_assembly.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@

it "must allow steps through the create! method" do
Transloadit::Assembly.new(@transloadit).create!(
{steps: @transloadit.step("thumbs", "/video/thumbs")}
steps: @transloadit.step("thumbs", "/video/thumbs")
)

assert_requested(:post, "api2.transloadit.com/assemblies") do |req|
Expand All @@ -99,7 +99,7 @@
end

it "must allow steps passed through the create! method override steps previously set" do
@assembly.create!({steps: @transloadit.step("resize", "/image/resize")})
@assembly.create!(steps: @transloadit.step("resize", "/image/resize"))

assert_requested(:post, "api2.transloadit.com/assemblies") do |req|
values = values_from_post_body(req.body)
Expand All @@ -112,7 +112,7 @@
it "must call the create! method with the same parameters" do
VCR.use_cassette "submit_assembly" do
file = open("lib/transloadit/version.rb")
mocker = MiniTest::Mock.new
mocker = Minitest::Mock.new
mocker.expect :call, nil, [file]
@assembly.stub :create!, mocker do
@assembly.submit!(file)
Expand Down Expand Up @@ -172,7 +172,7 @@
thumbs_duplicate = @transloadit.step("thumbs", "/video/encode")
options = {steps: [thumbs, thumbs_duplicate]}
assert_raises ArgumentError do
@assembly.create! open("lib/transloadit/version.rb"), options
@assembly.create! open("lib/transloadit/version.rb"), **options
end
end
end
Expand Down
3 changes: 1 addition & 2 deletions transloadit.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@ Gem::Specification.new do |gem|
gem.description = "The transloadit gem allows you to automate uploading files through the Transloadit REST API"

gem.required_rubygems_version = ">= 2.2.0"
gem.required_ruby_version = ">= 2.1.0"
gem.required_ruby_version = ">= 3.0.0"

gem.files = `git ls-files`.split("\n")
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
gem.require_paths = %w[lib]

gem.add_dependency "rest-client"
Expand Down

0 comments on commit 0f73dd6

Please sign in to comment.