Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Yabeda v0.13.0 breaks Ruby 2.7 #40

Closed
bibendi opened this issue Oct 8, 2024 · 4 comments
Closed

Yabeda v0.13.0 breaks Ruby 2.7 #40

bibendi opened this issue Oct 8, 2024 · 4 comments

Comments

@bibendi
Copy link
Contributor

bibendi commented Oct 8, 2024

Hey! This feature has broke Ruby 2.7

irb(Yabeda):001> labels
=> {:config=>"primary", :kind=>"SCHEMA", :cached=>false, :async=>true}

irb(Yabeda):002> ::Yabeda.activerecord.queries_total.tags
=> [:config, :kind, :cached, :async]

irb(Yabeda):003> ::Yabeda.activerecord.queries_total.increment(labels)
/usr/local/bundle/ruby/2.7.0/gems/yabeda-0.13.0/lib/yabeda/counter.rb:6:in `increment': unknown keywords: :config, :kind, :cached, :async (ArgumentError)

irb(Yabeda):004> ::Yabeda.activerecord.queries_total.increment(labels, by: 1)
=> 2
@Envek
Copy link
Member

Envek commented Oct 10, 2024

Ruby 2.x keyword argument handling for methods with arguments with default values was an absolute mess. See #26 (comment)

I shouldn't release this as is (I just didn't notice CI failure for 2.7 due to flaky specs in previous commits).

Probably I'm going to yank this release and re-release it with Ruby 2.x support dropped and minimum required Ruby bumped to 3.0

@bibendi
Copy link
Contributor Author

bibendi commented Oct 10, 2024

Doesn't the ruby2_keywords help here?

@Envek
Copy link
Member

Envek commented Oct 11, 2024

Something like this would work (but will be ugly as hell):

# def increment(tags = {}, by: 1)
def increment(*args)
 tags, by = parse_args(*args)
 # …
end

def parse_args(*args)
case args.size
when 0 # increment()
  [{}, 1]
when 1 # increment(by: 5) or increment(tags)
  if args[0].key?(:by)
    [{}, args.fetch(:by)]
  else
    [args[0], 1]
  end
when 2 # increment(tags, by: 5)
  [args[0], args[1].fetch(:by, 1)]
else
  raise ArgumentError, "wrong number of arguments (given #{args.size}, expected 0..2)"
end
end

@Envek Envek closed this as completed in 5b890ed Oct 11, 2024
@Envek
Copy link
Member

Envek commented Oct 11, 2024

Fix has been released in 0.13.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants