Class: Julewire::Core::Execution::ScopeIdentity

Inherits:
Object
  • Object
show all
Defined in:
lib/julewire/core/execution/scope_identity.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type:, id: nil, started_at: nil, parent: nil, parent_reference: nil) ⇒ ScopeIdentity

Returns a new instance of ScopeIdentity.



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/julewire/core/execution/scope_identity.rb', line 11

def initialize(type:, id: nil, started_at: nil, parent: nil, parent_reference: nil)
  @id = normalize_id(id || SecureRandom.uuid)
  @type = normalize_type(type)
  @started_at = frozen_time(started_at || Time.now.utc)
  @started_monotonic = monotonic_time
  @parent = parent
  @reference = { type: @type, id: @id }.freeze
  @lineage = Lineage.new(
    reference: @reference,
    parent_lineage: parent&.lineage,
    parent_reference: parent_reference
  )
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



9
10
11
# File 'lib/julewire/core/execution/scope_identity.rb', line 9

def id
  @id
end

#lineageObject (readonly)

Returns the value of attribute lineage.



9
10
11
# File 'lib/julewire/core/execution/scope_identity.rb', line 9

def lineage
  @lineage
end

#parentObject (readonly)

Returns the value of attribute parent.



9
10
11
# File 'lib/julewire/core/execution/scope_identity.rb', line 9

def parent
  @parent
end

#referenceObject (readonly)

Returns the value of attribute reference.



9
10
11
# File 'lib/julewire/core/execution/scope_identity.rb', line 9

def reference
  @reference
end

#started_atObject (readonly)

Returns the value of attribute started_at.



9
10
11
# File 'lib/julewire/core/execution/scope_identity.rb', line 9

def started_at
  @started_at
end

#started_monotonicObject (readonly)

Returns the value of attribute started_monotonic.



9
10
11
# File 'lib/julewire/core/execution/scope_identity.rb', line 9

def started_monotonic
  @started_monotonic
end

#typeObject (readonly)

Returns the value of attribute type.



9
10
11
# File 'lib/julewire/core/execution/scope_identity.rb', line 9

def type
  @type
end

Instance Method Details

#depthObject



25
# File 'lib/julewire/core/execution/scope_identity.rb', line 25

def depth = @lineage.depth

#execution_fields(execution, owned:) ⇒ Object



27
28
29
30
31
32
# File 'lib/julewire/core/execution/scope_identity.rb', line 27

def execution_fields(execution, owned:)
  fields = owned ? Lineage.clean_owned_execution_hash(execution) : Lineage.clean_execution_hash(execution)
  fields[:type] = @type
  fields[:id] = @id
  fields
end

#frozen_execution_hash(execution) ⇒ Object



34
35
36
# File 'lib/julewire/core/execution/scope_identity.rb', line 34

def frozen_execution_hash(execution)
  @lineage.merge_into_frozen(execution)
end

#frozen_time(value) ⇒ Object



38
39
40
# File 'lib/julewire/core/execution/scope_identity.rb', line 38

def frozen_time(value)
  Serialization::ValueCopy.call(value, freeze_values: true)
end