|
|
@ -34,6 +34,15 @@ class Domain < ActiveRecord::Base |
|
|
|
:minimum => 2, :maximum => 10, :message => "must have be at least 2, at most 10"} |
|
|
|
:minimum => 2, :maximum => 10, :message => "must have be at least 2, at most 10"} |
|
|
|
validates_associated :records |
|
|
|
validates_associated :records |
|
|
|
validates :user_id, :presence => true |
|
|
|
validates :user_id, :presence => true |
|
|
|
|
|
|
|
validate do # domain ownership |
|
|
|
|
|
|
|
segments = name.split('.') |
|
|
|
|
|
|
|
if segments.size > 2 |
|
|
|
|
|
|
|
parent = segments[1..-1].join('.') |
|
|
|
|
|
|
|
unless Domain.exists?(:name => parent, :user_id => user_id) |
|
|
|
|
|
|
|
errors.add :name, "issue, must create the domain named `#{parent}` first" |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
def slave?; self.type == 'SLAVE' end |
|
|
|
def slave?; self.type == 'SLAVE' end |
|
|
|
|
|
|
|
|
|
|
|