Class: RubyRemoteConfig::WebRepository

Inherits:
Object
  • Object
show all
Includes:
Repository
Defined in:
lib/web_repository.rb

Instance Attribute Summary collapse

Attributes included from Repository

#data, #lock, #name

Instance Method Summary collapse

Methods included from Repository

#get_data, #get_name

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

#urlObject (readonly)

Returns the value of attribute url.



12
13
14
# File 'lib/web_repository.rb', line 12

def url
  @url
end

Instance Method Details

#refreshObject



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