Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copy newer rails code for rewording or removing poorly named constants #1501

Merged
merged 1 commit into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/active_fedora/attribute_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down Expand Up @@ -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:
Expand Down
27 changes: 1 addition & 26 deletions lib/active_fedora/relation/delegation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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