Added splat args to every method call in import factories.
This commit is contained in:
parent
81bfeac091
commit
2b2ceeebab
9 changed files with 22 additions and 22 deletions
|
@ -5,39 +5,39 @@ module Import
|
||||||
extend self
|
extend self
|
||||||
|
|
||||||
def import_action(records, *args)
|
def import_action(records, *args)
|
||||||
pre_import_hook(records)
|
pre_import_hook(records, *args)
|
||||||
import_loop(records) do |record|
|
import_loop(records, *args) do |record|
|
||||||
next if skip?(record)
|
next if skip?(record, *args)
|
||||||
backend_instance = create_instance(record, *args)
|
backend_instance = create_instance(record, *args)
|
||||||
post_import_hook(record, backend_instance)
|
post_import_hook(record, backend_instance, *args)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def import(_records)
|
def import(_records, *_args)
|
||||||
raise 'Missing import method implementation for this factory'
|
raise 'Missing import method implementation for this factory'
|
||||||
end
|
end
|
||||||
|
|
||||||
def pre_import_hook(_records)
|
def pre_import_hook(_records, *args)
|
||||||
end
|
end
|
||||||
|
|
||||||
def post_import_hook(_record, _backend_instance)
|
def post_import_hook(_record, _backend_instance, *args)
|
||||||
end
|
end
|
||||||
|
|
||||||
def backend_class(_record)
|
def backend_class(_record, *_args)
|
||||||
"Import::#{module_name}".constantize
|
"Import::#{module_name}".constantize
|
||||||
end
|
end
|
||||||
|
|
||||||
def skip?(_record)
|
def skip?(_record, *_args)
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def create_instance(record, *args)
|
def create_instance(record, *args)
|
||||||
backend_class(record).new(record, *args)
|
backend_class(record, *args).new(record, *args)
|
||||||
end
|
end
|
||||||
|
|
||||||
def import_loop(records, &import_block)
|
def import_loop(records, *_args, &import_block)
|
||||||
records.each(&import_block)
|
records.each(&import_block)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ module Import
|
||||||
module ArticleCustomerFactory
|
module ArticleCustomerFactory
|
||||||
extend Import::Factory
|
extend Import::Factory
|
||||||
|
|
||||||
def skip?(record)
|
def skip?(record, *_args)
|
||||||
return true if record['SenderType'] != 'customer'
|
return true if record['SenderType'] != 'customer'
|
||||||
return true if record['CreatedBy'].to_i != 1
|
return true if record['CreatedBy'].to_i != 1
|
||||||
return true if record['From'].empty?
|
return true if record['From'].empty?
|
||||||
|
|
|
@ -7,13 +7,13 @@ module Import
|
||||||
# rubocop:disable Style/ModuleFunction
|
# rubocop:disable Style/ModuleFunction
|
||||||
extend self
|
extend self
|
||||||
|
|
||||||
def skip?(record)
|
def skip?(record, *_args)
|
||||||
return true if !importable?(record)
|
return true if !importable?(record)
|
||||||
return true if skip_field?(record['Name'])
|
return true if skip_field?(record['Name'])
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
|
|
||||||
def backend_class(record)
|
def backend_class(record, *_args)
|
||||||
"Import::OTRS::DynamicField::#{record['FieldType']}".constantize
|
"Import::OTRS::DynamicField::#{record['FieldType']}".constantize
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -6,12 +6,12 @@ module Import
|
||||||
# rubocop:disable Style/ModuleFunction
|
# rubocop:disable Style/ModuleFunction
|
||||||
extend self
|
extend self
|
||||||
|
|
||||||
def skip?(record)
|
def skip?(record, *_args)
|
||||||
return true if !determine_class(record)
|
return true if !determine_class(record)
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
|
|
||||||
def backend_class(record)
|
def backend_class(record, *_args)
|
||||||
"Import::OTRS::History::#{determine_class(record)}".constantize
|
"Import::OTRS::History::#{determine_class(record)}".constantize
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ module Import
|
||||||
# rubocop:disable Style/ModuleFunction
|
# rubocop:disable Style/ModuleFunction
|
||||||
extend self
|
extend self
|
||||||
|
|
||||||
def pre_import_hook(_records)
|
def pre_import_hook(_records, *_args)
|
||||||
backup
|
backup
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ module Import
|
||||||
# rubocop:disable Style/ModuleFunction
|
# rubocop:disable Style/ModuleFunction
|
||||||
extend self
|
extend self
|
||||||
|
|
||||||
def import(settings)
|
def import(settings, *_args)
|
||||||
settings.each do |setting|
|
settings.each do |setting|
|
||||||
next if direct_copy?(setting)
|
next if direct_copy?(setting)
|
||||||
next if number_generator?(setting)
|
next if number_generator?(setting)
|
||||||
|
|
|
@ -5,9 +5,9 @@ module Import
|
||||||
# rubocop:disable Style/ModuleFunction
|
# rubocop:disable Style/ModuleFunction
|
||||||
extend self
|
extend self
|
||||||
|
|
||||||
def import(records)
|
def import(records, *args)
|
||||||
ActiveRecord::Base.transaction do
|
ActiveRecord::Base.transaction do
|
||||||
import_action(records)
|
import_action(records, *args)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -8,7 +8,7 @@ module Import
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def import_loop(records, &import_block)
|
def import_loop(records, *_args, &import_block)
|
||||||
records.all!(&import_block)
|
records.all!(&import_block)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -17,7 +17,7 @@ module Import
|
||||||
# rubocop:disable Style/ModuleFunction
|
# rubocop:disable Style/ModuleFunction
|
||||||
extend self
|
extend self
|
||||||
|
|
||||||
def skip?(field)
|
def skip?(field, *_args)
|
||||||
# check if the Ticket object already has a same named column / attribute
|
# check if the Ticket object already has a same named column / attribute
|
||||||
# so we want to skip instead of importing it
|
# so we want to skip instead of importing it
|
||||||
Ticket.column_names.include?( local_attribute(field) )
|
Ticket.column_names.include?( local_attribute(field) )
|
||||||
|
|
Loading…
Reference in a new issue