Module: Axn::Mountable::InheritProfiles

Defined in:
lib/axn/mountable/inherit_profiles.rb

Constant Summary collapse

PROFILES =

Predefined inheritance profiles for mounting strategies

{
  # Inherits parent's lifecycle (hooks, callbacks, messages, async) but not fields
  # Use this when the mounted action should participate in the parent's execution lifecycle
  # but have its own independent contract
  # NOTE: Strategies cannot be controlled - they're mixed in via `include` and become part of the ancestry
  lifecycle: {
    fields: false,
    messages: true,
    hooks: true,
    callbacks: true,
    async: true,
  }.freeze,

  # Only inherits async config - for utility methods like enqueue_all
  # Use this when you need async capability but nothing else from the parent
  async_only: {
    fields: false,
    messages: false,
    hooks: false,
    callbacks: false,
    async: true,
  }.freeze,

  # Inherits nothing - completely standalone
  # Use this when the mounted action should be completely independent from the parent
  none: {
    fields: false,
    messages: false,
    hooks: false,
    callbacks: false,
    async: false,
  }.freeze,
}.freeze

Class Method Summary collapse

Class Method Details

.inherit?(inherit, feature) ⇒ Boolean

Check if a specific feature should be inherited

Parameters:

  • inherit (Symbol, Hash)

    The inherit configuration

  • feature (Symbol)

    The feature to check (e.g., :hooks, :async)

Returns:

  • (Boolean)


66
67
68
69
# File 'lib/axn/mountable/inherit_profiles.rb', line 66

def self.inherit?(inherit, feature)
  resolved = resolve(inherit)
  resolved.fetch(feature)
end

.resolve(inherit) ⇒ Hash

Resolve an inherit configuration to a full hash

Parameters:

  • inherit (Symbol, Hash)

    The inherit configuration

Returns:

  • (Hash)

    A hash with all inheritance options set to true/false



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/axn/mountable/inherit_profiles.rb', line 44

def self.resolve(inherit)
  case inherit
  when Symbol
    PROFILES.fetch(inherit) do
      raise ArgumentError, "Unknown inherit profile: #{inherit.inspect}. Valid profiles: #{PROFILES.keys.join(', ')}"
    end
  when Hash
    # Validate hash keys
    invalid_keys = inherit.keys - PROFILES[:none].keys
    raise ArgumentError, "Invalid inherit keys: #{invalid_keys.join(', ')}. Valid keys: #{PROFILES[:none].keys.join(', ')}" if invalid_keys.any?

    # Merge with none profile to ensure all keys are present
    PROFILES[:none].merge(inherit)
  else
    raise ArgumentError, "inherit must be a Symbol or Hash. Got: #{inherit.class}"
  end
end