Class: LeapSalesforce::Generator::SoqlObjects
- Inherits:
-
Object
- Object
- LeapSalesforce::Generator::SoqlObjects
- Includes:
- LeapSalesforce::Generator
- Defined in:
- lib/leap_salesforce/generator/soql_objects.rb
Overview
Creates SoqlObjects and related modules
Constant Summary collapse
- SOQL_OBJECT_FOLDER =
File.join(LeapSalesforce.lib_folder, 'soql_data').freeze
- FACTORY_FOLDER =
File.join(LeapSalesforce.lib_folder, 'factories').freeze
Instance Method Summary collapse
-
#create_all ⇒ Object
Generate soql_object and it’s related modules, factories.
-
#ensure_class_defined ⇒ Object
Create temporary class for building API requests on.
-
#generate_factory ⇒ Object
Generate factory for mass generating objects using FactoryBot.
-
#generate_field_module ⇒ Object
Generate module with fields for Soql Object.
-
#generate_soql_object ⇒ Object
Generate Soql object file.
Methods included from LeapSalesforce::Generator
#create_inner_file, #generate_file, #generate_files, #generate_from_template, #read_template, #template_loc
Instance Method Details
#create_all ⇒ Object
Generate soql_object and it’s related modules, factories
55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/leap_salesforce/generator/soql_objects.rb', line 55 def create_all puts "Generating Soql objects for #{LeapSalesforce.soql_objects.count} objects" LeapSalesforce.soql_objects.each do |soql_object| # Soql object is now special class # extract_info_from_object soql_object @soql_object = soql_object @field_name_file = "#{soql_object.reference}_field_names" generate_soql_object generate_field_module generate_factory end `rubocop -A #{SOQL_OBJECT_FOLDER} --enable-pending-cops` `rubocop -A #{FACTORY_FOLDER} --enable-pending-cops` end |
#ensure_class_defined ⇒ Object
Create temporary class for building API requests on
19 20 21 22 23 24 |
# File 'lib/leap_salesforce/generator/soql_objects.rb', line 19 def ensure_class_defined @soql_class = Object.const_get @soql_object.class_name rescue NameError @soql_class = Object.const_set @soql_object.class_name, Class.new(SoqlData) @soql_class.instance_variable_set(:@soql_object_name, @soql_object.backend_name) end |
#generate_factory ⇒ Object
Generate factory for mass generating objects using FactoryBot
47 48 49 50 51 52 |
# File 'lib/leap_salesforce/generator/soql_objects.rb', line 47 def generate_factory @default_fields, @other_fields = filter_fields content = read_template 'factory.rb.erb', binding file = File.join(FACTORY_FOLDER, "#{@soql_object.reference}.rb") generate_file file, content, overwrite: false end |
#generate_field_module ⇒ Object
Generate module with fields for Soql Object
40 41 42 43 44 |
# File 'lib/leap_salesforce/generator/soql_objects.rb', line 40 def generate_field_module field_content = read_template 'soql_object_field_names.rb.erb', binding field_file = File.join(SOQL_OBJECT_FOLDER, "#{@field_name_file}.rb") generate_file field_file, field_content end |
#generate_soql_object ⇒ Object
Generate Soql object file
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/leap_salesforce/generator/soql_objects.rb', line 27 def generate_soql_object ensure_class_defined desc = @soql_class.description unless desc.soql_fields? raise LeapSalesforce::SetupError, "Error producing Soql data for '#{@soql_class}', soql table " \ " '#{@soql_object.backend_name}'. Error message: '#{desc.}'" end content = read_template 'soql_object.rb.erb', binding file = File.join(SOQL_OBJECT_FOLDER, "#{@soql_object.reference}.rb") generate_file file, content, overwrite: false end |