class BloodContracts::Instrumentation::Session

Basic class to hold data about matching process Start date, finish date, result type name and the validation context

Constants

NO_SCOPE

Session scope fallback

NO_TYPE_MATCH

Session result type name fallback

NO_VALIDATION_PATH

Session validation path fallback

Attributes

context[R]

Frozen hash of matching pipeline context

@return [Hash]

extras[R]

Additional data for instrumentaion stores here

@return [Hash]

finished_at[R]

Time when session finished

@return [Time]

id[R]

Unique ID of the session

@return [String]

matcher_type_name[R]

Name of the type which owns the session

@return [String]

path[R]

List of matches in the pipeline run

@return [Array<String>]

result_type_name[R]

Name of the matching result type

@return [String]

scope[R]

Additional text about scope of the mathc (e.g. “User:12”)

@return [String]

started_at[R]

Time when session started

@return [Time]

Public Class Methods

new(type_name) click to toggle source

Initialize the session with matcher type name with defaults

@param type_name [String] name of the type which owns the session

@return [Nothing]

# File lib/blood_contracts/instrumentation/session.rb, line 76
def initialize(type_name)
  @id = SecureRandom.hex(10)
  @matcher_type_name = type_name
  @extras = {}
  @context = {}
end

Public Instance Methods

finish(type_match) click to toggle source

Marks the session as finished (with the type) If you inherit the Session this method runs right AFTER matching finished (even if an exception raised the method would be called)

@param type_match [BC::Refined] result type of matching pipeline

@return [Nothing]

# File lib/blood_contracts/instrumentation/session.rb, line 109
def finish(type_match)
  @finished_at = Time.now
  @context = type_match.context.dup.freeze if type_match
  @valid = type_match&.valid?

  @result_type_name = type_match&.class&.name || NO_TYPE_MATCH
  @id =    @context.fetch(:session_id) { @id }
  @scope = @context.fetch(:scope) { NO_SCOPE }
  @path =  @context.fetch(:steps) { NO_VALIDATION_PATH }
end
start() click to toggle source

Marks the session as started If you inherit the Session this method runs right BEFORE matching start

@return [Nothing]

# File lib/blood_contracts/instrumentation/session.rb, line 88
def start
  @started_at = Time.now
end
valid?() click to toggle source

Whether the result was valid or not

@return [Boolean]

# File lib/blood_contracts/instrumentation/session.rb, line 66
def valid?
  !!@valid
end