app/models/record_template.rb
# Convert this template record into a instance +record_type+ with the
# attributes of the template copied over to the instance
Convert this template record into a instance +record_type+ with the
attributes of the template copied over to the instance
Convert this template record into a instance + record_type + with the attributes of the template copied over to the instance
def build( domain_name = nil )
    record_class = self.record_type.constantize
    attrs = self.attributes.dup.with_indifferent_access
    attrs.delete_if { |k,_| !record_class.columns.map( &:name ).include?( k ) }
    attrs.delete( :id )
    if domain_name.present?
      attrs.keys.each do |k|
        attrs[k] = attrs[k].gsub( '%ZONE%', domain_name ) if attrs[k].is_a?( String )
      end
    end
    if soa?
      SOA::SOA_FIELDS.each do |soa_field|
        soa_val = instance_variable_get("@#{soa_field}")
        if domain_name.present? && soa_val.is_a?( String )
          soa_val = soa_val.gsub( '%ZONE%', domain_name )
        end
        attrs[soa_field] = soa_val
      end
      attrs[:serial] = 0
    end
    record_class.new( attrs )
  end
def build ( domain_name = nil ) record_class = self . record_type . constantize attrs = self . attributes . dup . with_indifferent_access attrs . delete_if { | k , _ | ! record_class . columns . map ( & :name ) . include? ( k ) } attrs . delete ( :id ) if domain_name . present? attrs . keys . each do | k | attrs [ k ] = attrs [ k ] . gsub ( '%ZONE%' , domain_name ) if attrs [ k ] . is_a? ( String ) end end if soa? SOA :: SOA_FIELDS . each do | soa_field | soa_val = instance_variable_get ( "@#{soa_field}" ) if domain_name . present? && soa_val . is_a? ( String ) soa_val = soa_val . gsub ( '%ZONE%' , domain_name ) end attrs [ soa_field ] = soa_val end attrs [ :serial ] = 0 end record_class . new ( attrs ) end
Convert this template record into a instance +record_type+ with the
attributes of the template copied over to the instance
Convert this template record into a instance + record_type + with the attributes of the template copied over to the instance
# get the class of the record_type # duplicate our own attributes, strip out the ones the destination doesn't # have (and the id as well) # parse each attribute, looking for %ZONE% # Handle SOA convenience fields if needed # instantiate a new destination with our duplicated attributes & validate
domain_name
<not_specific>