Skip to content

Commit

Permalink
Use ruby2_keywords for the moment (#205)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
deivid-rodriguez committed May 21, 2020
1 parent 22ce9de commit b546d7a
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 38 deletions.
2 changes: 2 additions & 0 deletions Gemfile.lock
Expand Up @@ -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/
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions arbre.gemspec
Expand Up @@ -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
21 changes: 6 additions & 15 deletions lib/arbre/context.rb
@@ -1,4 +1,5 @@
require 'arbre/element'
require 'ruby2_keywords'

module Arbre

Expand Down Expand Up @@ -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

Expand Down
33 changes: 10 additions & 23 deletions 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

Expand Down Expand Up @@ -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

Expand Down

0 comments on commit b546d7a

Please sign in to comment.