Class: Jackasset::AssetsChecker

Inherits:
Object
  • Object
show all
Defined in:
lib/jackasset/assets_checker.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host:, source_dir:) ⇒ AssetsChecker

Returns a new instance of AssetsChecker.



7
8
9
10
11
# File 'lib/jackasset/assets_checker.rb', line 7

def initialize(host:, source_dir:)
  @host = host
  @source_dir = source_dir
  @num_issues = 0
end

Instance Attribute Details

#hostObject (readonly)

Returns the value of attribute host.



5
6
7
# File 'lib/jackasset/assets_checker.rb', line 5

def host
  @host
end

#num_issuesObject (readonly)

Returns the value of attribute num_issues.



5
6
7
# File 'lib/jackasset/assets_checker.rb', line 5

def num_issues
  @num_issues
end

#source_dirObject (readonly)

Returns the value of attribute source_dir.



5
6
7
# File 'lib/jackasset/assets_checker.rb', line 5

def source_dir
  @source_dir
end

Class Method Details

.call(host: 'http://localhost:8080', source_dir:) ⇒ Object



13
14
15
# File 'lib/jackasset/assets_checker.rb', line 13

def self.call(host: 'http://localhost:8080', source_dir:)
  new(host: host, source_dir: source_dir).call
end

Instance Method Details

#callObject



17
18
19
20
21
22
23
24
25
# File 'lib/jackasset/assets_checker.rb', line 17

def call
  img_urls
  threads = img_urls.each_with_object([]) do |url, thread_list|
    next unless url.match?(/\Ahttp/)
    thread_list << Thread.new { check_url url }
  end
  threads.each(&:join)
  puts "Finished checking #{img_urls.count} URLs and found #{num_issues} issues"
end