Class: Operandi::Config
- Inherits:
-
Object
- Object
- Operandi::Config
- Defined in:
- lib/operandi/config.rb
Overview
Configuration class for Operandi global settings.
Constant Summary collapse
- DEFAULTS =
{ require_arg_type: true, require_output_type: true, use_transactions: true, load_errors: true, break_on_error: true, raise_on_error: false, rollback_on_error: true, load_warnings: true, break_on_warning: false, raise_on_warning: false, rollback_on_warning: false, ruby_lsp_type_mappings: {}.freeze, }.freeze
Instance Attribute Summary collapse
-
#break_on_error ⇒ Boolean
readonly
Whether to stop executing steps when an error is added.
-
#break_on_warning ⇒ Boolean
readonly
Whether to stop executing steps when a warning is added.
-
#load_errors ⇒ Boolean
readonly
Whether to copy errors to parent service in chain.
-
#load_warnings ⇒ Boolean
readonly
Whether to copy warnings to parent service in chain.
-
#raise_on_error ⇒ Boolean
readonly
Whether to raise Operandi::RuntimeError when service fails.
-
#raise_on_warning ⇒ Boolean
readonly
Whether to raise Operandi::RuntimeError when service has warnings.
-
#require_arg_type ⇒ Boolean
readonly
Whether arguments must have a type specified.
-
#require_output_type ⇒ Boolean
readonly
Whether outputs must have a type specified.
-
#rollback_on_error ⇒ Boolean
readonly
Whether to rollback the transaction when an error is added.
-
#rollback_on_warning ⇒ Boolean
readonly
Whether to rollback the transaction when a warning is added.
-
#ruby_lsp_type_mappings ⇒ Hash{String => String}
readonly
Custom type mappings for Ruby LSP addon.
-
#use_transactions ⇒ Boolean
readonly
Whether to wrap service execution in a database transaction.
Instance Method Summary collapse
-
#initialize ⇒ Config
constructor
Initialize configuration with default values.
-
#merge(config) ⇒ Hash
Merge configuration with additional options.
-
#require_type=(value) ⇒ void
Convenience setter for backward compatibility.
-
#reset_to_defaults! ⇒ void
Reset all configuration options to their default values.
-
#to_h ⇒ Hash{Symbol => Object}
Convert configuration to a hash.
Constructor Details
#initialize ⇒ Config
Initialize configuration with default values.
110 111 112 |
# File 'lib/operandi/config.rb', line 110 def initialize reset_to_defaults! end |
Instance Attribute Details
#break_on_error ⇒ Boolean (readonly)
Returns whether to stop executing steps when an error is added.
49 50 51 |
# File 'lib/operandi/config.rb', line 49 def break_on_error @break_on_error end |
#break_on_warning ⇒ Boolean (readonly)
Returns whether to stop executing steps when a warning is added.
61 62 63 |
# File 'lib/operandi/config.rb', line 61 def break_on_warning @break_on_warning end |
#load_errors ⇒ Boolean (readonly)
Returns whether to copy errors to parent service in chain.
46 47 48 |
# File 'lib/operandi/config.rb', line 46 def load_errors @load_errors end |
#load_warnings ⇒ Boolean (readonly)
Returns whether to copy warnings to parent service in chain.
58 59 60 |
# File 'lib/operandi/config.rb', line 58 def load_warnings @load_warnings end |
#raise_on_error ⇒ Boolean (readonly)
Returns whether to raise Operandi::RuntimeError when service fails.
52 53 54 |
# File 'lib/operandi/config.rb', line 52 def raise_on_error @raise_on_error end |
#raise_on_warning ⇒ Boolean (readonly)
Returns whether to raise Operandi::RuntimeError when service has warnings.
64 65 66 |
# File 'lib/operandi/config.rb', line 64 def raise_on_warning @raise_on_warning end |
#require_arg_type ⇒ Boolean (readonly)
Returns whether arguments must have a type specified.
37 38 39 |
# File 'lib/operandi/config.rb', line 37 def require_arg_type @require_arg_type end |
#require_output_type ⇒ Boolean (readonly)
Returns whether outputs must have a type specified.
40 41 42 |
# File 'lib/operandi/config.rb', line 40 def require_output_type @require_output_type end |
#rollback_on_error ⇒ Boolean (readonly)
Returns whether to rollback the transaction when an error is added.
55 56 57 |
# File 'lib/operandi/config.rb', line 55 def rollback_on_error @rollback_on_error end |
#rollback_on_warning ⇒ Boolean (readonly)
Returns whether to rollback the transaction when a warning is added.
67 68 69 |
# File 'lib/operandi/config.rb', line 67 def rollback_on_warning @rollback_on_warning end |
#ruby_lsp_type_mappings ⇒ Hash{String => String} (readonly)
Returns custom type mappings for Ruby LSP addon. Maps custom types to Ruby types for hover/completion. @example { "CustomTypes::UUID" => "String", "CustomTypes::Money" => "BigDecimal" }.
72 73 74 |
# File 'lib/operandi/config.rb', line 72 def ruby_lsp_type_mappings @ruby_lsp_type_mappings end |
#use_transactions ⇒ Boolean (readonly)
Returns whether to wrap service execution in a database transaction.
43 44 45 |
# File 'lib/operandi/config.rb', line 43 def use_transactions @use_transactions end |
Instance Method Details
#merge(config) ⇒ Hash
Merge configuration with additional options.
138 139 140 |
# File 'lib/operandi/config.rb', line 138 def merge(config) to_h.merge(config) end |
#require_type=(value) ⇒ void
This method returns an undefined value.
Convenience setter for backward compatibility. Sets both require_arg_type and require_output_type.
104 105 106 107 |
# File 'lib/operandi/config.rb', line 104 def require_type=(value) self.require_arg_type = value self.require_output_type = value end |
#reset_to_defaults! ⇒ void
This method returns an undefined value.
Reset all configuration options to their default values.
117 118 119 120 121 122 123 |
# File 'lib/operandi/config.rb', line 117 def reset_to_defaults! DEFAULTS.each do |key, value| instance_variable_set(:"@#{key}", value) end @to_h = nil # Invalidate memoized hash end |
#to_h ⇒ Hash{Symbol => Object}
Convert configuration to a hash.
128 129 130 131 132 |
# File 'lib/operandi/config.rb', line 128 def to_h @to_h ||= DEFAULTS.keys.to_h do |key| [key, public_send(key)] end end |