Class: Textus::Application::Context
- Inherits:
-
Object
- Object
- Textus::Application::Context
- Defined in:
- lib/textus/application/context.rb
Instance Attribute Summary collapse
-
#correlation_id ⇒ Object
readonly
Returns the value of attribute correlation_id.
-
#role ⇒ Object
readonly
Returns the value of attribute role.
-
#store ⇒ Object
readonly
Returns the value of attribute store.
Instance Method Summary collapse
- #can_read?(zone) ⇒ Boolean
- #can_write?(zone) ⇒ Boolean
- #delete(key, **opts) ⇒ Object
- #dry_run? ⇒ Boolean
- #get(key) ⇒ Object
-
#initialize(store:, role:, correlation_id: nil, clock: Time, dry_run: false) ⇒ Context
constructor
A new instance of Context.
- #list ⇒ Object
- #now ⇒ Object
-
#put(key, **opts) ⇒ Object
Backward-compat for intake handlers receiving a Context (was Store::View) that call store.put/get/delete on it.
- #where ⇒ Object
- #with_role(new_role) ⇒ Object
Constructor Details
#initialize(store:, role:, correlation_id: nil, clock: Time, dry_run: false) ⇒ Context
Returns a new instance of Context.
8 9 10 11 12 13 14 15 |
# File 'lib/textus/application/context.rb', line 8 def initialize(store:, role:, correlation_id: nil, clock: Time, dry_run: false) @store = store @role = role.to_s @correlation_id = correlation_id || SecureRandom.uuid @clock = clock @dry_run = dry_run @now = nil end |
Instance Attribute Details
#correlation_id ⇒ Object (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 |
#role ⇒ Object (readonly)
Returns the value of attribute role.
6 7 8 |
# File 'lib/textus/application/context.rb', line 6 def role @role end |
#store ⇒ Object (readonly)
Returns the value of attribute store.
6 7 8 |
# File 'lib/textus/application/context.rb', line 6 def store @store end |
Instance Method Details
#can_read?(zone) ⇒ Boolean
29 30 31 |
# File 'lib/textus/application/context.rb', line 29 def can_read?(zone) store.manifest.(zone.to_s).allows_read?(role) end |
#can_write?(zone) ⇒ Boolean
25 26 27 |
# File 'lib/textus/application/context.rb', line 25 def can_write?(zone) store.manifest.(zone.to_s).allows_write?(role) end |
#delete(key, **opts) ⇒ Object
50 51 52 53 |
# File 'lib/textus/application/context.rb', line 50 def delete(key, **opts) opts[:as] ||= role store.delete(key, **opts) end |
#dry_run? ⇒ Boolean
21 22 23 |
# File 'lib/textus/application/context.rb', line 21 def dry_run? @dry_run end |
#get(key) ⇒ Object
55 56 57 |
# File 'lib/textus/application/context.rb', line 55 def get(key, **) store.get(key, **) end |
#list ⇒ Object
59 60 61 |
# File 'lib/textus/application/context.rb', line 59 def list(*, **) store.list(*, **) end |
#now ⇒ Object
17 18 19 |
# File 'lib/textus/application/context.rb', line 17 def now @now ||= @clock.now end |
#put(key, **opts) ⇒ Object
Backward-compat for intake handlers receiving a Context (was Store::View) that call store.put/get/delete on it. Slated for removal in 0.10.0.
45 46 47 48 |
# File 'lib/textus/application/context.rb', line 45 def put(key, **opts) opts[:as] ||= role store.put(key, **opts) end |
#where ⇒ Object
63 64 65 |
# File 'lib/textus/application/context.rb', line 63 def where(*, **) store.where(*, **) end |
#with_role(new_role) ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'lib/textus/application/context.rb', line 33 def with_role(new_role) self.class.new( store: @store, role: new_role, correlation_id: @correlation_id, clock: @clock, dry_run: @dry_run, ) end |