From 26a4391e15e66c8cf7f0becae39d8e5a2810dd24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Wed, 20 May 2020 11:01:27 +0200 Subject: [PATCH] Use `ruby2_keywords` for the moment Without this gem, current activeadmin version becomes incompatible with the master branch of `arbre`. It shouldn't be an issue as long as we update activeadmin's code to use keyword arguments everywhere, set a minimum dependency on the next `arbre` and release both gems at the same time, but I think it's easier to be conservative. --- Gemfile.lock | 2 ++ arbre.gemspec | 1 + lib/arbre/context.rb | 21 ++++++--------------- lib/arbre/element.rb | 33 ++++++++++----------------------- 4 files changed, 19 insertions(+), 38 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index bd1d6bb5..3b2a8f23 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -3,6 +3,7 @@ PATH specs: arbre (1.2.1) activesupport (>= 3.0.0, < 6.1) + ruby2_keywords (>= 0.0.2) GEM remote: http://rubygems.org/ @@ -190,6 +191,7 @@ GEM rubocop-ast (0.0.3) parser (>= 2.7.0.1) ruby-progressbar (1.10.1) + ruby2_keywords (0.0.2) sawyer (0.8.1) addressable (>= 2.3.5, < 2.6) faraday (~> 0.8, < 1.0) diff --git a/arbre.gemspec b/arbre.gemspec index 06390c17..1248ecec 100644 --- a/arbre.gemspec +++ b/arbre.gemspec @@ -22,4 +22,5 @@ Gem::Specification.new do |s| s.required_ruby_version = '>= 2.5' s.add_dependency("activesupport", ">= 3.0.0", "< 6.1") + s.add_dependency("ruby2_keywords", ">= 0.0.2") end diff --git a/lib/arbre/context.rb b/lib/arbre/context.rb index e86b0024..7fab0199 100644 --- a/lib/arbre/context.rb +++ b/lib/arbre/context.rb @@ -1,4 +1,5 @@ require 'arbre/element' +require 'ruby2_keywords' module Arbre @@ -74,21 +75,11 @@ def respond_to_missing?(method, include_all) # Webservers treat Arbre::Context as a string. We override # method_missing to delegate to the string representation # of the html. - if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("2.7.a") - def method_missing(method, *args, **kwargs, &block) - if cached_html.respond_to? method - cached_html.send method, *args, **kwargs, &block - else - super - end - end - else - def method_missing(method, *args, &block) - if cached_html.respond_to? method - cached_html.send method, *args, &block - else - super - end + ruby2_keywords def method_missing(method, *args, &block) + if cached_html.respond_to? method + cached_html.send method, *args, &block + else + super end end diff --git a/lib/arbre/element.rb b/lib/arbre/element.rb index 22308a31..bf3d4062 100644 --- a/lib/arbre/element.rb +++ b/lib/arbre/element.rb @@ -1,6 +1,7 @@ require 'arbre/element/builder_methods' require 'arbre/element/proxy' require 'arbre/element_collection' +require 'ruby2_keywords' module Arbre @@ -172,29 +173,15 @@ def clear_children! # 3. Call the method on the helper object # 4. Call super # - if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("2.7.a") - def method_missing(name, *args, **kwargs, &block) - if current_arbre_element.respond_to?(name) - current_arbre_element.send name, *args, **kwargs, &block - elsif assigns && assigns.has_key?(name) - assigns[name] - elsif helpers.respond_to?(name) - helpers.send(name, *args, **kwargs, &block) - else - super - end - end - else - def method_missing(name, *args, &block) - if current_arbre_element.respond_to?(name) - current_arbre_element.send name, *args, &block - elsif assigns && assigns.has_key?(name) - assigns[name] - elsif helpers.respond_to?(name) - helpers.send(name, *args, &block) - else - super - end + ruby2_keywords def method_missing(name, *args, &block) + if current_arbre_element.respond_to?(name) + current_arbre_element.send name, *args, &block + elsif assigns && assigns.has_key?(name) + assigns[name] + elsif helpers.respond_to?(name) + helpers.send(name, *args, &block) + else + super end end