Class: Railsmith::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/railsmith/configuration.rb

Overview

Stores global settings used by gem components.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



14
15
16
17
18
19
20
# File 'lib/railsmith/configuration.rb', line 14

def initialize
  set_default_flags
  set_default_hook_state
  set_default_async_config
  set_default_instrumentation
  set_default_pipeline_options
end

Instance Attribute Details

#async_enqueuerObject

Returns the value of attribute async_enqueuer.



6
7
8
# File 'lib/railsmith/configuration.rb', line 6

def async_enqueuer
  @async_enqueuer
end

#async_job_classObject

Returns the value of attribute async_job_class.



6
7
8
# File 'lib/railsmith/configuration.rb', line 6

def async_job_class
  @async_job_class
end

#cross_domain_allowlistObject

Returns the value of attribute cross_domain_allowlist.



6
7
8
# File 'lib/railsmith/configuration.rb', line 6

def cross_domain_allowlist
  @cross_domain_allowlist
end

#custom_coercionsObject (readonly)

Returns the hash of custom coercions (keyed by type Class or Symbol).



41
42
43
# File 'lib/railsmith/configuration.rb', line 41

def custom_coercions
  @custom_coercions
end

#fail_on_arch_violationsObject

Returns the value of attribute fail_on_arch_violations.



6
7
8
# File 'lib/railsmith/configuration.rb', line 6

def fail_on_arch_violations
  @fail_on_arch_violations
end

#instrumentation_enabledObject

Returns the value of attribute instrumentation_enabled.



6
7
8
# File 'lib/railsmith/configuration.rb', line 6

def instrumentation_enabled
  @instrumentation_enabled
end

#on_cross_domain_violationObject

Returns the value of attribute on_cross_domain_violation.



6
7
8
# File 'lib/railsmith/configuration.rb', line 6

def on_cross_domain_violation
  @on_cross_domain_violation
end

#pipeline_detect_merge_collisionsObject

Returns the value of attribute pipeline_detect_merge_collisions.



6
7
8
# File 'lib/railsmith/configuration.rb', line 6

def pipeline_detect_merge_collisions
  @pipeline_detect_merge_collisions
end

#strict_modeObject

Returns the value of attribute strict_mode.



6
7
8
# File 'lib/railsmith/configuration.rb', line 6

def strict_mode
  @strict_mode
end

#warn_on_cross_domain_callsObject

Returns the value of attribute warn_on_cross_domain_calls.



6
7
8
# File 'lib/railsmith/configuration.rb', line 6

def warn_on_cross_domain_calls
  @warn_on_cross_domain_calls
end

Instance Method Details

#after_action(*actions, **options) ⇒ Object



77
78
79
# File 'lib/railsmith/configuration.rb', line 77

def after_action(*actions, **options, &)
  add_global_hook(:after, actions, options, &)
end

#around_action(*actions, **options) ⇒ Object



81
82
83
# File 'lib/railsmith/configuration.rb', line 81

def around_action(*actions, **options, &)
  add_global_hook(:around, actions, options, &)
end

#before_action(*actions, **options) ⇒ Object



73
74
75
# File 'lib/railsmith/configuration.rb', line 73

def before_action(*actions, **options, &)
  add_global_hook(:before, actions, options, &)
end

#default_async_job_classObject



22
23
24
25
26
# File 'lib/railsmith/configuration.rb', line 22

def default_async_job_class
  return nil unless defined?(Railsmith::AsyncNestedWriteJob)

  Railsmith::AsyncNestedWriteJob
end

#global_hooksObject

The live HookRegistry holding every globally declared hook. Tests can reset it via reset_global_hooks! between examples.



64
65
66
# File 'lib/railsmith/configuration.rb', line 64

def global_hooks
  @global_hooks ||= Railsmith::Hooks::HookRegistry.new
end

#register_coercion(type, coercer) ⇒ Object

Register a custom type coercion used by the input DSL.

Railsmith.configure do |c|
  c.register_coercion(:money, ->(v) { Money.new(v) })
end

Parameters:

  • type (Class, Symbol)

    the type key passed to ‘input :field, <type>`

  • coercer (#call)

    callable that receives the raw value and returns the coerced value



36
37
38
# File 'lib/railsmith/configuration.rb', line 36

def register_coercion(type, coercer)
  @custom_coercions[type] = coercer
end

#reset_global_hooks!Object

Clear every global hook. Primarily useful in test teardown.



69
70
71
# File 'lib/railsmith/configuration.rb', line 69

def reset_global_hooks!
  @global_hooks = nil
end