Class: Textus::Application::Context

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(store:, role:, correlation_id: nil, clock: Time, dry_run: false, bypass_freshness: false) ⇒ Context

Returns a new instance of Context.



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

def initialize(store:, role:, correlation_id: nil, clock: Time, dry_run: false, bypass_freshness: false)
  @store             = store
  @role              = role.to_s
  @correlation_id    = correlation_id || SecureRandom.uuid
  @clock             = clock
  @dry_run           = dry_run
  @bypass_freshness  = bypass_freshness
  @now               = nil
end

Instance Attribute Details

#correlation_idObject (readonly)

Returns the value of attribute correlation_id.



6
7
8
# File 'lib/textus/application/context.rb', line 6

def correlation_id
  @correlation_id
end

#roleObject (readonly)

Returns the value of attribute role.



6
7
8
# File 'lib/textus/application/context.rb', line 6

def role
  @role
end

#storeObject (readonly)

Returns the value of attribute store.



6
7
8
# File 'lib/textus/application/context.rb', line 6

def store
  @store
end

Class Method Details

.system(store) ⇒ Object



8
9
10
# File 'lib/textus/application/context.rb', line 8

def self.system(store)
  new(store: store, role: "human")
end

Instance Method Details

#bypass_freshness?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/textus/application/context.rb', line 30

def bypass_freshness?
  @bypass_freshness
end

#can_read?(zone) ⇒ Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/textus/application/context.rb', line 38

def can_read?(zone)
  store.manifest.permission_for(zone.to_s).allows_read?(role)
end

#can_write?(zone) ⇒ Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/textus/application/context.rb', line 34

def can_write?(zone)
  store.manifest.permission_for(zone.to_s).allows_write?(role)
end

#dry_run?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/textus/application/context.rb', line 26

def dry_run?
  @dry_run
end

#nowObject



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

def now
  @now ||= @clock.now
end

#with_role(new_role) ⇒ Object



42
43
44
45
46
47
48
49
50
51
# File 'lib/textus/application/context.rb', line 42

def with_role(new_role)
  self.class.new(
    store: @store,
    role: new_role,
    correlation_id: @correlation_id,
    clock: @clock,
    dry_run: @dry_run,
    bypass_freshness: @bypass_freshness,
  )
end