class Gorillib::Factory::NonConvertingFactory
A NonConvertingFactory
accepts objects that are already native, and throws a mismatch error for anything else.
@example
ff = Gorillib::Factory::NonConvertingFactory.new(:product => String, :blankish => ->(obj){ obj.nil? }) ff.receive(nil) #=> nil ff.receive("bob") #=> "bob" ff.receive(:bob) #=> Gorillib::Factory::FactoryMismatchError: must be an instance of String, got 3
Public Instance Methods
blankish?(obj)
click to toggle source
# File lib/gorillib/model/factories.rb, line 157 def blankish?(obj) obj.nil? ; end
receive(obj)
click to toggle source
# File lib/gorillib/model/factories.rb, line 158 def receive(obj) return nil if blankish?(obj) return obj if native?(obj) mismatched!(obj, "must be an instance of #{product},") rescue NoMethodError => err mismatched!(obj, err.message, err.backtrace) end