Skip to content

Commit

Permalink
Fix frozen string literal issue for ruby 3.4 (#300)
Browse files Browse the repository at this point in the history
* Fix frozen string literal issue

* Remove base64 instead of adding it since it's never used + fix ruby 3.4 warning
  • Loading branch information
chaadow authored Aug 1, 2024
1 parent 767f353 commit d60548a
Show file tree
Hide file tree
Showing 12 changed files with 35 additions and 22 deletions.
20 changes: 18 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,21 @@ permissions:
contents: read

jobs:
Shared:
uses: fog/.github/.github/workflows/ci.yml@v1.4.0
test:

runs-on: ubuntu-latest

strategy:
matrix:
ruby-version: ['3.0', '3.1', '3.2', '3.3', 'head']
continue-on-error: ${{ matrix.ruby-version == 'head' }}

steps:
- uses: actions/checkout@v4
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby-version }}
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
- name: Run tests
run: bundle exec rake RUBYOPT="--enable-frozen-string-literal"
2 changes: 1 addition & 1 deletion lib/fog/compute.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def self.new(orig_attributes)
Fog::Compute::DigitalOcean.new(attributes)
end
else
super(orig_attributes)
super
end
end

Expand Down
1 change: 0 additions & 1 deletion lib/fog/core.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# external core dependencies
require "base64"
require "cgi"
require "uri"
require "excon"
Expand Down
2 changes: 1 addition & 1 deletion lib/fog/core/mock.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def self.random_letters_and_numbers(length)
end

def self.random_selection(characters, length)
selection = ""
selection = +""
length.times do
position = rand(characters.length)
selection << characters[position..position]
Expand Down
2 changes: 1 addition & 1 deletion lib/fog/core/provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def extended(base)
private

def underscore_name(string)
string.gsub(/::/, "/")
string.gsub("::", "/")
.gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
.gsub(/([a-z\d])([A-Z])/,'\1_\2')
.tr("-", "_")
Expand Down
2 changes: 1 addition & 1 deletion lib/fog/core/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ def secrets(*args)
@secrets ||= []
else
args.reduce(secrets) do |secrets, secret|
secrets << "@#{secret}".to_sym
secrets << :"@#{secret}"
end
end
end
Expand Down
6 changes: 3 additions & 3 deletions lib/fog/formatador.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def self.formatador
end

def self.format(object, opts = { include_nested: true })
string = init_string(object)
string = +init_string(object)
indent { string << object_string(object, opts) }
string << "#{indentation}>"
end
Expand Down Expand Up @@ -48,7 +48,7 @@ def self.init_string(object)
end

def self.object_string(object, opts)
string = attribute_string(object).to_s
string = +attribute_string(object).to_s
string << nested_objects_string(object).to_s if opts[:include_nested]
string
end
Expand All @@ -68,7 +68,7 @@ def self.nested_objects_string(object)
return nested if object.respond_to?(:empty) and object.empty?
return nested unless object.is_a?(Enumerable)

nested = "#{indentation}[\n"
nested = +"#{indentation}[\n"
indent { nested << indentation + inspect_object(object) }
nested << "#{indentation}\n#{indentation}]\n"
end
Expand Down
1 change: 0 additions & 1 deletion lib/fog/storage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ def self.parse_data(data)
headers: {
"Content-Length" => get_body_size(data),
"Content-Type" => get_content_type(data)
# "Content-MD5" => Base64.encode64(Digest::MD5.digest(metadata[:body])).strip
}
}
end
Expand Down
5 changes: 2 additions & 3 deletions lib/tasks/test_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@ def initialize
def tests(mocked)
Fog::Formatador.display_line
start = Time.now.to_i
threads = []
Thread.main[:results] = []
Fog.providers.each do |key, value|
threads << Thread.new do
threads = Fog.providers.map do |key, value|
Thread.new do
Thread.main[:results] << {
provider: value,
success: sh("export FOG_MOCK=#{mocked} && bundle exec shindont +#{key}")
Expand Down
2 changes: 1 addition & 1 deletion spec/core/collection_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
require "securerandom"

class FogTestModelForCollection < Fog::Model
identity :id
identity :id
end

class FogTestCollection < Fog::Collection
Expand Down
10 changes: 5 additions & 5 deletions spec/formatador_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def all
end

it "returns formatted representation" do
Fog::Formatador.format(@collection).must_equal @expected
_(Fog::Formatador.format(@collection)).must_equal @expected
end
end

Expand All @@ -65,7 +65,7 @@ def all
end

it "returns formatted representation" do
Fog::Formatador.format(@collection).must_equal @expected
_(Fog::Formatador.format(@collection)).must_equal @expected
end
end

Expand All @@ -90,7 +90,7 @@ def all
EOS

opts = { include_nested: false }
Fog::Formatador.format(@collection, opts).must_equal @expected
_(Fog::Formatador.format(@collection, opts)).must_equal @expected
end
end

Expand All @@ -105,7 +105,7 @@ def all
end

it "returns formatted representation" do
Fog::Formatador.format(@subject).must_equal @expected
_(Fog::Formatador.format(@subject)).must_equal @expected
end
end

Expand Down Expand Up @@ -148,7 +148,7 @@ def all
end

it "returns formatted representation" do
Fog::Formatador.format(@collection).must_equal @expected
_(Fog::Formatador.format(@collection)).must_equal @expected
end
end
end
4 changes: 2 additions & 2 deletions spec/service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class Mock; def initialize(*_args); end; end
it "returns the real service" do
Fog.stub :mocking?, false do
service = TestService.new(generic_api_key: "abc")
service.must_be_instance_of TestService::Real
_(service).must_be_instance_of TestService::Real
end
end

Expand All @@ -115,7 +115,7 @@ class Mock; def initialize(*_args); end; end
it "returns mocked service" do
Fog.stub :mocking?, true do
service = TestService.new(generic_api_key: "abc")
service.must_be_instance_of TestService::Mock
_(service).must_be_instance_of TestService::Mock
end
end

Expand Down

0 comments on commit d60548a

Please sign in to comment.