Class: Operandi::Config

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

Overview

Configuration class for Operandi global settings.

Examples:

Accessing configuration

Operandi.config.require_arg_type # => true

Modifying configuration

Operandi.config.use_transactions = false

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

Instance Method Summary collapse

Constructor Details

#initializeConfig

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_errorBoolean (readonly)

Returns whether to stop executing steps when an error is added.

Returns:

  • (Boolean)

    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_warningBoolean (readonly)

Returns whether to stop executing steps when a warning is added.

Returns:

  • (Boolean)

    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_errorsBoolean (readonly)

Returns whether to copy errors to parent service in chain.

Returns:

  • (Boolean)

    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_warningsBoolean (readonly)

Returns whether to copy warnings to parent service in chain.

Returns:

  • (Boolean)

    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_errorBoolean (readonly)

Returns whether to raise Operandi::RuntimeError when service fails.

Returns:

  • (Boolean)

    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_warningBoolean (readonly)

Returns whether to raise Operandi::RuntimeError when service has warnings.

Returns:

  • (Boolean)

    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_typeBoolean (readonly)

Returns whether arguments must have a type specified.

Returns:

  • (Boolean)

    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_typeBoolean (readonly)

Returns whether outputs must have a type specified.

Returns:

  • (Boolean)

    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_errorBoolean (readonly)

Returns whether to rollback the transaction when an error is added.

Returns:

  • (Boolean)

    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_warningBoolean (readonly)

Returns whether to rollback the transaction when a warning is added.

Returns:

  • (Boolean)

    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_mappingsHash{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" }.

Returns:

  • (Hash{String => String})

    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_transactionsBoolean (readonly)

Returns whether to wrap service execution in a database transaction.

Returns:

  • (Boolean)

    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.

Parameters:

  • config (Hash)

    options to merge

Returns:

  • (Hash)

    merged configuration hash



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.

Parameters:

  • value (Boolean)

    whether to require types for arguments and outputs



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_hHash{Symbol => Object}

Convert configuration to a hash.

Returns:

  • (Hash{Symbol => Object})

    all configuration options as 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