Class: Servus::Config
- Inherits:
-
Object
- Object
- Servus::Config
- Defined in:
- lib/servus/config.rb
Overview
Instance Attribute Summary collapse
-
#events_dir ⇒ String
The directory where Event classes are located.
-
#guards_dir ⇒ String
The directory where guard classes are located.
-
#include_default_guards ⇒ Boolean
Whether to include the default built-in guards (EnsurePresent, EnsurePositive).
-
#lockdown_enabled ⇒ Boolean
Whether external instantiation of services is blocked and instance ‘#call` methods are automatically privatized.
-
#require_event_payload_schema ⇒ Boolean
Whether to require all event classes to define a payload schema.
-
#require_service_arguments_schema ⇒ Boolean
Whether to require all services to define an arguments schema.
-
#require_service_result_schema ⇒ Boolean
Whether to require all services to define a result schema.
- #routers ⇒ Array<Servus::Events::Router>
-
#schemas_dir ⇒ String
The directory where JSON schema files are located.
-
#services_dir ⇒ String
The directory where services are located.
-
#tests_dir ⇒ String
The directory where generated spec/test files are placed.
Instance Method Summary collapse
-
#initialize ⇒ Config
constructor
private
Initializes a new configuration with default values.
-
#schema_dir_for(service_namespace) ⇒ String
Returns the directory containing a service’s schema files.
-
#schema_path_for(service_namespace, type) ⇒ String
Returns the full path to a service’s schema file.
- #set_default_directories ⇒ Object
Constructor Details
#initialize ⇒ Config
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.
128 129 130 131 132 133 134 135 |
# File 'lib/servus/config.rb', line 128 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 end |
Instance Attribute Details
#events_dir ⇒ String
The directory where Event classes are located.
Defaults to ‘Rails.root/app/events` in Rails applications.
30 31 32 |
# File 'lib/servus/config.rb', line 30 def events_dir @events_dir end |
#guards_dir ⇒ String
The directory where guard classes are located.
Defaults to ‘Rails.root/app/guards` in Rails applications.
44 45 46 |
# File 'lib/servus/config.rb', line 44 def guards_dir @guards_dir end |
#include_default_guards ⇒ Boolean
Whether to include the default built-in guards (EnsurePresent, EnsurePositive).
58 59 60 |
# File 'lib/servus/config.rb', line 58 def include_default_guards @include_default_guards end |
#lockdown_enabled ⇒ Boolean
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.
113 114 115 |
# File 'lib/servus/config.rb', line 113 def lockdown_enabled @lockdown_enabled end |
#require_event_payload_schema ⇒ Boolean
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.
83 84 85 |
# File 'lib/servus/config.rb', line 83 def require_event_payload_schema @require_event_payload_schema end |
#require_service_arguments_schema ⇒ Boolean
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.
66 67 68 |
# File 'lib/servus/config.rb', line 66 def require_service_arguments_schema @require_service_arguments_schema end |
#require_service_result_schema ⇒ Boolean
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.
75 76 77 |
# File 'lib/servus/config.rb', line 75 def require_service_result_schema @require_service_result_schema end |
#routers ⇒ Array<Servus::Events::Router>
95 96 97 |
# File 'lib/servus/config.rb', line 95 def routers @routers || [Servus::Events::ClassRouter.new] end |
#schemas_dir ⇒ String
The directory where JSON schema files are located.
Defaults to ‘Rails.root/app/schemas/services` in Rails applications.
23 24 25 |
# File 'lib/servus/config.rb', line 23 def schemas_dir @schemas_dir end |
#services_dir ⇒ String
The directory where services are located.
Defaults to ‘Rails.root/app/services` in Rails applications.
37 38 39 |
# File 'lib/servus/config.rb', line 37 def services_dir @services_dir end |
#tests_dir ⇒ String
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.
53 54 55 |
# File 'lib/servus/config.rb', line 53 def tests_dir @tests_dir end |
Instance Method Details
#schema_dir_for(service_namespace) ⇒ String
Returns the directory containing a service’s schema files.
166 167 168 |
# File 'lib/servus/config.rb', line 166 def schema_dir_for(service_namespace) File.join(root_path, schemas_dir, service_namespace) end |
#schema_path_for(service_namespace, type) ⇒ String
Returns the full path to a service’s schema file.
154 155 156 |
# File 'lib/servus/config.rb', line 154 def schema_path_for(service_namespace, type) File.join(root_path, schemas_dir, service_namespace, "#{type}.json") end |
#set_default_directories ⇒ Object
137 138 139 140 141 142 143 |
# File 'lib/servus/config.rb', line 137 def set_default_directories @guards_dir = 'app/guards' @events_dir = 'app/events' @schemas_dir = 'app/schemas' @services_dir = 'app/services' @tests_dir = 'spec' end |