Class: Querly::ScriptEnumerator
- Inherits:
-
Object
- Object
- Querly::ScriptEnumerator
- Defined in:
- lib/querly/script_enumerator.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#paths ⇒ Object
readonly
Returns the value of attribute paths.
-
#threads ⇒ Object
readonly
Returns the value of attribute threads.
Class Method Summary collapse
Instance Method Summary collapse
-
#each(&block) ⇒ Object
Yields ‘Script` object concurrently, in different threads.
- #each_path(&block) ⇒ Object
-
#initialize(paths:, config:, threads:) ⇒ ScriptEnumerator
constructor
A new instance of ScriptEnumerator.
Constructor Details
#initialize(paths:, config:, threads:) ⇒ ScriptEnumerator
Returns a new instance of ScriptEnumerator.
7 8 9 10 11 |
# File 'lib/querly/script_enumerator.rb', line 7 def initialize(paths:, config:, threads:) @paths = paths @config = config @threads = threads end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
4 5 6 |
# File 'lib/querly/script_enumerator.rb', line 4 def config @config end |
#paths ⇒ Object (readonly)
Returns the value of attribute paths.
3 4 5 |
# File 'lib/querly/script_enumerator.rb', line 3 def paths @paths end |
#threads ⇒ Object (readonly)
Returns the value of attribute threads.
5 6 7 |
# File 'lib/querly/script_enumerator.rb', line 5 def threads @threads end |
Class Method Details
.find_loader(path) ⇒ Object
44 45 46 47 |
# File 'lib/querly/script_enumerator.rb', line 44 def self.find_loader(path) basename = path.basename.to_s @loaders.find {|pair| pair.first === basename }&.last end |
.register_loader(pattern, loader) ⇒ Object
40 41 42 |
# File 'lib/querly/script_enumerator.rb', line 40 def self.register_loader(pattern, loader) @loaders << [pattern, loader] end |
Instance Method Details
#each(&block) ⇒ Object
Yields ‘Script` object concurrently, in different threads.
14 15 16 17 18 19 20 21 22 |
# File 'lib/querly/script_enumerator.rb', line 14 def each(&block) if block_given? Parallel.each(each_path, in_threads: threads) do |path| load_script_from_path path, &block end else self.enum_for :each end end |
#each_path(&block) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/querly/script_enumerator.rb', line 24 def each_path(&block) if block_given? paths.each do |path| if path.directory? enumerate_files_in_dir(path, &block) else yield path end end else enum_for :each_path end end |