Module: Servus::Guards

Included in:
Base
Defined in:
lib/servus/guards.rb,
lib/servus/guards/state_guard.rb,
lib/servus/guards/falsey_guard.rb,
lib/servus/guards/truthy_guard.rb,
lib/servus/guards/presence_guard.rb

Overview

Module providing guard functionality to Servus services.

Guard methods are defined directly on this module when guard classes inherit from Servus::Guard. The inherited hook triggers method definition, so no registry or method_missing is needed.

Examples:

Using guards in a service

class TransferService < Servus::Base
  def call
    enforce_presence!(user: user, account: )
    enforce_state!(on: , check: :status, is: :active)
    # ... perform transfer ...
    success(result)
  end
end

See Also:

Defined Under Namespace

Classes: FalseyGuard, PresenceGuard, StateGuard, TruthyGuard

Class Method Summary collapse

Class Method Details

.load_defaultsvoid

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Loads default guards if configured.

Called after Guards module is defined to load built-in guards when Servus.config.include_default_guards is true.



35
36
37
38
39
40
41
42
# File 'lib/servus/guards.rb', line 35

def load_defaults
  return unless Servus.config.include_default_guards

  require_relative 'guards/presence_guard'
  require_relative 'guards/truthy_guard'
  require_relative 'guards/falsey_guard'
  require_relative 'guards/state_guard'
end