Class: Zypper::Upgraderepo::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/zypper/upgraderepo/request.rb

Overview

Load the right class to handle the protool and achieve the request..

Class Method Summary collapse

Class Method Details

.build(repo, timeout) ⇒ Object

Raises:



15
16
17
18
19
20
21
# File 'lib/zypper/upgraderepo/request.rb', line 15

def self.build(repo, timeout)
  @@registry ||= load_requests

  raise InvalidProtocol, repo unless @@registry.include? repo.protocol

  Object.const_get(find_class(repo)).new(repo, timeout)
end

.find_class(repo) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/zypper/upgraderepo/request.rb', line 40

def self.find_class(repo)
  domain = URI(repo.url).hostname

  return @@registry[repo.protocol][domain] if @@registry[repo.protocol].key? domain

  @@registry[repo.protocol]["default"]
end

.load_requestsObject



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/zypper/upgraderepo/request.rb', line 27

def self.load_requests
  res = {}
  Requests.constants.each do |klass|
    obj = Object.const_get("Zypper::Upgraderepo::Requests::#{klass}")
    obj.register_protocol.each do |protocol|
      res[protocol] ||= {}
      res[protocol][obj.domain] = "Zypper::Upgraderepo::Requests::#{klass}"
    end
  end

  res
end

.protocolsObject



23
24
25
# File 'lib/zypper/upgraderepo/request.rb', line 23

def self.protocols
  load_requests.keys
end