Class: BloodContracts::Instrumentation::Session
- Inherits:
-
Object
- Object
- BloodContracts::Instrumentation::Session
- Defined in:
- lib/blood_contracts/instrumentation/session.rb
Overview
Basic class to hold data about matching process Start date, finish date, result type name and the validation context
Constant Summary collapse
- NO_SCOPE =
Session scope fallback
"unscoped"
- NO_VALIDATION_PATH =
Session validation path fallback
"undefined"
- NO_TYPE_MATCH =
Session result type name fallback
"unmatched"
Instance Attribute Summary collapse
-
#context ⇒ Hash
readonly
Frozen hash of matching pipeline context.
-
#extras ⇒ Hash
readonly
Additional data for instrumentaion stores here.
-
#finished_at ⇒ Time
readonly
Time when session finished.
-
#id ⇒ String
readonly
Unique ID of the session.
-
#matcher_type_name ⇒ String
readonly
Name of the type which owns the session.
-
#path ⇒ Array<String>
readonly
List of matches in the pipeline run.
-
#result_type_name ⇒ String
readonly
Name of the matching result type.
-
#scope ⇒ String
readonly
Additional text about scope of the mathc (e.g. “User:12”).
-
#started_at ⇒ Time
readonly
Time when session started.
Instance Method Summary collapse
-
#finish(type_match) ⇒ Nothing
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).
-
#initialize(type_name) ⇒ Nothing
constructor
Initialize the session with matcher type name with defaults.
-
#start ⇒ Nothing
Marks the session as started If you inherit the Session this method runs right BEFORE matching start.
-
#valid? ⇒ Boolean
Whether the result was valid or not.
Constructor Details
#initialize(type_name) ⇒ Nothing
Initialize the session with matcher type name with defaults
76 77 78 79 80 81 |
# 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 |
Instance Attribute Details
#context ⇒ Hash (readonly)
Frozen hash of matching pipeline context
30 31 32 |
# File 'lib/blood_contracts/instrumentation/session.rb', line 30 def context @context end |
#extras ⇒ Hash (readonly)
Additional data for instrumentaion stores here
60 61 62 |
# File 'lib/blood_contracts/instrumentation/session.rb', line 60 def extras @extras end |
#finished_at ⇒ Time (readonly)
Time when session finished
24 25 26 |
# File 'lib/blood_contracts/instrumentation/session.rb', line 24 def finished_at @finished_at end |
#id ⇒ String (readonly)
Unique ID of the session
12 13 14 |
# File 'lib/blood_contracts/instrumentation/session.rb', line 12 def id @id end |
#matcher_type_name ⇒ String (readonly)
Name of the type which owns the session
42 43 44 |
# File 'lib/blood_contracts/instrumentation/session.rb', line 42 def matcher_type_name @matcher_type_name end |
#path ⇒ Array<String> (readonly)
List of matches in the pipeline run
54 55 56 |
# File 'lib/blood_contracts/instrumentation/session.rb', line 54 def path @path end |
#result_type_name ⇒ String (readonly)
Name of the matching result type
48 49 50 |
# File 'lib/blood_contracts/instrumentation/session.rb', line 48 def result_type_name @result_type_name end |
#scope ⇒ String (readonly)
Additional text about scope of the mathc (e.g. “User:12”)
36 37 38 |
# File 'lib/blood_contracts/instrumentation/session.rb', line 36 def scope @scope end |
#started_at ⇒ Time (readonly)
Time when session started
18 19 20 |
# File 'lib/blood_contracts/instrumentation/session.rb', line 18 def started_at @started_at end |
Instance Method Details
#finish(type_match) ⇒ Nothing
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)
109 110 111 112 113 114 115 116 117 118 |
# 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 ⇒ Nothing
Marks the session as started If you inherit the Session this method runs right BEFORE matching start
88 89 90 |
# File 'lib/blood_contracts/instrumentation/session.rb', line 88 def start @started_at = Time.now end |
#valid? ⇒ Boolean
Whether the result was valid or not
66 67 68 |
# File 'lib/blood_contracts/instrumentation/session.rb', line 66 def valid? !!@valid end |