Sha256: dcb290ca3e572418d417b8a4ae673382425ac6c012cd84aa39b20e638c2cc81c

Contents?: true

Size: 1.26 KB

Versions: 49

Compression:

Stored size: 1.26 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 ||= ::Array.new
    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

49 entries across 49 versions & 2 rubygems

Version Path
eac_tools-0.76.0 sub/eac_cli/lib/eac_cli/runner_with_set.rb
eac_tools-0.75.2 sub/eac_cli/lib/eac_cli/runner_with_set.rb
eac_cli-0.37.0 lib/eac_cli/runner_with_set.rb
eac_tools-0.75.1 sub/eac_cli/lib/eac_cli/runner_with_set.rb
eac_tools-0.75.0 sub/eac_cli/lib/eac_cli/runner_with_set.rb
eac_tools-0.74.1 sub/eac_cli/lib/eac_cli/runner_with_set.rb
eac_tools-0.74.0 sub/eac_cli/lib/eac_cli/runner_with_set.rb
eac_cli-0.36.0 lib/eac_cli/runner_with_set.rb
eac_tools-0.73.0 sub/eac_cli/lib/eac_cli/runner_with_set.rb
eac_tools-0.72.0 sub/eac_cli/lib/eac_cli/runner_with_set.rb
eac_tools-0.70.1 sub/eac_cli/lib/eac_cli/runner_with_set.rb
eac_tools-0.70.0 sub/eac_cli/lib/eac_cli/runner_with_set.rb
eac_tools-0.69.1 sub/eac_cli/lib/eac_cli/runner_with_set.rb
eac_tools-0.69.0 sub/eac_cli/lib/eac_cli/runner_with_set.rb
eac_cli-0.35.1 lib/eac_cli/runner_with_set.rb
eac_cli-0.34.1 lib/eac_cli/runner_with_set.rb
eac_tools-0.68.0 sub/eac_cli/lib/eac_cli/runner_with_set.rb
eac_tools-0.67.1 sub/eac_cli/lib/eac_cli/runner_with_set.rb
eac_cli-0.35.0 lib/eac_cli/runner_with_set.rb
eac_tools-0.67.0 sub/eac_cli/lib/eac_cli/runner_with_set.rb