Sha256: fc46b6af1657e280873c453cd96e6eca9969097677a96b32309a09f373049354

Contents?: true

Size: 1.01 KB

Versions: 212

Compression:

Stored size: 1.01 KB

Contents

# frozen_string_literal: true

require 'avm/registry/from_gems'
require 'eac_ruby_utils/core_ext'

module Avm
  module Registry
    class WithPath < ::Avm::Registry::FromGems
      require_sub __FILE__

      # @return [Object, nil]
      def class_detect(klass, detect_args)
        r = klass.new(*detect_args)
        r.valid? ? r : nil
      end

      def detect_by_path(path)
        detect_by_path_optional(path) || raise_not_found(path)
      end

      def detect_by_path_optional(path)
        on_cache do
          cache.detect_optional(path)
        end
      end

      private

      attr_accessor :cache

      def on_cache(&block)
        cache.present? ? on_cache_with_cache(&block) : on_cache_with_no_cache(&block)
      end

      def on_cache_with_cache(&block)
        block.call
      end

      def on_cache_with_no_cache(&block)
        self.cache = ::Avm::Registry::WithPath::Cache.new(self)
        begin
          block.call
        ensure
          self.cache = nil
        end
      end
    end
  end
end

Version data entries

212 entries across 212 versions & 2 rubygems

Version Path
avm-0.94.1 lib/avm/registry/with_path.rb
eac_tools-0.98.0 sub/avm/lib/avm/registry/with_path.rb
avm-0.94.0 lib/avm/registry/with_path.rb
eac_tools-0.94.0 sub/avm/lib/avm/registry/with_path.rb
avm-0.93.0 lib/avm/registry/with_path.rb
eac_tools-0.92.0 sub/avm/lib/avm/registry/with_path.rb
avm-0.92.0 lib/avm/registry/with_path.rb
eac_tools-0.91.0 sub/avm/lib/avm/registry/with_path.rb
avm-0.90.1 lib/avm/registry/with_path.rb
eac_tools-0.87.1 sub/avm/lib/avm/registry/with_path.rb
avm-0.90.0 lib/avm/registry/with_path.rb
eac_tools-0.87.0 sub/avm/lib/avm/registry/with_path.rb
avm-0.89.0 lib/avm/registry/with_path.rb
eac_tools-0.86.12 sub/avm/lib/avm/registry/with_path.rb
avm-0.88.0 lib/avm/registry/with_path.rb
eac_tools-0.86.11 sub/avm/lib/avm/registry/with_path.rb
avm-0.87.0 lib/avm/registry/with_path.rb
eac_tools-0.86.8 sub/avm/lib/avm/registry/with_path.rb
avm-0.86.2 lib/avm/registry/with_path.rb
eac_tools-0.86.7 sub/avm/lib/avm/registry/with_path.rb