Class: RuboCop::Schema::CachedHTTPClient

Inherits:
Object
  • Object
show all
Includes:
Helpers
Defined in:
lib/rubocop/schema/cached_http_client.rb

Instance Method Summary collapse

Methods included from Helpers

#boolean, #deep_dup, #deep_merge, #http_get, #strip_html, #template, templates

Constructor Details

#initialize(cache_dir, &event_handler) ⇒ CachedHTTPClient

Returns a new instance of CachedHTTPClient.



11
12
13
14
# File 'lib/rubocop/schema/cached_http_client.rb', line 11

def initialize(cache_dir, &event_handler)
  @cache_dir     = Pathname(cache_dir)
  @event_handler = event_handler
end

Instance Method Details

#get(url) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/rubocop/schema/cached_http_client.rb', line 16

def get(url)
  url = URI(url)
  validate_url url

  path = path_for_url(url)
  return path.read if path.readable?

  path.parent.mkpath
  Event.dispatch type: :request, &@event_handler

  http_get(url).tap(&path.method(:write))
end