Sha256: 366fe257c691254a4f34f88265831900644b00773d5bdf73e3b19647e0cb0fca

Contents?: true

Size: 757 Bytes

Versions: 12

Compression:

Stored size: 757 Bytes

Contents

require 'dry-container'

module Coprl
  module ContainerMethods
    include Coprl::Symbol::ToStr

    def registered_keys
      @registered_keys ||= []
    end

    def registered?(presenter)
      container.key?(sym_to_str(presenter))
    end

    def [](name)
      resolve(name)
    end

    def resolve(name)
      container.resolve(sym_to_str(name))
    end

    def list
      container.keys
    end
    alias keys list

    def container
      @container ||= Dry::Container.new
    end

    # This method empties out the container
    # It should ONLY be used for testing purposes
    def reset!
      registered_keys.each { |key| ClassConstants.new(key).deconstantize }
      @registered_keys = []
      container._container.clear
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
coprl-3.0.0.beta.12 lib/coprl/container_methods.rb
coprl-3.0.0.beta.11 lib/coprl/container_methods.rb
coprl-3.0.0.beta.10 lib/coprl/container_methods.rb
coprl-3.0.0.beta.9 lib/coprl/container_methods.rb
coprl-3.0.0.beta.8 lib/coprl/container_methods.rb
coprl-3.0.0.beta.7 lib/coprl/container_methods.rb
coprl-3.0.0.beta.6 lib/coprl/container_methods.rb
coprl-3.0.0.beta.5 lib/coprl/container_methods.rb
coprl-3.0.0.beta.4 lib/coprl/container_methods.rb
coprl-3.0.0.beta.3 lib/coprl/container_methods.rb
coprl-3.0.0.beta.2 lib/coprl/container_methods.rb
coprl-3.0.0.beta.1 lib/coprl/container_methods.rb