Module: Avm::Sources::Base::Subs

Defined in:
lib/avm/sources/base/subs.rb

Constant Summary collapse

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

Instance Method Summary collapse

Instance Method Details

#sub_for_path(path) ⇒ Avm::Sources::Base?

Returns:



16
17
18
# File 'lib/avm/sources/base/subs.rb', line 16

def sub_for_path(path)
  subs.lazy.map { |sub| path.expand_path.child_of?(sub.path) ? sub : nil }.find(&:present?)
end

#subsEnumerable<Avm::Sources::Base>

Returns:



21
22
23
24
25
26
# File 'lib/avm/sources/base/subs.rb', line 21

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

#subs_paths_to_searchObject



28
29
30
31
32
33
34
35
36
# File 'lib/avm/sources/base/subs.rb', line 28

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