Class: GsImgFetcher::Manager

Inherits:
Object
  • Object
show all
Defined in:
lib/gs_img_fetcher/manager.rb

Constant Summary collapse

DEFAULT_MAX_THREADS =
Concurrent.processor_count

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(entry_set, output_dir: nil, async: true, max_threads: nil, max_size: nil) ⇒ Manager

Returns a new instance of Manager.



18
19
20
21
22
23
24
25
26
27
# File 'lib/gs_img_fetcher/manager.rb', line 18

def initialize(entry_set, output_dir: nil, async: true, max_threads: nil, max_size: nil)
  @entry_set = entry_set
  @output_dir = output_dir || Dir.pwd
  @async = async
  @max_threads = max_threads || DEFAULT_MAX_THREADS
  @max_size = max_size
  @entries = Queue.new
  @successful_fetches = Queue.new
  @failed_fetches = Queue.new
end

Instance Attribute Details

#entriesObject (readonly)

Returns the value of attribute entries.



14
15
16
# File 'lib/gs_img_fetcher/manager.rb', line 14

def entries
  @entries
end

#entry_setObject (readonly)

Returns the value of attribute entry_set.



14
15
16
# File 'lib/gs_img_fetcher/manager.rb', line 14

def entry_set
  @entry_set
end

#failed_fetchesObject (readonly)

Returns the value of attribute failed_fetches.



14
15
16
# File 'lib/gs_img_fetcher/manager.rb', line 14

def failed_fetches
  @failed_fetches
end

#successful_fetchesObject (readonly)

Returns the value of attribute successful_fetches.



14
15
16
# File 'lib/gs_img_fetcher/manager.rb', line 14

def successful_fetches
  @successful_fetches
end

Class Method Details

.fetch(input_path, **opts) ⇒ Object



8
9
10
11
# File 'lib/gs_img_fetcher/manager.rb', line 8

def fetch(input_path, **opts)
  entry_set = EntrySet.from_file(input_path)
  new(entry_set, **opts).setup.fetch
end

Instance Method Details

#fetchObject



39
40
41
42
43
44
45
# File 'lib/gs_img_fetcher/manager.rb', line 39

def fetch
  @async ? async_fetch : sync_fetch

  log_result
  successful_fetches.close
  failed_fetches.close
end

#setupObject



29
30
31
32
33
34
35
36
37
# File 'lib/gs_img_fetcher/manager.rb', line 29

def setup
  tap do
    log_entries

    next unless entries.empty?

    entry_set.valid_entries.each { |e| entries.push(e) }
  end
end