Sha256: bbf383adee4d78e5aa725e25d79624c16cc6dcf5b30b91295b9faa41df728405

Contents?: true

Size: 1.28 KB

Versions: 3

Compression:

Stored size: 1.28 KB

Contents

require 'nokogiri'

module Dcgen

  def self.customfield master , destination, output = true

    remove_customfields = []

    master_objects = Dir.glob(master + '/objects/*object').map {|c| c.match(/^.*\/(.*).object$/)[1] }

    master_objects.each do |obj|

      master_obj_file = File.join(master,'objects',obj + '.object')
      destination_obj_file = File.join(destination,'objects',obj + '.object')

      if File.exists? destination_obj_file

        master_obj_xml = File.open(master_obj_file).read
        destination_obj_xml = File.open(destination_obj_file).read

        master_doc = Nokogiri::XML(master_obj_xml).remove_namespaces!
        destination_doc = Nokogiri::XML(destination_obj_xml).remove_namespaces!

        # Find all the customfields that are in destination, if they are not present in
        # master, then they have to be in the remove list
        destination_doc.xpath('//fields/fullName').each do |field|
          remove_customfields << "#{obj}.#{field.text}" if master_doc.xpath("//fields[fullName=\"#{field.text}\"]").empty?
        end

      end

    end

    
    if output
      puts "CustomFields:" if not remove_customfields.empty?
      remove_customfields.each do |customfield|
        puts "  #{customfield}"
      end
    end

    remove_customfields

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
salesforce-dcgen-0.8.0 lib/dcgen/plugins/customfield.rb
salesforce-dcgen-0.7.0 lib/dcgen/plugins/customfield.rb
salesforce-dcgen-0.6.0 lib/dcgen/plugins/customfield.rb