Sha256: bb744bac89de08981ee055c0e639d206f4c725e3a4a10179aeb9558ef5563468
Contents?: true
Size: 1000 Bytes
Versions: 1
Compression:
Stored size: 1000 Bytes
Contents
# frozen_string_literal: true module FlexValidations # @abstract Validation should define {#validate} and {#to_s} methods module Validation # @abstract Do validation of value # # @param value [Object] Value to be validated # # @return [FlexValidations::Result] # # @example # odd.validate(1).success? #=> true # # @example # odd.validate(2).fail? #=> true def validate(value) raise 'not implemented' end # @abstract Returns description of validation # # @return [String] def to_s raise 'not implemented' end # @param [Object] Value to match # # @return [Boolean] # # @example # case 1 # when odd # puts "its odd number" # end def ===(value) validate(value).success? || super end # @return [Proc] # # @example # [1, 2, 3].select(&odd) #=> [1, 3] def to_proc proc { |value| validate(value).success? } end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
flex_validations-0.1.0 | lib/flex_validations/validation.rb |