Module: BloodContracts::Instrumentation::SessionRecording

Defined in:
lib/blood_contracts/instrumentation/session_recording.rb

Overview

Prependable module for matching session recording

Defined Under Namespace

Modules: Inheritance, Match

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.prepended(other) ⇒ Object

Modifications in singleton class of BC::Refined

rubocop:disable Metrics/MethodLength

Parameters:

  • other (BC::Refined)

    class to enhance



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/blood_contracts/instrumentation/session_recording.rb', line 77

def self.prepended(other)
  class << other
    prepend Inheritance

    # Class to use as a session (writer)
    #
    # @return [Session]
    #
    attr_writer :session_klass

    # Class to use as a session
    # By default is set to Session
    #
    # @return [Session]
    #
    def session_klass
      @session_klass ||= Session
    end

    # Whether type anonymous or not
    #
    # @return [Boolean]
    #
    def anonymous?
      name.nil?
    end

    # List of instruments for the type
    #
    # @return [Array<Instrument>]
    #
    def instruments
      return @instruments if defined? @instruments

      reset_instruments!
    end

    # Alias for instruments reader
    # See #instruments
    alias setup_instruments instruments

    # Reset the List of instruments for the type
    # Note, that if list of instruments is empty there is no need to
    # init the session, so type is not prepended by Match wrapper
    #
    # @return [Array<Instrument>]
    #
    def reset_instruments!
      @instruments = Instrumentation.select_instruments(name)
    ensure
      prepend(Match) unless @instruments.empty?
    end
  end
end

Instance Method Details

#initializeObject

Adds @session initialization to constructor



8
9
10
11
12
# File 'lib/blood_contracts/instrumentation/session_recording.rb', line 8

def initialize(*)
  super
  self.class.instruments
  @session = self.class.session_klass.new(self.class.name)
end