Class: Textus::Application::Context

Inherits:
Data
  • Object
show all
Defined in:
lib/textus/application/context.rb

Overview

A Context describes the call: who is acting (role), what request this is part of (correlation_id), what time it is (now), and whether writes should be suppressed (dry_run).

Collaborators (manifest, file_store, bus, audit log, authorizer) are never read from Context — use cases pull them from a Caps record (Read/Write/Hook) that Session derives from the Store.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#correlation_idObject (readonly)

Returns the value of attribute correlation_id

Returns:

  • (Object)

    the current value of correlation_id



12
13
14
# File 'lib/textus/application/context.rb', line 12

def correlation_id
  @correlation_id
end

#dry_runObject (readonly)

Returns the value of attribute dry_run

Returns:

  • (Object)

    the current value of dry_run



12
13
14
# File 'lib/textus/application/context.rb', line 12

def dry_run
  @dry_run
end

#nowObject (readonly)

Returns the value of attribute now

Returns:

  • (Object)

    the current value of now



12
13
14
# File 'lib/textus/application/context.rb', line 12

def now
  @now
end

#roleObject (readonly)

Returns the value of attribute role

Returns:

  • (Object)

    the current value of role



12
13
14
# File 'lib/textus/application/context.rb', line 12

def role
  @role
end

Class Method Details

.build(role:, correlation_id: nil, now: nil, dry_run: false) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/textus/application/context.rb', line 13

def self.build(role:, correlation_id: nil, now: nil, dry_run: false)
  new(
    role: role.to_s,
    correlation_id: correlation_id || SecureRandom.uuid,
    now: now || Time.now,
    dry_run: dry_run,
  )
end

Instance Method Details

#dry_run?Boolean

Returns:

  • (Boolean)


22
# File 'lib/textus/application/context.rb', line 22

def dry_run? = dry_run

#with_role(new_role) ⇒ Object



24
25
26
27
28
29
30
31
# File 'lib/textus/application/context.rb', line 24

def with_role(new_role)
  self.class.new(
    role: new_role.to_s,
    correlation_id: correlation_id,
    now: now,
    dry_run: dry_run,
  )
end