Module: Pace::Mock

Defined in:
lib/pace/mock.rb

Class Method Summary collapse

Class Method Details

.disableObject



53
54
55
56
57
58
59
60
61
# File 'lib/pace/mock.rb', line 53

def self.disable
  Pace.logger.info "Disabling Pace mock"

  Pace::Worker.class_eval do
    if instance_methods.include?(:start_without_mock)
      alias :start :start_without_mock
    end
  end
end

.enableObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/pace/mock.rb', line 26

def self.enable
  Pace.logger.info "Enabling Pace mock"

  Pace::Worker.class_eval do
    if instance_methods.include?(:start_with_mock)
      alias :start :start_with_mock
    else
      def start_with_mock(&block)
        jobs = nil

        EM.run do
          @redis = EM::Protocols::Redis.connect(@options)
          @redis.lrange(queue, 0, -1) do |jobs|
            jobs.each do |job|
              block.call JSON.parse(job)
            end
            @redis.del(queue) { EM.stop_event_loop }
          end
        end
      end

      alias :start_without_mock :start
      alias :start :start_with_mock
    end
  end
end