class Dry::System::Component

Components are objects providing information about auto-registered files. They expose an API to query this information and use a configurable loader object to initialize class instances.

@api public

Constants

DEFAULT_OPTIONS

Attributes

file_path[R]

@!attribute [r] file_path

@return [String, nil] full path to the component's file, if found
identifier[R]

@!attribute [r] identifier

@return [String] component's unique identifier
options[R]

@!attribute [r] options

@return [Hash] component's options

Public Class Methods

new(identifier, options = EMPTY_HASH) click to toggle source

@api private

Calls superclass method
# File lib/dry/system/component.rb, line 41
def self.new(identifier, options = EMPTY_HASH)
  options = DEFAULT_OPTIONS.merge(options)

  namespace = options.delete(:namespace)
  separator = options.delete(:separator)

  identifier =
    if identifier.is_a?(Identifier)
      identifier
    else
      Identifier.new(
        identifier,
        namespace: namespace,
        separator: separator
      )
    end

  super(identifier, **options)
end
new(identifier, file_path: nil, **options) click to toggle source

@api private

# File lib/dry/system/component.rb, line 62
def initialize(identifier, file_path: nil, **options)
  @identifier = identifier
  @file_path = file_path
  @options = options
end

Public Instance Methods

auto_register?() click to toggle source

@api private

# File lib/dry/system/component.rb, line 113
def auto_register?
  callable_option?(options[:auto_register])
end
bootable?() click to toggle source

@api private

# File lib/dry/system/component.rb, line 78
def bootable?
  false
end
file_exists?() click to toggle source

Returns true if the component has a corresponding file

@return [Boolean] @api private

# File lib/dry/system/component.rb, line 98
def file_exists?
  !!file_path
end
inflector() click to toggle source

@api private

# File lib/dry/system/component.rb, line 108
def inflector
  options[:inflector]
end
instance(*args) click to toggle source

Returns the component's instance

@return [Object] component's class instance @api public

# File lib/dry/system/component.rb, line 72
def instance(*args)
  loader.call(self, *args)
end
key() click to toggle source
# File lib/dry/system/component.rb, line 82
def key
  identifier.to_s
end
loader() click to toggle source

@api private

# File lib/dry/system/component.rb, line 103
def loader
  options[:loader]
end
memoize?() click to toggle source

@api private

# File lib/dry/system/component.rb, line 118
def memoize?
  callable_option?(options[:memoize])
end
path() click to toggle source
# File lib/dry/system/component.rb, line 86
def path
  identifier.path
end
root_key() click to toggle source
# File lib/dry/system/component.rb, line 90
def root_key
  identifier.root_key
end

Private Instance Methods

callable_option?(value) click to toggle source
# File lib/dry/system/component.rb, line 124
def callable_option?(value)
  if value.respond_to?(:call)
    !!value.call(self)
  else
    !!value
  end
end