class BloodContracts::Instrumentation::Session
Basic class to hold data about matching process Start date, finish date, result type name and the validation context
Constants
Attributes
Frozen hash of matching pipeline context
@return [Hash]
Additional data for instrumentaion stores here
@return [Hash]
Time when session finished
@return [Time]
Unique ID of the session
@return [String]
Name of the type which owns the session
@return [String]
List of matches in the pipeline run
@return [Array<String>]
Name of the matching result type
@return [String]
Additional text about scope of the mathc (e.g. “User:12”)
@return [String]
Time when session started
@return [Time]
Public Class Methods
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
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
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
Whether the result was valid or not
@return [Boolean]
# File lib/blood_contracts/instrumentation/session.rb, line 66 def valid? !!@valid end