examples/business_processes/lib/bcdd/contracts.rb in bcdd-process-0.2.0 vs examples/business_processes/lib/bcdd/contracts.rb in bcdd-process-0.3.0
- old
+ new
@@ -1,29 +1,29 @@
# 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 = ::BCDD::Contract[::String]
+ is_str = contract[::String]
is_uuid = ->(val) { val.match?(/\A[0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12}\z/) or '%p must be an UUID' }
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' }
- ::BCDD::Contract.register(
+ register(
is_str: is_str,
is_uuid: is_str & is_present & is_uuid,
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 = ::BCDD::Contract[::Hash] & ->(value) { value.empty? }
- ErrorMessages = ::BCDD::Contract[errors: [::String]]
- ErrorsByAttribute = ::BCDD::Contract.pairs(::Symbol => [::String])
+ EmptyHash = contract[::Hash] & ->(value) { value.empty? }
+ ErrorMessages = contract[errors: [::String]]
+ ErrorsByAttribute = contract.pairs(::Symbol => [::String])
- ::BCDD::Contract.register(
+ register(
empty_hash: EmptyHash,
error_messages: ErrorMessages,
errors_by_attribute: ErrorsByAttribute
)
end