Class: Servus::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/servus/config.rb

Overview

Configuration settings for the Servus gem.

Manages global configuration options for services, events, guards, and logging. Access the configuration via config or modify via configure.

Examples:

Configuring Servus

Servus.configure do |config|
  config.require_service_arguments_schema = true
end

See Also:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

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.

Initializes a new configuration with default values.



155
156
157
158
159
160
161
162
163
# File 'lib/servus/config.rb', line 155

def initialize
  set_default_directories
  @include_default_guards           = true
  @lockdown_enabled                 = true
  @require_service_arguments_schema = false
  @require_service_result_schema    = false
  @require_event_payload_schema     = false
  @log_filter_parameters            = [].freeze
end

Instance Attribute Details

#events_dirString

The directory where Event classes are located.

Defaults to Rails.root/app/events in Rails applications.

Returns:

  • (String)

    the events directory path



24
25
26
# File 'lib/servus/config.rb', line 24

def events_dir
  @events_dir
end

#guards_dirString

The directory where guard classes are located.

Defaults to Rails.root/app/guards in Rails applications.

Returns:

  • (String)

    the guards directory path



38
39
40
# File 'lib/servus/config.rb', line 38

def guards_dir
  @guards_dir
end

#include_default_guardsBoolean

Whether to include the default built-in guards (EnsurePresent, EnsurePositive).

Returns:

  • (Boolean)

    true to include default guards, false to exclude them



52
53
54
# File 'lib/servus/config.rb', line 52

def include_default_guards
  @include_default_guards
end

#lockdown_enabledBoolean

Whether external instantiation of services is blocked and instance #call methods are automatically privatized.

When enabled (default), callers must invoke services via the class method Base.call, which runs argument validation, logging, benchmarking, guards, result validation, and event emission. Calling MyService.new or instance.call directly raises NoMethodError.

Disable this if you have existing code that instantiates services directly or otherwise prefer to opt out of the enforcement.

Returns:

  • (Boolean)

    true to enforce lockdown (default), false to allow direct instantiation and public instance #call

See Also:



107
108
109
# File 'lib/servus/config.rb', line 107

def lockdown_enabled
  @lockdown_enabled
end

#log_filter_parametersArray

Keys whose values are filtered from Servus's service-call argument logging, shown as [FILTERED]. Accepts the same notations as ActiveSupport::ParameterFilter (partial-match strings/symbols, regexps, procs).

Defaults to [] — no filtering. Set the keys you want masked in your initializer; Rails users can simply reuse their app's request-log filtering as the value:

config.log_filter_parameters = Rails.application.config.filter_parameters

Returns:

  • (Array)

    parameter filter patterns



121
122
123
# File 'lib/servus/config.rb', line 121

def log_filter_parameters
  @log_filter_parameters
end

#require_event_payload_schemaBoolean

Whether to require all event classes to define a payload schema.

When enabled, raises Support::Errors::SchemaRequiredError when an event validates a payload without a payload schema defined.

Returns:

  • (Boolean)

    true to require payload schemas, false to allow schema-less events



77
78
79
# File 'lib/servus/config.rb', line 77

def require_event_payload_schema
  @require_event_payload_schema
end

#require_service_arguments_schemaBoolean

Whether to require all services to define an arguments schema.

When enabled, raises Support::Errors::SchemaRequiredError when a service is called without an arguments schema defined.

Returns:

  • (Boolean)

    true to require arguments schemas, false to allow schema-less services



60
61
62
# File 'lib/servus/config.rb', line 60

def require_service_arguments_schema
  @require_service_arguments_schema
end

#require_service_result_schemaBoolean

Whether to require all services to define a result schema.

When enabled, raises Support::Errors::SchemaRequiredError when a service returns a successful response without a result schema defined. Failure schemas remain optional regardless of this setting.

Returns:

  • (Boolean)

    true to require result schemas, false to allow schema-less services



69
70
71
# File 'lib/servus/config.rb', line 69

def require_service_result_schema
  @require_service_result_schema
end

#routersArray<Servus::Events::Router>

Returns:



89
90
91
# File 'lib/servus/config.rb', line 89

def routers
  @routers || [Servus::Events::ClassRouter.new]
end

#services_dirString

The directory where services are located.

Defaults to Rails.root/app/services in Rails applications.

Returns:

  • (String)

    the services directory path



31
32
33
# File 'lib/servus/config.rb', line 31

def services_dir
  @services_dir
end

#tests_dirString

The directory where generated spec/test files are placed.

Defaults to "spec". Projects using Minitest or a custom test layout can override this (e.g., "test") so generators write files into the correct location.

Returns:

  • (String)

    the tests directory path



47
48
49
# File 'lib/servus/config.rb', line 47

def tests_dir
  @tests_dir
end

Instance Method Details

#parameter_filterActiveSupport::ParameterFilter

Parameter filter built from #log_filter_parameters, memoized until the list is reassigned.

Returns:

  • (ActiveSupport::ParameterFilter)


138
139
140
# File 'lib/servus/config.rb', line 138

def parameter_filter
  @parameter_filter ||= ActiveSupport::ParameterFilter.new(log_filter_parameters)
end

#set_default_directoriesObject



165
166
167
168
169
170
# File 'lib/servus/config.rb', line 165

def set_default_directories
  @guards_dir   = 'app/guards'
  @events_dir   = 'app/events'
  @services_dir = 'app/services'
  @tests_dir    = 'spec'
end