Class: RuboCop::RemoteConfig
- Inherits:
-
Object
- Object
- RuboCop::RemoteConfig
- Defined in:
- lib/rubocop/remote_config.rb
Overview
Common methods and behaviors for dealing with remote config files.
Constant Summary collapse
- CACHE_LIFETIME =
24 * 60 * 60
Instance Attribute Summary collapse
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Instance Method Summary collapse
- #file ⇒ Object
- #inherit_from_remote(file, path) ⇒ Object
-
#initialize(url, base_dir) ⇒ RemoteConfig
constructor
A new instance of RemoteConfig.
Constructor Details
#initialize(url, base_dir) ⇒ RemoteConfig
Returns a new instance of RemoteConfig.
13 14 15 16 |
# File 'lib/rubocop/remote_config.rb', line 13 def initialize(url, base_dir) @uri = URI.parse(url) @base_dir = base_dir end |
Instance Attribute Details
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
9 10 11 |
# File 'lib/rubocop/remote_config.rb', line 9 def uri @uri end |
Instance Method Details
#file ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/rubocop/remote_config.rb', line 18 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) open cache_path, 'w' do |io| io.write response.body end end cache_path end |
#inherit_from_remote(file, path) ⇒ Object
32 33 34 35 36 |
# File 'lib/rubocop/remote_config.rb', line 32 def inherit_from_remote(file, path) new_uri = @uri.dup new_uri.path.gsub!(%r{/[^/]*$}, "/#{file}") RemoteConfig.new(new_uri.to_s, File.dirname(path)) end |