Module: Diana::Config

Included in:
Diana
Defined in:
lib/diana/config.rb

Overview

Defines Diana module configuration methods

Instance Method Summary collapse

Instance Method Details

#methods_visibilitySymbol

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the current visibility of dependency methods.

Returns:

  • (Symbol)

    The current visibility of dependency methods.



55
56
57
# File 'lib/diana/config.rb', line 55

def methods_visibility
  @methods_visibility || DEFAULT_METHODS_VISIBILITY
end

#methods_visibility=(visibility) ⇒ Symbol

Sets the visibility of dependency methods.

Examples:

Setting the default visibility of dependency methods to public.

Diana.methods_visibility = :public

Parameters:

  • visibility (Symbol)

    The new visibility for dependency methods (:private, :public, :protected).

Returns:

  • (Symbol)

    The new default visibility for dependency methods.

Raises:

  • (ArgumentError)

    If the visibility is not :private, :public, or :protected.



68
69
70
71
72
73
74
# File 'lib/diana/config.rb', line 68

def methods_visibility=(visibility)
  if (visibility != :private) && (visibility != :public) && (visibility != :protected)
    raise ArgumentError, "methods_visibility value must be :private, :public, or :protected"
  end

  @methods_visibility = visibility
end

#resolve(value) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Resolves a given value using the current resolver.

Parameters:

  • value (Object)

    The value to resolve.

Returns:

  • (Object)

    The resolved value.



47
48
49
# File 'lib/diana/config.rb', line 47

def resolve(value)
  resolver.call(value)
end

#resolver#call

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the current resolver.

Returns:

  • (#call)

    The current resolver.



21
22
23
# File 'lib/diana/config.rb', line 21

def resolver
  @resolver || DEFAULT_RESOLVER
end

#resolver=(new_resolver) ⇒ #call

Sets a new resolver.

Examples:

Setting a resolver that can resolve strings to a DI container.

Diana.resolver = proc do |value|
  case value
  when Proc then value.call
  when String then MyContainer[value].call
  else value
  end
end

Parameters:

  • new_resolver (#call)

    The new resolver to set.

Returns:

  • (#call)

    The new resolver.



38
39
40
# File 'lib/diana/config.rb', line 38

def resolver=(new_resolver)
  @resolver = new_resolver
end