Class: RubyRemoteConfig::WebRepository
- Inherits:
-
Object
- Object
- RubyRemoteConfig::WebRepository
- Includes:
- Repository
- Defined in:
- lib/web_repository.rb
Instance Attribute Summary collapse
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Attributes included from Repository
Instance Method Summary collapse
-
#initialize(name:, url:) ⇒ WebRepository
constructor
A new instance of WebRepository.
- #refresh ⇒ Object
Methods included from Repository
Constructor Details
#initialize(name:, url:) ⇒ WebRepository
Returns a new instance of WebRepository.
14 15 16 17 |
# File 'lib/web_repository.rb', line 14 def initialize(name:, url:) super(name: name) @url = URI.parse(url) end |
Instance Attribute Details
#url ⇒ Object (readonly)
Returns the value of attribute url.
12 13 14 |
# File 'lib/web_repository.rb', line 12 def url @url end |
Instance Method Details
#refresh ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/web_repository.rb', line 19 def refresh @lock.synchronize do http = Net::HTTP.new(@url.host, @url.port) http.use_ssl = @url.scheme == 'https' request = Net::HTTP::Get.new(@url) response = http.request(request) if response.code == '200' @raw_data = response.body @data = YAML.safe_load(@raw_data) else raise "Failed to fetch data from #{@url}: #{response}" end end end |