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

Ruby 3.0.0, LinkFormatter, positional/keyword/default arguments issue on #initialize #124

Closed
matthewkrom opened this issue Feb 9, 2021 · 6 comments

Comments

@matthewkrom
Copy link

matthewkrom commented Feb 9, 2021

The last code update for this repo is from Sept 2018, and it looks like at least one method does not support the Ruby 3.0.0 changes to keyword/positioned/default arguments, as shown below. Using #ping on the Notifier results in an ArgumentError in the LinkFormatter.

Is this still an active project, or has the team moved on to a different gem for Ruby 3?

module Slack
  class Notifier
    module Util
      class LinkFormatter

        def initialize string, formats: %i[html markdown]
          @formats = formats
          @orig    = string.respond_to?(:scrub) ? string.scrub : string
        end
      end
   end
  end
end

@matthewkrom
Copy link
Author

I've monkey-patched for the very short term, using the initializer below, which tests fine in my (possibly limited) use case. Could someone more familiar with the project report on whether the code base overall should/could support Ruby 3.0.0?

module Slack
  class Notifier
    module Util
      class LinkFormatter

        # Outmoded for Ruby 3.0.0
        # def initialize string, formats: %i[html markdown]
        #   @formats = formats
        #   @orig    = string.respond_to?(:scrub) ? string.scrub : string
        # end
        
        # Monkey patch for Ruby 3.0.0
        def initialize string, in_opts={formats: %i[html markdown]}
          opts = in_opts || {}
          @formats = opts[:formats]
          @orig    = string.respond_to?(:scrub) ? string.scrub : string
        end
        
      end
    end
  end
end

@matthutchinson
Copy link

I have this same issue, your patch worked for me, would be nice to see this fixed in the gem.

@matthutchinson
Copy link

matthutchinson commented Feb 16, 2021

Actually I think this handles the case where you don't pass any format argument

    def initialize string, opts = {}
      @formats = opts[:formats] || %i[html markdown]
      @orig    = string.respond_to?(:scrub) ? string.scrub : string
    end

right now calling Slack::Notifier::Util::LinkFormatter.format("some message") against your patch fails with a nil error

@punitcse
Copy link

PR #123 should solve the issue once merged.

@cameronbarker
Copy link

👍

@stevenosloan
Copy link
Member

#123 was merged and a new version cut, so this should be resolved.

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

5 participants