Refactoring: Splitted up instance_action statistics diff for different usages.

This commit is contained in:
Thorsten Eckel 2017-09-01 14:07:42 +02:00
parent 00f0bd8212
commit ab0e64d3a9
5 changed files with 62 additions and 17 deletions

View file

@ -1,4 +1,4 @@
require 'sequencer/unit/import/common/model/statistics/mixin/diff'
require 'sequencer/unit/import/common/model/statistics/mixin/instance_action_diff'
class Sequencer
class Unit
@ -7,7 +7,7 @@ class Sequencer
module Model
module Statistics
class Diff < Sequencer::Unit::Base
include ::Sequencer::Unit::Import::Common::Model::Statistics::Mixin::Diff
include ::Sequencer::Unit::Import::Common::Model::Statistics::Mixin::InstanceActionDiff
def process
state.provide(:statistics_diff, diff)

View file

@ -0,0 +1,29 @@
class Sequencer
class Unit
module Import
module Common
module Model
module Statistics
module Mixin
module Common
private
def actions
%i[skipped created updated unchanged failed deactivated]
end
def empty_diff
possible_actions.collect { |key| [key, 0] }.to_h
end
def possible_actions
@possible_actions ||= actions
end
end
end
end
end
end
end
end
end

View file

@ -0,0 +1,25 @@
require 'sequencer/unit/import/common/model/statistics/mixin/common'
class Sequencer
class Unit
module Import
module Common
module Model
module Statistics
module Mixin
module EmptyDiff
include Sequencer::Unit::Import::Common::Model::Statistics::Mixin::Common
def self.included(base)
base.provides :statistics_diff
end
alias diff empty_diff
end
end
end
end
end
end
end
end

View file

@ -1,3 +1,5 @@
require 'sequencer/unit/import/common/model/statistics/mixin/common'
class Sequencer
class Unit
module Import
@ -5,7 +7,8 @@ class Sequencer
module Model
module Statistics
module Mixin
module Diff
module InstanceActionDiff
include Sequencer::Unit::Import::Common::Model::Statistics::Mixin::Common
def self.included(base)
base.uses :instance_action
@ -14,13 +17,9 @@ class Sequencer
private
def actions
%i[skipped created updated unchanged failed deactivated]
end
def diff
raise "Unknown action '#{instance_action}'" if !possible?
defaults.merge(
empty_diff.merge(
instance_action => 1,
sum: 1,
)
@ -29,14 +28,6 @@ class Sequencer
def possible?
possible_actions.include?(instance_action)
end
def defaults
possible_actions.collect { |key| [key, 0] }.to_h
end
def possible_actions
@possible_actions ||= actions
end
end
end
end

View file

@ -5,7 +5,7 @@ class Sequencer
module FolderContact
module Statistics
class Diff < Sequencer::Unit::Base
include ::Sequencer::Unit::Import::Common::Model::Statistics::Mixin::Diff
include ::Sequencer::Unit::Import::Common::Model::Statistics::Mixin::InstanceActionDiff
uses :ews_folder_name