Sha256: d456c3f0447fe01f20b91878824d81016b4d09bdcd34cd1397f36a6c6108eefd

Contents?: true

Size: 1.25 KB

Versions: 14

Compression:

Stored size: 1.25 KB

Contents

# frozen_string_literal: true

require 'eac_ruby_utils/gems_registry'

module EacCli
  class RunnerWithSet
    class << self
      def default
        @default ||= new
      end
    end

    def add_namespace(namespace)
      namespace = sanitize_namespace(namespace)
      namespace_set << namespace unless namespace_set.include?(namespace)
      self
    end

    def add_from_gems_registry
      ::EacRubyUtils::GemsRegistry.new('RunnerWith').registered.each do |registered_gem|
        add_namespace(registered_gem.registered_module)
      end
    end

    def item_to_module(item)
      item.is_a?(::Module) ? item : key_to_module(item)
    end

    def namespaces
      namespace_set.dup
    end

    private

    def namespace_set
      @namespace_set ||= []
    end

    def key_to_module(key)
      namespace_set.lazy
        .map { |namespace| key_to_module_in_namespace(namespace, key) }
        .find(&:present?) ||
        raise("Not module found with key \"#{key}\" (Namespaces: #{namespace_set})")
    end

    def key_to_module_in_namespace(namespace, key)
      namespace.const_get(key.to_s.camelize)
    rescue ::NameError
      nil
    end

    def sanitize_namespace(source)
      source.is_a?(::Module) ? source : source.to_s.constantize
    end
  end
end

Version data entries

14 entries across 14 versions & 2 rubygems

Version Path
eac_cli-0.42.0 lib/eac_cli/runner_with_set.rb
eac_cli-0.40.1 lib/eac_cli/runner_with_set.rb
eac_cli-0.40.0 lib/eac_cli/runner_with_set.rb
eac_cli-0.39.0 lib/eac_cli/runner_with_set.rb
eac_cli-0.38.1 lib/eac_cli/runner_with_set.rb
eac_tools-0.82.0 sub/eac_cli/lib/eac_cli/runner_with_set.rb
eac_tools-0.81.0 sub/eac_cli/lib/eac_cli/runner_with_set.rb
eac_tools-0.80.0 sub/eac_cli/lib/eac_cli/runner_with_set.rb
eac_tools-0.79.0 sub/eac_cli/lib/eac_cli/runner_with_set.rb
eac_tools-0.78.0 sub/eac_cli/lib/eac_cli/runner_with_set.rb
eac_tools-0.77.1 sub/eac_cli/lib/eac_cli/runner_with_set.rb
eac_tools-0.77.0 sub/eac_cli/lib/eac_cli/runner_with_set.rb
eac_cli-0.38.0 lib/eac_cli/runner_with_set.rb
eac_tools-0.76.1 sub/eac_cli/lib/eac_cli/runner_with_set.rb