Skip to content

Commit

Permalink
FIX: Make MiniProfiler.profile_method compatible with Ruby 3 (#481)
Browse files Browse the repository at this point in the history
* Make MiniProfiler.profile_method compatible with Ruby 3

Signed-off-by: OsamaSayegh <[email protected]>

* use ruby2_keywords hack

Signed-off-by: OsamaSayegh <[email protected]>
  • Loading branch information
OsamaSayegh authored Jan 28, 2021
1 parent 8711a00 commit 1994a3d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ jobs:
options: --health-cmd "timeout 5 bash -c 'cat < /dev/null > /dev/udp/127.0.0.1/11211'" --health-interval 10s --health-timeout 5s --health-retries 5
strategy:
matrix:
ruby: ["2.7", "2.6", "2.5"]
ruby: ["3.0", "2.7", "2.6", "2.5"]
redis: ["5.x"]
steps:
- uses: actions/checkout@v2
- uses: actions/setup-ruby@v1
- uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
- name: Setup redis
Expand Down
4 changes: 3 additions & 1 deletion lib/mini_profiler/profiling_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ def profile_method(klass, method, type = :profile, &blk)
end
end
end
if klass.respond_to?(:ruby2_keywords, true)
klass.send(:ruby2_keywords, with_profiling)
end
klass.send :alias_method, method, with_profiling
end

Expand Down Expand Up @@ -154,7 +157,6 @@ def counter(type, duration_ms = nil)
def clean_method_name(method)
method.to_s.gsub(/[\?\!]/, "")
end

end
end
end
12 changes: 12 additions & 0 deletions spec/lib/profiler_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ def foo(bar, baz)
[bar, baz, yield]
end

def kwargs_test(a, b, c = 1, d: 4)
{ a: a, b: b, c: c, d: d }
end

def self.bar(baz, boo)
[baz, boo, yield]
end
Expand All @@ -76,6 +80,14 @@ def self.bar(baz, boo)
Rack::MiniProfiler.unprofile_singleton_method TestClass, :bar
end

it 'optional positional args and keyword args should not conflict' do
block_args = nil
Rack::MiniProfiler.profile_method(TestClass, :kwargs_test) do |a, b, c = 1, d: 4|
block_args = { a: a, b: b, c: c, d: d }
end
expect(TestClass.new.kwargs_test(10, 20, d: 90)).to eq({ a: 10, b: 20, c: 1, d: 90 })
expect(block_args).to eq({ a: 10, b: 20, c: 1, d: 90 })
end
end

describe 'step' do
Expand Down

0 comments on commit 1994a3d

Please sign in to comment.