Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
process_host / lib / process_host / signal.rb
Size: Mime:
module ProcessHost
  module Signal
    def self.configure(receiver, attr_name: nil)
      attr_name ||= :signal

      receiver.public_send "#{attr_name}=", ::Signal
    end

    module Substitute
      def self.build
        Signal.new
      end

      class Signal
        def trap(signal, &handler)
          handlers[signal] = handler
        end

        def simulate_signal(signal)
          handler = handlers[signal]

          return if handler.nil?

          handler.()

          record = Record.new signal
          records << record
          record
        end

        def handlers
          @handlers ||= {}
        end

        def records
          @records ||= []
        end

        Record = Struct.new :signal

        module Assertions
          def trapped?(signal=nil)
            if signal.nil?
              records.any?
            else
              records.any? { |record| record.signal == signal }
            end
          end
        end
      end
    end
  end
end