Class: LeapSalesforce::Generator::SoqlEnums
- Inherits:
-
Object
- Object
- LeapSalesforce::Generator::SoqlEnums
- Includes:
- LeapSalesforce::Generator
- Defined in:
- lib/leap_salesforce/generator/soql_enums.rb
Overview
Creates Soql Enumerations / Picklists from objects in LeapSalesforce.objects_to_verify
Constant Summary collapse
- ENUM_FOLDER =
Returns Folder where enumeration objects are stored.
File.join(LeapSalesforce.lib_folder, 'metadata', 'enum').freeze
Instance Method Summary collapse
-
#cleanup_files_created ⇒ Object
Clean up files generated for all picklists.
-
#create ⇒ Object
Create Soql enumerations for all objects specified to verify.
-
#create_picklists_for(entity) ⇒ Object
Create files for each picklist found for that entity.
-
#generate_picklist_file(picklist) ⇒ Object
Generate file for a picklist from it’s metadata.
-
#reset_enum_folder ⇒ Object
Reset state of Enum folder so that enums that no longer exist do not persist.
Methods included from LeapSalesforce::Generator
#create_inner_file, #generate_file, #generate_files, #generate_from_template, #read_template, #template_loc
Instance Method Details
#cleanup_files_created ⇒ Object
Clean up files generated for all picklists
72 73 74 |
# File 'lib/leap_salesforce/generator/soql_enums.rb', line 72 def cleanup_files_created `rubocop -A #{ENUM_FOLDER} --display-only-fail-level-offenses --enable-pending-cops` end |
#create ⇒ Object
Create Soql enumerations for all objects specified to verify
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/leap_salesforce/generator/soql_enums.rb', line 16 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 reset_enum_folder LeapSalesforce.objects_to_verify.each { |entity| create_picklists_for entity } cleanup_files_created end |
#create_picklists_for(entity) ⇒ Object
Create files for each picklist found for that entity
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/leap_salesforce/generator/soql_enums.rb', line 30 def create_picklists_for(entity) soql_object = LeapSalesforce.soql_objects.find { |so| so.class_name == entity.to_s } raise "Could not find soql object for '#{entity}'" unless soql_object unless soql_object.create_enum != false puts "Skipping picklists for #{entity}" return end puts "Creating picklists for #{entity}" @entity_name = entity picklists = entity.picklists puts "#{picklists.count} picklists found" picklists.each do |picklist| if soql_object.excludes?(picklist) puts "Excluding picklist '#{picklist}'" else generate_picklist_file picklist end end end |
#generate_picklist_file(picklist) ⇒ Object
Generate file for a picklist from it’s metadata
52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/leap_salesforce/generator/soql_enums.rb', line 52 def generate_picklist_file(picklist) @picklist = picklist @enum_name = picklist.to_class_name picklist_name = picklist.to_key_name values = @entity_name.picklist_for(picklist) @enum_values = {} values.each do |value| @enum_values[value.to_key_name_for(@enum_values)] = value end content = read_template 'picklist.rb.erb', binding file = File.join(ENUM_FOLDER, @entity_name.to_s.snakecase, "#{picklist_name}.rb") generate_file file, content end |
#reset_enum_folder ⇒ Object
Reset state of Enum folder so that enums that no longer exist do not persist
67 68 69 |
# File 'lib/leap_salesforce/generator/soql_enums.rb', line 67 def reset_enum_folder FileUtils.rm_rf ENUM_FOLDER end |