Browse Source

Rename validation_methods variable (?)

pull/2438/head
Kat 2 years ago
parent
commit
f2b697a50a
  1. 12
      app/services/documentation_generator.rb
  2. 16
      lib/tasks/generate_lettings_documentation.rake
  3. 16
      lib/tasks/generate_sales_documentation.rake

12
app/services/documentation_generator.rb

@ -9,10 +9,10 @@ class DocumentationGenerator
include Validations::SoftValidations
include Validations::Sales::SoftValidations
def describe_hard_validations(client, validation_methods, all_helper_methods, log_type)
def describe_hard_validations(client, all_validation_methods, all_helper_methods, log_type)
form = FormHandler.instance.forms["current_#{log_type}"]
validation_methods.each do |meth|
all_validation_methods.each do |meth|
if LogValidation.where(validation_name: meth.to_s, bulk_upload_specific: false).exists?
Rails.logger.info("Validation #{meth} already exists")
next
@ -39,8 +39,8 @@ class DocumentationGenerator
end
end
def describe_bu_validations(client, form, row_parser_class, validation_methods, all_helper_methods, field_mapping_for_errors, log_type)
validation_methods.each do |meth|
def describe_bu_validations(client, form, row_parser_class, all_validation_methods, all_helper_methods, field_mapping_for_errors, log_type)
all_validation_methods.each do |meth|
if LogValidation.where(validation_name: meth.to_s, bulk_upload_specific: true, from: form.start_date).exists?
Rails.logger.info("Validation #{meth} already exists for #{form.start_date.year}")
next
@ -67,9 +67,9 @@ class DocumentationGenerator
end
end
def describe_soft_validations(client, validation_methods, all_helper_methods, log_type)
def describe_soft_validations(client, all_validation_methods, all_helper_methods, log_type)
validation_descriptions = {}
validation_methods.each do |meth|
all_validation_methods.each do |meth|
validation_source = method(meth).source
helper_methods_source = all_helper_methods.map { |helper_method|
if validation_source.include?(helper_method.to_s)

16
lib/tasks/generate_lettings_documentation.rake

@ -9,7 +9,7 @@ namespace :generate_lettings_documentation do
include Validations::TenancyValidations
include Validations::DateValidations
include Validations::LocalAuthorityValidations
validation_methods = public_methods.select { |method| method.starts_with?("validate_") }
all_validation_methods = public_methods.select { |method| method.starts_with?("validate_") }
all_methods = [Validations::SetupValidations,
Validations::HouseholdValidations,
Validations::PropertyValidations,
@ -17,9 +17,9 @@ namespace :generate_lettings_documentation do
Validations::TenancyValidations,
Validations::DateValidations,
Validations::LocalAuthorityValidations].map { |x| x.instance_methods + x.private_instance_methods }.flatten
all_helper_methods = all_methods - validation_methods
all_helper_methods = all_methods - all_validation_methods
DocumentationGenerator.new.describe_hard_validations(client, validation_methods, all_helper_methods, "lettings")
DocumentationGenerator.new.describe_hard_validations(client, all_validation_methods, all_helper_methods, "lettings")
end
desc "Generate documentation for soft lettings validations"
@ -29,9 +29,9 @@ namespace :generate_lettings_documentation do
client = OpenAI::Client.new(access_token: ENV["OPENAI_API_KEY"])
all_helper_methods = Validations::SoftValidations.private_instance_methods
validation_methods = Validations::SoftValidations.instance_methods
all_validation_methods = Validations::SoftValidations.instance_methods
DocumentationGenerator.new.describe_soft_validations(client, validation_methods, all_helper_methods, "lettings")
DocumentationGenerator.new.describe_soft_validations(client, all_validation_methods, all_helper_methods, "lettings")
end
desc "Generate documentation for hard bu lettings validations"
@ -40,12 +40,12 @@ namespace :generate_lettings_documentation do
[[FormHandler.instance.forms[FormHandler.instance.form_name_from_start_year(2023, "lettings")], BulkUpload::Lettings::Year2023::RowParser],
[FormHandler.instance.forms[FormHandler.instance.form_name_from_start_year(2024, "lettings")], BulkUpload::Lettings::Year2024::RowParser]].each do |form, row_parser_class|
validation_methods = row_parser_class.private_instance_methods.select { |method| method.starts_with?("validate_") }
all_validation_methods = row_parser_class.private_instance_methods.select { |method| method.starts_with?("validate_") }
all_helper_methods = row_parser_class.private_instance_methods(false) + row_parser_class.instance_methods(false) - validation_methods
all_helper_methods = row_parser_class.private_instance_methods(false) + row_parser_class.instance_methods(false) - all_validation_methods
field_mapping_for_errors = row_parser_class.new.send("field_mapping_for_errors")
DocumentationGenerator.new.describe_bu_validations(client, form, row_parser_class, validation_methods, all_helper_methods, field_mapping_for_errors, "lettings")
DocumentationGenerator.new.describe_bu_validations(client, form, row_parser_class, all_validation_methods, all_helper_methods, field_mapping_for_errors, "lettings")
end
end

16
lib/tasks/generate_sales_documentation.rake

@ -9,7 +9,7 @@ namespace :generate_sales_documentation do
include Validations::Sales::SaleInformationValidations
include Validations::SharedValidations
include Validations::LocalAuthorityValidations
validation_methods = public_methods.select { |method| method.starts_with?("validate_") }
all_validation_methods = public_methods.select { |method| method.starts_with?("validate_") }
all_methods = [Validations::Sales::SetupValidations,
Validations::Sales::HouseholdValidations,
Validations::Sales::PropertyValidations,
@ -18,9 +18,9 @@ namespace :generate_sales_documentation do
Validations::SharedValidations,
Validations::LocalAuthorityValidations].map { |x| x.instance_methods + x.private_instance_methods }.flatten
all_helper_methods = all_methods - validation_methods
all_helper_methods = all_methods - all_validation_methods
DocumentationGenerator.new.describe_hard_validations(client, validation_methods, all_helper_methods, "sales")
DocumentationGenerator.new.describe_hard_validations(client, all_validation_methods, all_helper_methods, "sales")
end
desc "Generate documentation for soft sales validations"
@ -30,9 +30,9 @@ namespace :generate_sales_documentation do
client = OpenAI::Client.new(access_token: ENV["OPENAI_API_KEY"])
all_helper_methods = Validations::SoftValidations.private_instance_methods + Validations::Sales::SoftValidations.private_instance_methods
validation_methods = Validations::SoftValidations.instance_methods + Validations::Sales::SoftValidations.instance_methods
all_validation_methods = Validations::SoftValidations.instance_methods + Validations::Sales::SoftValidations.instance_methods
DocumentationGenerator.new.describe_soft_validations(client, validation_methods, all_helper_methods, "sales")
DocumentationGenerator.new.describe_soft_validations(client, all_validation_methods, all_helper_methods, "sales")
end
desc "Generate documentation for hard bu sales validations"
@ -40,11 +40,11 @@ namespace :generate_sales_documentation do
client = OpenAI::Client.new(access_token: ENV["OPENAI_API_KEY"])
[[FormHandler.instance.forms[FormHandler.instance.form_name_from_start_year(2023, "sales")], BulkUpload::Sales::Year2023::RowParser],
[FormHandler.instance.forms[FormHandler.instance.form_name_from_start_year(2024, "sales")], BulkUpload::Sales::Year2024::RowParser]].each do |form, row_parser_class|
validation_methods = row_parser_class.private_instance_methods.select { |method| method.starts_with?("validate_") }
all_helper_methods = row_parser_class.private_instance_methods(false) + row_parser_class.instance_methods(false) - validation_methods
all_validation_methods = row_parser_class.private_instance_methods.select { |method| method.starts_with?("validate_") }
all_helper_methods = row_parser_class.private_instance_methods(false) + row_parser_class.instance_methods(false) - all_validation_methods
field_mapping_for_errors = row_parser_class.new.send("field_mapping_for_errors")
DocumentationGenerator.new.describe_bu_validations(client, form, row_parser_class, validation_methods, all_helper_methods, field_mapping_for_errors, "sales")
DocumentationGenerator.new.describe_bu_validations(client, form, row_parser_class, all_validation_methods, all_helper_methods, field_mapping_for_errors, "sales")
end
end

Loading…
Cancel
Save