Class: Templatecop::PathFinder

Inherits:
Object
  • Object
show all
Defined in:
lib/templatecop/path_finder.rb

Overview

Collect file paths from given path patterns.

Instance Method Summary collapse

Constructor Details

#initialize(default_patterns:, patterns:) ⇒ PathFinder

Returns a new instance of PathFinder.

Parameters:

  • default_patterns (Array<String>)
  • patterns (Array<String>)

    Patterns normally given as CLI arguments (e.g. ‘[“app/views/*/.html.template”]`).



10
11
12
13
14
15
16
# File 'lib/templatecop/path_finder.rb', line 10

def initialize(
  default_patterns:,
  patterns:
)
  @default_patterns = default_patterns
  @patterns = patterns
end

Instance Method Details

#callArray<String>

Returns:

  • (Array<String>)


19
20
21
22
23
24
25
# File 'lib/templatecop/path_finder.rb', line 19

def call
  patterns.flat_map do |pattern|
    ::Pathname.glob(pattern).select(&:file?).map do |pathname|
      pathname.expand_path.to_s
    end
  end.uniq.sort
end