Class: Querly::ScriptEnumerator

Inherits:
Object
  • Object
show all
Defined in:
lib/querly/script_enumerator.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(paths:, preprocessors: {}) ⇒ ScriptEnumerator

Returns a new instance of ScriptEnumerator.



6
7
8
9
# File 'lib/querly/script_enumerator.rb', line 6

def initialize(paths:, preprocessors: {})
  @paths = paths
  @preprocessors = preprocessors
end

Instance Attribute Details

#pathsObject (readonly)

Returns the value of attribute paths.



3
4
5
# File 'lib/querly/script_enumerator.rb', line 3

def paths
  @paths
end

#preprocessorsObject (readonly)

Returns the value of attribute preprocessors.



4
5
6
# File 'lib/querly/script_enumerator.rb', line 4

def preprocessors
  @preprocessors
end

Class Method Details

.find_loader(path) ⇒ Object



32
33
34
35
# File 'lib/querly/script_enumerator.rb', line 32

def self.find_loader(path)
  basename = path.basename.to_s
  @loaders.find {|pair| pair.first === basename }&.last
end

.register_loader(pattern, loader) ⇒ Object



28
29
30
# File 'lib/querly/script_enumerator.rb', line 28

def self.register_loader(pattern, loader)
  @loaders << [pattern, loader]
end

Instance Method Details

#each(&block) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/querly/script_enumerator.rb', line 11

def each(&block)
  if block_given?
    paths.each do |path|
      case
      when path.file?
        load_script_from_path path, &block
      when path.directory?
        enumerate_files_in_dir(path, &block)
      end
    end
  else
    self.enum_for :each
  end
end