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

Implement Ruby 3 support? #20

Open
olofheurgren opened this issue Sep 24, 2021 · 2 comments
Open

Implement Ruby 3 support? #20

olofheurgren opened this issue Sep 24, 2021 · 2 comments

Comments

@olofheurgren
Copy link

olofheurgren commented Sep 24, 2021

Hi!

I realize this might be far-fetched since the gem has not been updated in a long time, but is there any possibility that support for Ruby 3.x will be implemented?

Ruby 3 introduces breaking changes related to keyword arguments and I suspect this causes errors with Sinja. Declaring a resource causes an ArgumentError in Ruby 3.0.1. For instance, this program:

require 'sinatra/base'
require 'sinatra/jsonapi'
require 'jsonapi-serializers'

class App < Sinatra::Base
  register Sinatra::JSONAPI

  resource :foos do
  end 
end

App.run!

yields:

.../.rvm/gems/ruby-3.0.1/gems/sinatra-2.1.0/lib/sinatra/base.rb:1650:in `route': wrong number of arguments (given 4, expected 2..3) (ArgumentError)
  from .../.rvm/gems/ruby-3.0.1/gems/sinja-1.3.0/lib/sinja.rb:386:in `route'
  from .../.rvm/gems/ruby-3.0.1/gems/sinatra-2.1.0/lib/sinatra/base.rb:1443:in `options'
  from .../.rvm/gems/ruby-3.0.1/gems/sinatra-contrib-2.1.0/lib/sinatra/namespace.rb:341:in `prefixed'
  from .../.rvm/gems/ruby-3.0.1/gems/sinatra-contrib-2.1.0/lib/sinatra/namespace.rb:234:in `block (2 levels) in prefixed'
  from .../.rvm/gems/ruby-3.0.1/gems/sinja-1.3.0/lib/sinja/resource_routes.rb:12:in `registered'
  from .../.rvm/gems/ruby-3.0.1/gems/sinatra-contrib-2.1.0/lib/sinatra/namespace.rb:249:in `block in register'
  from .../.rvm/gems/ruby-3.0.1/gems/sinatra-contrib-2.1.0/lib/sinatra/namespace.rb:247:in `each'
  from .../.rvm/gems/ruby-3.0.1/gems/sinatra-contrib-2.1.0/lib/sinatra/namespace.rb:247:in `register'
  from .../.rvm/gems/ruby-3.0.1/gems/sinja-1.3.0/lib/sinja/resource.rb:28:in `registered'
  from .../.rvm/gems/ruby-3.0.1/gems/sinatra-contrib-2.1.0/lib/sinatra/namespace.rb:249:in `block in register'
  from .../.rvm/gems/ruby-3.0.1/gems/sinatra-contrib-2.1.0/lib/sinatra/namespace.rb:247:in `each'
  from .../.rvm/gems/ruby-3.0.1/gems/sinatra-contrib-2.1.0/lib/sinatra/namespace.rb:247:in `register'
  from .../.rvm/gems/ruby-3.0.1/gems/sinja-1.3.0/lib/sinja.rb:356:in `block in resource'
  from .../.rvm/gems/ruby-3.0.1/gems/sinatra-contrib-2.1.0/lib/sinatra/namespace.rb:199:in `class_eval'
  from .../.rvm/gems/ruby-3.0.1/gems/sinatra-contrib-2.1.0/lib/sinatra/namespace.rb:199:in `block in new'
  from .../.rvm/gems/ruby-3.0.1/gems/sinatra-contrib-2.1.0/lib/sinatra/namespace.rb:189:in `initialize'
  from .../.rvm/gems/ruby-3.0.1/gems/sinatra-contrib-2.1.0/lib/sinatra/namespace.rb:189:in `new'
  from .../.rvm/gems/ruby-3.0.1/gems/sinatra-contrib-2.1.0/lib/sinatra/namespace.rb:189:in `new'
  from .../.rvm/gems/ruby-3.0.1/gems/sinatra-contrib-2.1.0/lib/sinatra/namespace.rb:219:in `namespace'
  from .../.rvm/gems/ruby-3.0.1/gems/sinja-1.3.0/lib/sinja.rb:333:in `resource'
  from sinja_demo.rb:8:in `<class:App>'
  from sinja_demo.rb:5:in `<main>'

whereas it works fine when using Ruby 2.7.x.

I think Sinja looks really nice and it would definitely suit my needs, so fingers crossed this will be considered :)

Thanks!

@mwpastore mwpastore pinned this issue Sep 24, 2021
@olofheurgren
Copy link
Author

I forgot to mention that the stack trace was produced using Sinatra's master branch instead of rubygems.org. It contains fixes also related to keyword arguments that have not been released yet. See sinatra/sinatra#1720

@hugopeixoto
Copy link

I'm fixing these issues as I bump into them.

Fixes available in in this branch: https://github.com/hugopeixoto/sinja/tree/fix/ruby-3-support

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