Sha256: 9846e5d4b3888d54fe3ea28c878fa48e5792ef2f1a50b4d081be771a1266b57b

Contents?: true

Size: 692 Bytes

Versions: 5

Compression:

Stored size: 692 Bytes

Contents

module Alf
  module Tools

    # Defines all coercion rules, through Myrrha inheritance
    Coercions = Myrrha::Coerce.dup.append do
    end

    # Coerces a value to a particular domain.
    #
    # Example:
    #
    #   Tools.coerce("123", Integer) # => 123
    #
    # @param [Object] val any value
    # @param [Class] domain a domain, represented by a ruby class
    # @return [Object] an instance of `domain` resulting from the coercion
    # @raise [Myrrha::CoercionError] if something goes wrong
    def coerce(val, domain)
      Coercions.apply(val, domain)
    rescue Myrrha::Error => ex
      raise CoercionError, ex.message, caller
    end

  end # module Tools
end # module Alf

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
alf-0.12.2 lib/alf/tools/coerce.rb
alf-0.12.1 lib/alf/tools/coerce.rb
alf-0.12.0 lib/alf/tools/coerce.rb
alf-0.11.1 lib/alf/tools/coerce.rb
alf-0.11.0 lib/alf/tools/coerce.rb