42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
# File 'lib/domrobot/cli.rb', line 42
def updateRecord name
success_callbacks = []
if options["touch"]
require "fileutils"
success_callbacks << Proc.new do |message,data|
FileUtils.mkdir_p File.dirname options["touch"]
File.write options["touch"], [message,data].join("\n")
end
end
if options["default_address"]
require "domrobot/address"
address = Domrobot::Address.default
else
address = options["address"]
end
raise Exceptions unless address
subdomain = Subdomain.construct options["subdomain"]
domain = options["domain"]
name = [name,subdomain,domain].join(".")
type = options["type"]
record = Record.find_by domain:domain, name:name
unless record
puts "NEW"
record = Record.new domain:domain,name:name,type:type,content:address
result = record.save
if result["code"] = 1000
m,d = "OK NOOP","#{address} A #{name}."
puts m
success_callbacks.map{|cb| cb.call(m,d)} and exit 0
end
exit 1
end
if record.content == address
m,d = "OK NOOP","#{address} A #{name}."
puts m
success_callbacks.map{|cb| cb.call(m,d) } and exit 0
end
record.content = address
result = record.update
if result["code"] = 1000
m,d = "OK CREATE","#{address} A #{name}."
puts m
success_callbacks.map{|cb| cb.call(m,d)} and exit 0
end
exit 1
end
|