Class: DeployTool::Target

Inherits:
Object
  • Object
show all
Defined in:
lib/deploytool/target.rb

Direct Known Subclasses

EfficientCloud

Defined Under Namespace

Classes: EfficientCloud

Class Method Summary collapse

Class Method Details

.find(target_spec) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/deploytool/target.rb', line 28

def self.find(target_spec)
  known_subclasses.each do |klass|
    next unless klass.matches?(target_spec)
    return klass.create(target_spec)
  end
  nil
end

.from_config(config) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/deploytool/target.rb', line 36

def self.from_config(config)
  known_subclasses.each do |klass|
    next unless klass.to_s.split('::').last == config['type']
    return klass.new(config)
  end
  nil
end

.get_json_resource(url) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/deploytool/target.rb', line 44

def self.get_json_resource(url)
  res = nil
  begin
    timeout(5) do
      res = Net::HTTP.get_response(Addressable::URI.parse(url))
    end
  rescue Timeout::Error
    $logger.debug "Calling '%s' took longer than 5s, skipping" % [url, res.code, res.body]
    return nil
  end
  return nil if res.nil?
  if res.code != '200'
    $logger.debug "Calling '%s' returned %s, skipping" % [url, res.code, res.body]
    return nil
  end
  JSON.parse(res.body)
end