statistical_factory.rb 773 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. module Import
  2. module StatisticalFactory
  3. include Import::Factory
  4. # rubocop:disable Style/ModuleFunction
  5. extend self
  6. attr_reader :statistics
  7. def import(records, *args)
  8. super
  9. end
  10. def reset_statistics
  11. @statistics = {
  12. skipped: 0,
  13. created: 0,
  14. updated: 0,
  15. unchanged: 0,
  16. failed: 0,
  17. deactivated: 0,
  18. }
  19. end
  20. def pre_import_hook(_records, *_args)
  21. reset_statistics if @statistics.blank?
  22. end
  23. def post_import_hook(_record, backend_instance, *_args)
  24. add_to_statistics(backend_instance)
  25. end
  26. def add_to_statistics(backend_instance)
  27. action = backend_instance.action
  28. @statistics[action] += 1
  29. end
  30. end
  31. end