Sha256: 54cbc8fc23fb75e45aa3baa770ab4f1595d88b44d934c36ed365def753faf668

Contents?: true

Size: 1.64 KB

Versions: 1

Compression:

Stored size: 1.64 KB

Contents

# frozen_string_literal: true

require_relative 'soql_objects'

module LeapSalesforce
  # Generators for creating code
  module Generator
    # Creates Soql Enumerations / Picklists
    class SoqlEnums
      include Generator

      ENUM_FOLDER = File.join(LeapSalesforce.lib_folder, 'metadata', 'enum').freeze

      # Create Soql enumerations for all objects specified to verify
      def create
        if LeapSalesforce.objects_to_verify.empty?
          raise LeapSalesforce::SetupError, 'LeapSalesforce.objects_to_verify is empty. ' \
        'Please set the list of objects you want to verify in .leap_salesforce:soql_objects ' \
        'and then run task "leaps:create_soql_objects" to create objects'
        end

        LeapSalesforce.objects_to_verify.each do |entity|
          unless entity.create_enum?
            puts "Skipping picklists for #{entity}"
            next
          end

          puts "Creating picklists for #{entity}"
          @entity_name = entity
          picklists = entity.picklists
          puts "#{picklists.count} picklists found"
          picklists.each do |picklist|
            @picklist = picklist
            @enum_name = picklist.to_class_name
            picklist_name = picklist.to_key_name
            values = entity.picklist_for picklist
            @enum_values = {}
            values.each { |value| @enum_values[value.to_key_name] = value }
            content = read_template 'picklist.rb.erb', binding
            file = File.join(ENUM_FOLDER, entity.to_s.snakecase, "#{picklist_name}.rb")
            generate_file file, content
          end
        end
        `rubocop -a #{ENUM_FOLDER}`
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
leap_salesforce-0.1.5 lib/leap_salesforce/generator/soql_enums.rb