thoughtbot--factory_bot/lib/factory_bot/null_object.rb

25 lines
487 B
Ruby
Raw Normal View History

module FactoryBot
2012-05-05 02:31:31 -04:00
# @api private
2012-03-09 16:14:06 -05:00
class NullObject < ::BasicObject
def initialize(methods_to_respond_to)
@methods_to_respond_to = methods_to_respond_to.map(&:to_s)
end
def method_missing(name, *args, &block)
if respond_to?(name)
nil
else
super
end
end
2018-10-05 14:54:08 -04:00
def respond_to?(method, _include_private = false)
@methods_to_respond_to.include? method.to_s
2012-01-08 00:23:25 -05:00
end
2018-10-05 14:54:08 -04:00
def respond_to_missing?(*)
false
end
2012-01-08 00:23:25 -05:00
end
end