Skip to content

Instantly share code, notes, and snippets.

@leucos
Created March 31, 2012 19:29
Show Gist options
  • Select an option

  • Save leucos/2267725 to your computer and use it in GitHub Desktop.

Select an option

Save leucos/2267725 to your computer and use it in GitHub Desktop.
require 'sequel'
DB = Sequel.sqlite
DB.run "CREATE TABLE records (name VARCHAR(255) PRIMARY KEY NOT NULL, type VARCHAR(5), content VARCHAR(255))"
DB.run "INSERT INTO records VALUES ('example.com', 'SOA', 'ns.example.com root.example.com 2012333335 28800 86400 3600000 86400')"
Soa = Struct.new(:ns, :email, :serial, :refresh,:retry, :expiry, :minimum)
class Record < Sequel::Model
many_to_one :domain
plugin :validation_helpers
plugin :composition
composition :soa,
:composer => proc { @soa = Soa.new(self.content.split()) if self.type == 'SOA' },
:decomposer => proc { self.content = @soa.to_a.join(' ') }·
end
print "Testing."
a = Record.first
puts a.content
a.soa.ns = "newns.example.com"
a.soa.email = "hostmaster.example.com"
a.soa.serial = "00000"
a.soa.refresh = "11111"
a.soa.retry = "22222"
a.soa.expiry = "33333"
a.soa.minimum = "44444"
puts a.content
puts a.soa.ns
a.save
puts a.content
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment