Module: Disposable::Twin::Coercion::ClassMethods
- Defined in:
- lib/disposable/twin/coercion.rb
Instance Method Summary collapse
- #coercing_setter!(name, type, nilify = false) ⇒ Object
- #property(name, options = {}, &block) ⇒ Object
Instance Method Details
#coercing_setter!(name, type, nilify = false) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# 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) ⇒ Object
14 15 16 17 18 |
# File 'lib/disposable/twin/coercion.rb', line 14 def property(name, ={}, &block) super(name, , &block).tap do coercing_setter!(name, [:type], [:nilify]) if [:type] || [:nilify] end end |