Module: Philiprehberger::GuardClause

Defined in:
lib/philiprehberger/guard_clause.rb,
lib/philiprehberger/guard_clause/guard.rb,
lib/philiprehberger/guard_clause/version.rb

Defined Under Namespace

Classes: Error, Guard

Constant Summary collapse

UUID_PATTERN =
/\A[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}\z/i
EMAIL_PATTERN =
/\A[^@\s]+@[^@\s]+\.[^@\s]+\z/
BUILT_IN_PATTERNS =
{
  uuid: UUID_PATTERN,
  email: EMAIL_PATTERN
}.freeze
VERSION =
'0.3.0'

Class Method Summary collapse

Class Method Details

.guard(value, soft: false) ⇒ Guard

Create a guard for the given value

Parameters:

  • value (Object)

    the value to guard

  • soft (Boolean) (defaults to: false)

    when true, collect errors instead of raising

Returns:

  • (Guard)

    the guard object



15
16
17
# File 'lib/philiprehberger/guard_clause.rb', line 15

def self.guard(value, soft: false)
  Guard.new(value, soft: soft)
end