Module: Tins::Concern::ModuleMixin

Included in:
Module
Defined in:
lib/tins/xt/concern.rb

Overview

Note:

This implementation relies on Thread.current which makes it

ModuleMixin provides thread-local storage for concern configuration.

This mixin adds methods to any module that includes it, allowing for configuration of concerns through thread-local storage. The configuration is stored in the current thread’s context and persists during the execution of code that uses this concern.

thread-safe but scoped to individual threads.

Instance Method Summary collapse

Instance Method Details

#tins_concern_argsArray?

Retrieves the current concern configuration arguments.

This method fetches the arguments that were previously set using #tins_concern_configure. If no configuration has been set, it returns nil.

Examples:

MyConcern.tins_concern_configure(:option1, :option2)
puts MyConcern.tins_concern_args  # => [:option1, :option2]

Returns:

  • (Array, nil)

    The stored configuration arguments or nil



56
57
58
# File 'lib/tins/xt/concern.rb', line 56

def tins_concern_args
  Thread.current[:tin_concern_args]
end

#tins_concern_configure(*args) ⇒ Module

Configures the module with the given arguments and returns self.

This method stores the provided arguments in thread-local storage, making them available via #tins_concern_args. It’s designed to be chainable (returns self).

Examples:

MyConcern.tins_concern_configure(:option1, :option2)

Parameters:

  • args (Array)

    Arguments to configure this concern with

Returns:

  • (Module)

    The module itself, for chaining



41
42
43
44
# File 'lib/tins/xt/concern.rb', line 41

def tins_concern_configure(*args)
  Thread.current[:tin_concern_args] = args
  self
end