From 57268a1e8f2616457fefe50b61775361b5aee7ce Mon Sep 17 00:00:00 2001 From: Thomas Reynolds Date: Thu, 27 Dec 2018 12:55:04 -0800 Subject: [PATCH] Pass all known methods through proxy. For #2228 --- .../middleman-core/core_extensions/data/proxies/array.rb | 3 +-- .../middleman-core/core_extensions/data/proxies/base.rb | 2 +- .../middleman-core/core_extensions/data/proxies/hash.rb | 8 +++++--- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/middleman-core/lib/middleman-core/core_extensions/data/proxies/array.rb b/middleman-core/lib/middleman-core/core_extensions/data/proxies/array.rb index ee599d21..8987d6e7 100644 --- a/middleman-core/lib/middleman-core/core_extensions/data/proxies/array.rb +++ b/middleman-core/lib/middleman-core/core_extensions/data/proxies/array.rb @@ -6,8 +6,7 @@ module Middleman module Data module Proxies class ArrayProxy < BaseProxy - FULL_ACCESS_METHODS = Set.new %i[size any? inspect join] - WRAPPED_LIST_METHODS = Set.new %i[each select sort shuffle reverse] + WRAPPED_LIST_METHODS = Set.new %i[each each_with_index select sort shuffle reverse] def method_missing(name, *args, &block) if self.class.const_get(:WRAPPED_LIST_METHODS).include?(name) diff --git a/middleman-core/lib/middleman-core/core_extensions/data/proxies/base.rb b/middleman-core/lib/middleman-core/core_extensions/data/proxies/base.rb index d1b764cf..95810592 100644 --- a/middleman-core/lib/middleman-core/core_extensions/data/proxies/base.rb +++ b/middleman-core/lib/middleman-core/core_extensions/data/proxies/base.rb @@ -16,7 +16,7 @@ module Middleman end def method_missing(name, *args, &block) - if self.class.const_get(:FULL_ACCESS_METHODS).include?(name) + if @data.respond_to?(name) log_access(:__full_access__) return @data.send(name, *args, &block) diff --git a/middleman-core/lib/middleman-core/core_extensions/data/proxies/hash.rb b/middleman-core/lib/middleman-core/core_extensions/data/proxies/hash.rb index 308af727..884c36fc 100644 --- a/middleman-core/lib/middleman-core/core_extensions/data/proxies/hash.rb +++ b/middleman-core/lib/middleman-core/core_extensions/data/proxies/hash.rb @@ -5,8 +5,6 @@ module Middleman module Data module Proxies class HashProxy < BaseProxy - FULL_ACCESS_METHODS = Set.new %i[size inspect keys key? values each_key] - def fetch(key, default = Undefined, &block) wrap_data key.to_sym, @data.fetch(key, default, &block) end @@ -17,7 +15,11 @@ module Middleman alias get [] def method_missing(name, *_args) - self[name] if @data.key?(name) + return self[name] if @data.key?(name) + + super + rescue NoMethodError + nil end end end