clowne-rb / clowne

A flexible gem for cloning models
https://clowne.evilmartians.io
MIT License
316 stars 18 forks source link

Fix Ruby 2.7 deprecation notice for Proc.new passed block capture #53

Closed Sub-Xaero closed 4 years ago

Sub-Xaero commented 4 years ago

New Ruby 2.7 projects running this gem get the following deprecation warning.

Looks like an easy fix, so I hopped in and made the change.

Open to comments and criticism :)

lib/clowne/declarations.rb:11: warning: Capturing the given block using Proc.new is deprecated; use `&block` instead
/bundle/ruby/2.7.0/gems/clowne-1.1.0/lib/clowne/declarations.rb:11: warning: Capturing the given block using Proc.new is deprecated; use `&block` instead
/bundle/ruby/2.7.0/gems/clowne-1.1.0/lib/clowne/declarations.rb:11: warning: Capturing the given block using Proc.new is deprecated; use `&block` instead

for the following lines:

module Clowne
  module Declarations # :nodoc:
    module_function

    def add(id, declaration = nil)
      declaration = Proc.new if block_given?

      if declaration.is_a?(Class)
        DSL.send(:define_method, id) do |*args, &block|
          declarations.push declaration.new(*args, &block)
        end
      elsif declaration.is_a?(Proc)
        DSL.send(:define_method, id, &declaration)
      else
        raise ArgumentError, "Unsupported declaration type: #{declaration.class}"
      end
    end
  end
end
Sub-Xaero commented 4 years ago

Thanks for approving this! Let me know if you need anything else from me in order to get it merged in :)

palkan commented 4 years ago

We only need @ssnickolay to push the button 🙂

ssnickolay commented 4 years ago

@Sub-Xaero thanks for the PR! p.s. I'll bump gem version today\tomorrow

Sub-Xaero commented 4 years ago

Amazing, thanks for the fast response! 😊