lib/rails/graphql/helpers/with_owner.rb in rails-graphql-0.1.3 vs lib/rails/graphql/helpers/with_owner.rb in rails-graphql-0.2.0
- old
+ new
@@ -4,13 +4,20 @@
module GraphQL # :nodoc:
module Helpers # :nodoc:
# Helper module that allows other objects to hold an +assigned_to+ object
module WithOwner
def self.included(other)
+ other.extend(WithOwner::ClassMethods)
other.class_attribute(:owner, instance_writer: false)
end
+ module ClassMethods # :nodoc: all
+ def method_defined?(method_name)
+ super || owner&.method_defined?(method_name)
+ end
+ end
+
private
def respond_to_missing?(*args) # :nodoc:
owner_respond_to?(*args) || super
end
@@ -22,11 +29,12 @@
end
end
# Since owners are classes, this checks for the instance methods of
# it, since this is a instance method
- def owner_respond_to?(method_name, include_private = false)
- (include_private ? %i[public protected private] : %i[public]).any? do |type|
+ def owner_respond_to?(method_name, with_private = false)
+ return true if !owner.is_a?(Class) && owner.respond_to?(method_name, with_private)
+ (with_private ? %i[public protected private] : %i[public]).any? do |type|
owner.send("#{type}_instance_methods").include?(method_name)
end unless owner.nil?
end
end
end