Class: Cert

Inherits:
CouchRest::Model::Base
  • Object
show all
Defined in:
app/models/cert.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.pick_from_poolObject



25
26
27
28
29
30
31
32
# File 'app/models/cert.rb', line 25

def pick_from_pool
  cert = self.sample || self.create!
  cert.destroy
  return cert
rescue RESOURCE_NOT_FOUND
  retry if Cert.by_random.count > 0
  raise RECORD_NOT_FOUND
end

.sampleObject



21
22
23
# File 'app/models/cert.rb', line 21

def sample
  self.by_random.startkey(rand).first || self.by_random.first
end

Instance Method Details

#attach_zipObject



40
41
42
43
# File 'app/models/cert.rb', line 40

def attach_zip
  file = File.open(Rails.root.join("config", "cert"))
  self.create_attachment :file => file, :name => zipname
end

#set_randomObject



36
37
38
# File 'app/models/cert.rb', line 36

def set_random
  self.random = rand
end

#zip_attachmentObject



49
50
51
# File 'app/models/cert.rb', line 49

def zip_attachment
  attachments[zipname]
end

#zipnameObject



45
46
47
# File 'app/models/cert.rb', line 45

def zipname
  'cert.txt'
end

#zippedObject



53
54
55
# File 'app/models/cert.rb', line 53

def zipped
  read_attachment(zipname)
end