Skip to content

Commit

Permalink
Make method missing methods compatible with ruby 3.0 keyword argument…
Browse files Browse the repository at this point in the history
… handling
  • Loading branch information
Timmitry committed May 3, 2022
1 parent be01ce9 commit f7aa7a4
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 18 deletions.
4 changes: 2 additions & 2 deletions lib/trestle/admin.rb
Expand Up @@ -9,9 +9,9 @@ def initialize(context=nil)
end

# Delegate all missing methods to corresponding class method if available
def method_missing(name, *args, &block)
def method_missing(name, *args, **kwargs, &block)
if self.class.respond_to?(name)
self.class.send(name, *args, &block)
self.class.send(name, *args, **kwargs, &block)
else
super
end
Expand Down
7 changes: 2 additions & 5 deletions lib/trestle/evaluation_context.rb
Expand Up @@ -5,16 +5,13 @@ module Trestle
# both the Adapter/Navigation instance, as well as the controller/view from where they are invoked.
module EvaluationContext
protected
def self.ruby2_keywords(*)
end unless respond_to?(:ruby2_keywords, true)

# Missing methods are called on the given context if available.
#
# We include private methods as methods such as current_user
# are usually declared as private or protected.
ruby2_keywords def method_missing(name, *args, &block)
def method_missing(name, *args, **kwargs, &block)
if context_responds_to?(name)
@context.send(name, *args, &block)
@context.send(name, *args, **kwargs, &block)
else
super
end
Expand Down
4 changes: 2 additions & 2 deletions lib/trestle/form/builder.rb
Expand Up @@ -29,9 +29,9 @@ def respond_to_missing?(name, include_all=false)
self.class.fields.has_key?(name) || super
end

def method_missing(name, *args, &block)
def method_missing(name, *args, **kwargs, &block)
if field = self.class.fields[name]
field.new(self, @template, *args, &block).render
field.new(self, @template, *args, **kwargs, &block).render
else
super
end
Expand Down
11 changes: 4 additions & 7 deletions lib/trestle/form/renderer.rb
Expand Up @@ -4,9 +4,6 @@
module Trestle
class Form
class Renderer
def self.ruby2_keywords(*)
end unless respond_to?(:ruby2_keywords, true)

include ::ActionView::Context
include ::ActionView::Helpers::CaptureHelper

Expand Down Expand Up @@ -43,15 +40,15 @@ def fields_for(*args, &block)
concat(result)
end

ruby2_keywords def method_missing(name, *args, &block)
def method_missing(name, *args, **kwargs, &block)
target = @form.respond_to?(name) ? @form : @template

if block_given? && !RAW_BLOCK_HELPERS.include?(name)
result = target.send(name, *args) do |*blockargs|
render_form(*blockargs, &block)
result = target.send(name, *args, **kwargs) do |*blockargs, **kwblockargs|
render_form(*blockargs, **kwblockargs &block)
end
else
result = target.send(name, *args, &block)
result = target.send(name, *args, **kwargs, &block)
end

if target == @form || WHITELISTED_HELPERS.include?(name)
Expand Down
4 changes: 2 additions & 2 deletions lib/trestle/toolbar/context.rb
Expand Up @@ -25,8 +25,8 @@ def respond_to_missing?(name, include_all=false)
builder.respond_to?(name) || super
end

def method_missing(name, *args, &block)
result = builder.send(name, *args, &block)
def method_missing(name, *args, **kwargs, &block)
result = builder.send(name, *args, **kwargs, &block)

if builder.builder_methods.include?(name)
group { @current_group << result }
Expand Down

0 comments on commit f7aa7a4

Please sign in to comment.