Class: NameServerCache

Inherits:
Object
  • Object
show all
Defined in:
app/models/name_server_cache.rb

Class Method Summary collapse

Class Method Details

.get_cached(key, opts = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/models/name_server_cache.rb', line 6

def self.get_cached(key, opts={})
  unless Rails.configuration.action_controller.perform_caching
    if block_given?
      return yield
    end
  end

  val = Rails.cache.read(key)
  unless val
    if block_given?
      val = yield
      if val
        Rails.cache.write(key, val, opts)
      end
    end
  end

  return val
end

.get_name_serversObject

Raises:

  • (OpenShift::UserException)


26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'app/models/name_server_cache.rb', line 26

def self.get_name_servers
  dns = Dnsruby::DNS.new()
  domain = Rails.application.config.openshift[:domain_suffix]
  while domain && !domain.empty?
    resources = dns.getresources(domain, Dnsruby::Types.NS)
    unless resources.empty?
      break
    else
      dp = domain.partition('.')
      domain = dp[2]
    end
  end
  raise OpenShift::UserException.new("Unable to find nameservers for domain '#{Rails.application.config.openshift[:domain_suffix]}'",
                                     141) if resources.empty?
  @nameservers = []
  resources.each do |resource|
    @nameservers.push(resource.domainname.to_s)
  end                
  get_cached("name_servers", :expires_in => 1.hour) {@nameservers}
end