Sha256: d2bdaee2f01483cf7cf4146840ee6026ade2e7003d537c22a18e959c30ce1219

Contents?: true

Size: 1.8 KB

Versions: 117

Compression:

Stored size: 1.8 KB

Contents

# frozen_string_literal: true

require 'avm/sources/base/subs_paths'
require 'eac_ruby_utils/core_ext'

module Avm
  module Sources
    class Base
      module Subs
        CONFIGURATION_SUBS_EXCLUDE_PATHS_KEY = 'subs.exclude_path'
        CONFIGURATION_SUBS_INCLUDE_PATHS_KEY = 'subs.include_path'
        SUBS_EXCLUDE_PATHS_DEFAULT = [].freeze
        SUBS_INCLUDE_PATHS_DEFAULT = ['sub/*'].freeze

        # @return [Enumerable<Avm::Sources::Base>]
        def subs
          subs_paths_to_search
            .map { |sub_path| ::Avm::Registry.sources.detect_optional(sub_path, parent: self) }
            .reject(&:blank?)
            .sort_by { |sub| [sub.path] }
        end

        def subs_paths_to_search
          subs_include_paths.flat_map do |subs_include_path|
            ::Pathname.glob(path.join(subs_include_path)).reject do |sub_path|
              subs_exclude_paths.any? do |subs_exclude_path|
                sub_path.fnmatch?(path.join(subs_exclude_path).to_path)
              end
            end
          end
        end

        %i[include exclude].each do |type|
          %i[path paths configured_paths default_paths].each do |method_suffix|
            obj_method_name = "subs_#{type}_path_obj"

            define_method "subs_#{type}_#{method_suffix}" do
              send(obj_method_name).send(method_suffix)
            end

            define_method "#{obj_method_name}_uncached" do
              ::Avm::Sources::Base::SubsPaths.new(
                self,
                self.class.const_get("CONFIGURATION_SUBS_#{type}_PATHS_KEY".upcase),
                self.class.const_get("SUBS_#{type}_PATHS_DEFAULT".upcase)
              )
            end

            private "#{obj_method_name}_uncached" # rubocop:disable Style/AccessModifierDeclarations
          end
        end
      end
    end
  end
end

Version data entries

117 entries across 117 versions & 3 rubygems

Version Path
avm-0.61.0 lib/avm/sources/base/subs.rb
eac_tools-0.54.0 sub/avm/lib/avm/sources/base/subs.rb
eac_tools-0.53.0 sub/avm/lib/avm/sources/base/subs.rb
eac_tools-0.52.0 sub/avm/lib/avm/sources/base/subs.rb
avm-0.60.0 lib/avm/sources/base/subs.rb
eac_tools-0.51.0 sub/avm/lib/avm/sources/base/subs.rb
avm-0.59.0 lib/avm/sources/base/subs.rb
eac_tools-0.50.0 sub/avm/lib/avm/sources/base/subs.rb
avm-0.58.0 lib/avm/sources/base/subs.rb
eac_tools-0.49.0 sub/avm/lib/avm/sources/base/subs.rb
eac_tools-0.48.1 sub/avm/lib/avm/sources/base/subs.rb
eac_tools-0.48.0 sub/avm/lib/avm/sources/base/subs.rb
eac_tools-0.47.2 sub/avm/lib/avm/sources/base/subs.rb
eac_tools-0.47.1 sub/avm/lib/avm/sources/base/subs.rb
eac_tools-0.47.0 sub/avm/lib/avm/sources/base/subs.rb
avm-0.57.0 lib/avm/sources/base/subs.rb
eac_tools-0.46.0 sub/avm/lib/avm/sources/base/subs.rb
avm-0.56.1 lib/avm/sources/base/subs.rb
eac_tools-0.45.2 sub/avm/lib/avm/sources/base/subs.rb
eac_tools-0.45.1 sub/avm/lib/avm/sources/base/subs.rb