diff --git a/lib/bookbinder/preprocessing/preprocessor.rb b/lib/bookbinder/preprocessing/preprocessor.rb index d2a0b61e1..733d8fe3d 100644 --- a/lib/bookbinder/preprocessing/preprocessor.rb +++ b/lib/bookbinder/preprocessing/preprocessor.rb @@ -1,14 +1,18 @@ module Bookbinder module Preprocessing class Preprocessor - def initialize(*processes, default: nil) + class NullProcess + def preprocess(*) + end + end + + def initialize(*processes) @processes = processes - @default = default end def preprocess(objs, *args, &block) objs.group_by { |obj| - processes.detect ->{ default } { |process| process.applicable_to?(obj) } + processes.detect ->{ NullProcess.new } { |process| process.applicable_to?(obj) } }.each do |process, objs| process.preprocess(objs, *args) end @@ -16,7 +20,7 @@ def preprocess(objs, *args, &block) private - attr_reader :processes, :default + attr_reader :processes end end end diff --git a/spec/lib/bookbinder/preprocessing/preprocessor_spec.rb b/spec/lib/bookbinder/preprocessing/preprocessor_spec.rb index e9892b26d..2b0e4abf9 100644 --- a/spec/lib/bookbinder/preprocessing/preprocessor_spec.rb +++ b/spec/lib/bookbinder/preprocessing/preprocessor_spec.rb @@ -25,7 +25,7 @@ module Preprocessing preprocessor.preprocess(objs, 'extra', 'args') end - it "applies the default process to objects that aren't applicable to any process" do + it "does nothing to objects that aren't applicable to any process" do objs = [ Object.new, Object.new, @@ -33,18 +33,15 @@ module Preprocessing Object.new, ] - process_1 = double('default process') - process_2 = double('some other process') + process_1 = double('some other process') + process_2 = double('second process') - preprocessor = Preprocessor.new(process_2, default: process_1) - - block = ->(*){} + preprocessor = Preprocessor.new(process_1, process_2) - allow(process_1).to receive(:applicable_to?) { false } - allow(process_2).to receive(:applicable_to?) { |obj| objs[2..3].include?(obj) } + allow(process_1).to receive(:applicable_to?) { |obj| objs[2..3].include?(obj) } + allow(process_2).to receive(:applicable_to?) { false } - expect(process_1).to receive(:preprocess).with(objs[0..1], 'extra', 'args') - expect(process_2).to receive(:preprocess).with(objs[2..3], 'extra', 'args') + expect(process_1).to receive(:preprocess).with(objs[2..3], 'extra', 'args') preprocessor.preprocess(objs, 'extra', 'args') end