diff --git a/lib/active_fedora/attribute_methods.rb b/lib/active_fedora/attribute_methods.rb index b9595c0a1..979763ba1 100644 --- a/lib/active_fedora/attribute_methods.rb +++ b/lib/active_fedora/attribute_methods.rb @@ -14,7 +14,7 @@ def self.set_name_cache(name, value) end end - BLACKLISTED_CLASS_METHODS = %w[private public protected allocate new name parent superclass].freeze + RESTRICTED_CLASS_METHODS = %w[private public protected allocate new name parent superclass].freeze class GeneratedAttributeMethods < Module; end # :nodoc: @@ -81,7 +81,7 @@ def method_defined_within?(name, klass, superklass = klass.superclass) # :nodoc: # A class method is 'dangerous' if it is already (re)defined by Active Record, but # not by any ancestors. (So 'puts' is not dangerous but 'new' is.) def dangerous_class_method?(method_name) - BLACKLISTED_CLASS_METHODS.include?(method_name.to_s) || class_method_defined_within?(method_name, Base) + RESTRICTED_CLASS_METHODS.include?(method_name.to_s) || class_method_defined_within?(method_name, Base) end def class_method_defined_within?(name, klass, superklass = klass.superclass) # :nodoc: diff --git a/lib/active_fedora/relation/delegation.rb b/lib/active_fedora/relation/delegation.rb index 70cb4ba21..3742125b0 100644 --- a/lib/active_fedora/relation/delegation.rb +++ b/lib/active_fedora/relation/delegation.rb @@ -7,32 +7,7 @@ module Delegation # :nodoc: # may vary depending on the klass of a relation, so we create a subclass of Relation # for each different klass, and the delegations are compiled into that subclass only. - BLACKLISTED_ARRAY_METHODS = [ - :compact!, :flatten!, :reject!, :reverse!, :rotate!, :map!, - :shuffle!, :slice!, :sort!, :sort_by!, :delete_if, - :keep_if, :pop, :shift, :delete_at, :select! - ].to_set - - delegate :length, :map, :to_ary, to: :to_a + delegate :length, :map, :to_ary, :[], :&, :|, :+, :-, :sample, :reverse, :rotate, :compact, :shuffle, :slice, :index, :rindex, :size, to: :to_a delegate :any?, :all?, :collect, :include?, to: :each - - protected - - def array_delegable?(method) - Array.method_defined?(method) && BLACKLISTED_ARRAY_METHODS.exclude?(method) - end - - def method_missing(method, *args, &block) - if array_delegable?(method) - self.class.delegate method, to: :to_a - to_a.public_send(method, *args, &block) - else - super - end - end - - def respond_to_missing?(method, *args) - array_delegable?(method) || super - end end end