Method: JSONAPIonify::Types::BaseType.loader

Defined in:
lib/jsonapionify/types.rb

.loader(&block) ⇒ Object



36
37
38
39
40
41
42
43
# File 'lib/jsonapionify/types.rb', line 36

def self.loader(&block)
  meth = instance_method define_method(:load, &block)
  define_method(:load) do |value|
    return nil if value.nil? && !not_null?
    raise NotNullError if value.nil? && not_null?
    meth.bind(self).call(value)
  end
end