Class: RuboCop::RemoteConfig Private
Do not use. This class is for internal use only.
Relationships & Source Files | |
Inherits: | Object |
Defined in: | lib/rubocop/remote_config.rb |
Overview
Common methods and behaviors for dealing with remote config files.
Constant Summary
-
CACHE_LIFETIME =
# File 'lib/rubocop/remote_config.rb', line 1224 * 60 * 60
Class Method Summary
- .new(url, base_dir) ⇒ RemoteConfig constructor Internal use only
Instance Attribute Summary
- #uri readonly Internal use only
- #cache_path_exists? ⇒ Boolean readonly private Internal use only
- #cache_path_expired? ⇒ Boolean readonly private Internal use only
Instance Method Summary
- #file Internal use only
- #inherit_from_remote(file, path) Internal use only
- #cache_name_from_uri private Internal use only
- #cache_path private Internal use only
- #cloned_url private Internal use only
- #generate_request(uri) {|request| ... } private Internal use only
- #handle_response(response, limit, &block) private Internal use only
- #request(uri = @uri, limit = 10, &block) private Internal use only
Instance Attribute Details
#cache_path_exists? ⇒ Boolean
(readonly, private)
# File 'lib/rubocop/remote_config.rb', line 86
def cache_path_exists? @cache_path_exists ||= File.exist?(cache_path) end
#cache_path_expired? ⇒ Boolean
(readonly, private)
# File 'lib/rubocop/remote_config.rb', line 90
def cache_path_expired? return true unless cache_path_exists? @cache_path_expired ||= begin file_age = (Time.now - File.stat(cache_path).mtime).to_f (file_age / CACHE_LIFETIME) > 1 end end
#uri (readonly)
[ GitHub ]# File 'lib/rubocop/remote_config.rb', line 10
attr_reader :uri
Instance Method Details
#cache_name_from_uri (private)
[ GitHub ]# File 'lib/rubocop/remote_config.rb', line 99
def cache_name_from_uri uri = cloned_url uri.query = nil uri.to_s.gsub!(/[^0-9A-Za-z]/, '-') end
#cache_path (private)
[ GitHub ]# File 'lib/rubocop/remote_config.rb', line 82
def cache_path File. (".rubocop-#{cache_name_from_uri}", @base_dir) end
#cloned_url (private)
[ GitHub ]#file
[ GitHub ]# File 'lib/rubocop/remote_config.rb', line 23
def file return cache_path unless cache_path_expired? request do |response| next if response.is_a?(Net::HTTPNotModified) next if response.is_a?(SocketError) File.write(cache_path, response.body) end cache_path end
#generate_request(uri) {|request| ... } (private)
#handle_response(response, limit, &block) (private)
[ GitHub ]# File 'lib/rubocop/remote_config.rb', line 66
def handle_response(response, limit, &block) case response when Net::HTTPSuccess, Net::HTTPNotModified, SocketError yield response when Net::HTTPRedirection request(URI.parse(response['location']), limit - 1, &block) else begin response.error! rescue StandardError => e = "#{e.} while downloading remote config file #{cloned_url}" raise e, end end end
#inherit_from_remote(file, path)
[ GitHub ]#request(uri = @uri, limit = 10, &block) (private)
# File 'lib/rubocop/remote_config.rb', line 44
def request(uri = @uri, limit = 10, &block) raise ArgumentError, 'HTTP redirect too deep' if limit.zero? http = Net::HTTP.new(uri.hostname, uri.port) http.use_ssl = uri.instance_of?(URI::HTTPS) generate_request(uri) do |request| handle_response(http.request(request), limit, &block) rescue SocketError => e handle_response(e, limit, &block) end end