File: reset_class_variables.rb

package info (click to toggle)
ruby-celluloid 0.18.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 848 kB
  • sloc: ruby: 7,579; makefile: 10
file content (31 lines) | stat: -rw-r--r-- 854 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
module Specs
  class << self
    def reset_class_variables(description)
      # build uuid from example ending (most unique)
      uuid_prefix = description[-[description.size, 20].min..-1]
      reset_uuid(uuid_prefix)

      reset_probe(Queue.new)
      yield
      reset_probe(nil)
    end

    def reset_probe(value)
      # !!! DO NOT INTRODUCE ADDITIONAL GLOBAL VARIABLES !!!
      # rubocop:disable Style/GlobalVars
      $CELLULOID_MONITORING = !value.nil?
      # rubocop:enable Style/GlobalVars

      replace_const(Celluloid::Probe, :EVENTS_BUFFER, value)
    end

    def reset_uuid(uuid_prefix)
      replace_const(Celluloid::Internals::UUID, :PREFIX, uuid_prefix)
    end

    def replace_const(klass, const, value)
      klass.send(:remove_const, const) if klass.const_defined?(const)
      klass.const_set(const, value)
    end
  end
end