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:, config:) ⇒ ScriptEnumerator

Returns a new instance of ScriptEnumerator.



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

def initialize(paths:, config:)
  @paths = paths
  @config = config
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



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

def config
  @config
end

#pathsObject (readonly)

Returns the value of attribute paths.



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

def paths
  @paths
end

Class Method Details

.find_loader(path) ⇒ Object



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

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

.register_loader(pattern, loader) ⇒ Object



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

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
# File 'lib/querly/script_enumerator.rb', line 11

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