Sha256: 694c4d2e5c65a7d8332b5c1d862d46a282ab50f2fb0a1f3d03367ea69ad985ae

Contents?: true

Size: 1.15 KB

Versions: 2

Compression:

Stored size: 1.15 KB

Contents

require "active_support/core_ext/object/inclusion"
module Uses
  class Config
    # Configure what should happen when a circular dependency is detected.
    #
    # :warn:: Emit a warning, but allow it (default)
    # :raise_error:: Raise an exception, effectively making your app unusable until
    #                you resolve the circular dependencies
    # :ignore:: Emit a warning at DEBUG level, effectively allowing you to ignore these issues.
    attr_reader :on_circular_dependency

    # The array of custom initializers.  Generally you should use
    # `Uses.initializers do |initializers|` to manipulate this
    attr_reader :initializers

    def initialize
      reset!
    end

    def reset!
      self.on_circular_dependency = :warn
      @initializers = {}
    end

    ON_CIRCULAR_DEPENDENCY_VALUES = [
      :ignore,
      :raise_error,
      :warn,
    ]
    def on_circular_dependency=(new_value)
      if !new_value.in?(ON_CIRCULAR_DEPENDENCY_VALUES)
        raise ArgumentError, "#{new_value} is not a valid value for on_circular_dependency. Use one of #{ON_CIRCULAR_DEPENDENCY_VALUES}"
      end
      @on_circular_dependency = new_value
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
uses-1.0.0 lib/uses/config.rb
uses-1.0.0.pre.beta1 lib/uses/config.rb