module Disposable::Twin::Coercion::ClassMethods

Public Instance Methods

coercing_setter!(name, type, nilify=false) click to toggle source
Calls superclass method
# File lib/disposable/twin/coercion.rb, line 20
def coercing_setter!(name, type, nilify=false)
  # TODO: remove nilily with next release (0.5) for new dry-type versions
  type = type ? (DRY_TYPES_CONSTANT::Nil | type) : DRY_TYPES_CONSTANT::Nil if nilify

  warn "DEPRECATION WARNING [Disposable]: nilify is deprecated and it will be removed with the next release" if nilify && DRY_TYPES_VERSION >= Gem::Version.new("1.0.0")

  mod = Module.new do
    define_method("#{name}=") do |value|
      super type.(value)
    end
  end
  include mod
end
property(name, options={}, &block) click to toggle source
Calls superclass method
# File lib/disposable/twin/coercion.rb, line 14
def property(name, options={}, &block)
  super(name, options, &block).tap do
    coercing_setter!(name, options[:type], options[:nilify]) if options[:type] || options[:nilify]
  end
end