app/models/zone_template.rb
# Build a new zone using +self+ as a template. +domain+ should be valid domain
# name. Pass the optional +user+ object along to have the new one owned by the
# user, otherwise it's for admins only.
#
# This method will throw exceptions as it encounters errors, and will use a
# transaction to complete/rollback the operation.
Build a new zone using +self+ as a template. +domain+ should be valid domain
name. Pass the optional +user+ object along to have the new one owned by the
user, otherwise it's for admins only.

This method will throw exceptions as it encounters errors, and will use a
transaction to complete/rollback the operation.
Build a new zone using + self + as a template . + domain + should be valid domain name . Pass the optional + user + object along to have the new one owned by the user otherwise it ' s for admins only . This method will throw exceptions as it encounters errors and will use a transaction to complete / rollback the operation .
def build( domain_name, user = nil )
    domain = Domain.new( :name => domain_name, :ttl => self.ttl, :type => self.type )
    domain.master = self.master if slave?
    domain.user = user if user.is_a?( User )
    self.class.transaction do
      soa_template = record_templates.detect { |r| r.record_type == 'SOA' }
      built_soa_template = soa_template.build( domain_name )
      Domain::SOA_FIELDS.each do |f|
        domain.send( "#{f}=", built_soa_template.send( f ) )
      end
      domain.save!
      templates = record_templates.dup
      Record.batch do
        templates.delete( soa_template )
        templates.each do |template|
          record = template.build( domain_name )
          record.domain = domain
          record.save!
        end
      end
    end
    domain
  end
def build ( domain_name , user = nil ) domain = Domain . new ( :name => domain_name , :ttl => self . ttl , :type => self . type ) domain . master = self . master if slave? domain . user = user if user . is_a? ( User ) self . class . transaction do soa_template = record_templates . detect { | r | r . record_type == 'SOA' } built_soa_template = soa_template . build ( domain_name ) Domain :: SOA_FIELDS . each do | f | domain . send ( "#{f}=" , built_soa_template . send ( f ) ) end domain . save! templates = record_templates . dup Record . batch do templates . delete ( soa_template ) templates . each do | template | record = template . build ( domain_name ) record . domain = domain record . save! end end end domain end
Build a new zone using +self+ as a template.
Build a new zone using + self + as a template .
# Pick our SOA template out, and populate the zone # save the zone or die # get the templates # now build the remaining records according to the templates
domain_name
<not_specific>
user
<not_specific>