# 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