Sha256: 7fb89fd4824eec7d36c7d5a7ce70075d8859363715060c513fe2128630d60483

Contents?: true

Size: 912 Bytes

Versions: 1

Compression:

Stored size: 912 Bytes

Contents

# frozen_string_literal: true

module BCDD::Contracts
  HasSize = ->(min, max) { ->(val) { val.size.between?(min, max) or "must be >= #{min} and <= #{max} chars" } }

  is_str = contract[::String]
  is_email = ->(val) { val.match?(::URI::MailTo::EMAIL_REGEXP) or '%p must be an email' }
  is_present = ->(val) { val.present? or '%p must be present' }
  is_persisted = ->(val) { val.persisted? or '%p must be persisted' }

  register(
    is_str: is_str,
    is_email: is_str & is_present& is_email,
    is_present: is_present,
    is_password: is_str & is_present & HasSize[8, 72],
    is_persisted: is_persisted
  )

  EmptyHash = contract[::Hash] & ->(value) { value.empty? }
  ErrorMessages = contract[errors: [::String]]
  ErrorsByAttribute = contract.pairs(::Symbol => [::String])

  register(
    empty_hash: EmptyHash,
    error_messages: ErrorMessages,
    errors_by_attribute: ErrorsByAttribute
  )
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
bcdd-process-0.4.0 examples/business_processes/lib/bcdd/contracts.rb