From 2b2ceeebab5ca01f5d60447aa13e553fc6765da3 Mon Sep 17 00:00:00 2001 From: Thorsten Eckel Date: Tue, 20 Dec 2016 16:16:09 +0100 Subject: [PATCH] Added splat args to every method call in import factories. --- lib/import/base_factory.rb | 22 ++++++++++----------- lib/import/otrs/article_customer_factory.rb | 2 +- lib/import/otrs/dynamic_field_factory.rb | 4 ++-- lib/import/otrs/history_factory.rb | 4 ++-- lib/import/otrs/state_factory.rb | 2 +- lib/import/otrs/sys_config_factory.rb | 2 +- lib/import/transaction_factory.rb | 4 ++-- lib/import/zendesk/base_factory.rb | 2 +- lib/import/zendesk/ticket_field_factory.rb | 2 +- 9 files changed, 22 insertions(+), 22 deletions(-) diff --git a/lib/import/base_factory.rb b/lib/import/base_factory.rb index 0fe6746e6..ed8039bd3 100644 --- a/lib/import/base_factory.rb +++ b/lib/import/base_factory.rb @@ -5,39 +5,39 @@ module Import extend self def import_action(records, *args) - pre_import_hook(records) - import_loop(records) do |record| - next if skip?(record) + pre_import_hook(records, *args) + import_loop(records, *args) do |record| + next if skip?(record, *args) backend_instance = create_instance(record, *args) - post_import_hook(record, backend_instance) + post_import_hook(record, backend_instance, *args) end end - def import(_records) + def import(_records, *_args) raise 'Missing import method implementation for this factory' end - def pre_import_hook(_records) + def pre_import_hook(_records, *args) end - def post_import_hook(_record, _backend_instance) + def post_import_hook(_record, _backend_instance, *args) end - def backend_class(_record) + def backend_class(_record, *_args) "Import::#{module_name}".constantize end - def skip?(_record) + def skip?(_record, *_args) false end private def create_instance(record, *args) - backend_class(record).new(record, *args) + backend_class(record, *args).new(record, *args) end - def import_loop(records, &import_block) + def import_loop(records, *_args, &import_block) records.each(&import_block) end diff --git a/lib/import/otrs/article_customer_factory.rb b/lib/import/otrs/article_customer_factory.rb index 95bc24db9..18c22c931 100644 --- a/lib/import/otrs/article_customer_factory.rb +++ b/lib/import/otrs/article_customer_factory.rb @@ -3,7 +3,7 @@ module Import module ArticleCustomerFactory extend Import::Factory - def skip?(record) + def skip?(record, *_args) return true if record['SenderType'] != 'customer' return true if record['CreatedBy'].to_i != 1 return true if record['From'].empty? diff --git a/lib/import/otrs/dynamic_field_factory.rb b/lib/import/otrs/dynamic_field_factory.rb index f6bbf350e..1937dbfdd 100644 --- a/lib/import/otrs/dynamic_field_factory.rb +++ b/lib/import/otrs/dynamic_field_factory.rb @@ -7,13 +7,13 @@ module Import # rubocop:disable Style/ModuleFunction extend self - def skip?(record) + def skip?(record, *_args) return true if !importable?(record) return true if skip_field?(record['Name']) false end - def backend_class(record) + def backend_class(record, *_args) "Import::OTRS::DynamicField::#{record['FieldType']}".constantize end diff --git a/lib/import/otrs/history_factory.rb b/lib/import/otrs/history_factory.rb index 3d91b66e9..f0d99dbb9 100644 --- a/lib/import/otrs/history_factory.rb +++ b/lib/import/otrs/history_factory.rb @@ -6,12 +6,12 @@ module Import # rubocop:disable Style/ModuleFunction extend self - def skip?(record) + def skip?(record, *_args) return true if !determine_class(record) false end - def backend_class(record) + def backend_class(record, *_args) "Import::OTRS::History::#{determine_class(record)}".constantize end diff --git a/lib/import/otrs/state_factory.rb b/lib/import/otrs/state_factory.rb index 40b85c8b1..6da18c9b1 100644 --- a/lib/import/otrs/state_factory.rb +++ b/lib/import/otrs/state_factory.rb @@ -6,7 +6,7 @@ module Import # rubocop:disable Style/ModuleFunction extend self - def pre_import_hook(_records) + def pre_import_hook(_records, *_args) backup end diff --git a/lib/import/otrs/sys_config_factory.rb b/lib/import/otrs/sys_config_factory.rb index da118a481..886dc4d17 100644 --- a/lib/import/otrs/sys_config_factory.rb +++ b/lib/import/otrs/sys_config_factory.rb @@ -5,7 +5,7 @@ module Import # rubocop:disable Style/ModuleFunction extend self - def import(settings) + def import(settings, *_args) settings.each do |setting| next if direct_copy?(setting) next if number_generator?(setting) diff --git a/lib/import/transaction_factory.rb b/lib/import/transaction_factory.rb index 8f1af13fb..c9b90b54f 100644 --- a/lib/import/transaction_factory.rb +++ b/lib/import/transaction_factory.rb @@ -5,9 +5,9 @@ module Import # rubocop:disable Style/ModuleFunction extend self - def import(records) + def import(records, *args) ActiveRecord::Base.transaction do - import_action(records) + import_action(records, *args) end end end diff --git a/lib/import/zendesk/base_factory.rb b/lib/import/zendesk/base_factory.rb index 5ec8fdfdb..3e2753b7e 100644 --- a/lib/import/zendesk/base_factory.rb +++ b/lib/import/zendesk/base_factory.rb @@ -8,7 +8,7 @@ module Import private - def import_loop(records, &import_block) + def import_loop(records, *_args, &import_block) records.all!(&import_block) end end diff --git a/lib/import/zendesk/ticket_field_factory.rb b/lib/import/zendesk/ticket_field_factory.rb index b85dd8eb5..9b3d0606c 100644 --- a/lib/import/zendesk/ticket_field_factory.rb +++ b/lib/import/zendesk/ticket_field_factory.rb @@ -17,7 +17,7 @@ module Import # rubocop:disable Style/ModuleFunction extend self - def skip?(field) + def skip?(field, *_args) # check if the Ticket object already has a same named column / attribute # so we want to skip instead of importing it Ticket.column_names.include?( local_attribute(field) )