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.
Class Method Summary collapse
Instance Method Summary collapse
- #audit_log ⇒ Object
- #authorize_read!(mentry) ⇒ Object
- #authorize_write!(mentry) ⇒ Object
- #bus ⇒ Object
- #can_read?(zone) ⇒ Boolean
- #can_write?(zone) ⇒ Boolean
- #dry_run? ⇒ Boolean
- #file_store ⇒ Object
-
#initialize(store:, role:, correlation_id: nil, clock: Time, dry_run: false) ⇒ Context
constructor
A new instance of Context.
- #manifest ⇒ Object
- #now ⇒ Object
- #schemas ⇒ 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.
12 13 14 15 16 17 18 19 |
# File 'lib/textus/application/context.rb', line 12 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 |
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
#audit_log ⇒ Object
44 |
# File 'lib/textus/application/context.rb', line 44 def audit_log = @store.audit_log |
#authorize_read!(mentry) ⇒ Object
53 54 55 56 57 58 59 |
# File 'lib/textus/application/context.rb', line 53 def (mentry) return if can_read?(mentry.zone) readers = @store.manifest.zone_readers[mentry.zone] readers = nil if readers == :all raise ReadForbidden.new(mentry.key, mentry.zone, readers: readers) end |
#authorize_write!(mentry) ⇒ Object
46 47 48 49 50 51 |
# File 'lib/textus/application/context.rb', line 46 def (mentry) return if can_write?(mentry.zone) writers = @store.manifest.zone_writers(mentry.zone) raise WriteForbidden.new(mentry.key, mentry.zone, writers: writers) end |
#bus ⇒ Object
37 38 39 |
# File 'lib/textus/application/context.rb', line 37 def bus @store.bus end |
#can_read?(zone) ⇒ Boolean
33 34 35 |
# File 'lib/textus/application/context.rb', line 33 def can_read?(zone) store.manifest.(zone.to_s).allows_read?(role) end |
#can_write?(zone) ⇒ Boolean
29 30 31 |
# File 'lib/textus/application/context.rb', line 29 def can_write?(zone) store.manifest.(zone.to_s).allows_write?(role) end |
#dry_run? ⇒ Boolean
25 26 27 |
# File 'lib/textus/application/context.rb', line 25 def dry_run? @dry_run end |
#file_store ⇒ Object
43 |
# File 'lib/textus/application/context.rb', line 43 def file_store = @store.file_store |
#manifest ⇒ Object
41 |
# File 'lib/textus/application/context.rb', line 41 def manifest = @store.manifest |
#now ⇒ Object
21 22 23 |
# File 'lib/textus/application/context.rb', line 21 def now @now ||= @clock.now end |
#schemas ⇒ Object
42 |
# File 'lib/textus/application/context.rb', line 42 def schemas = @store.schemas |
#with_role(new_role) ⇒ Object
61 62 63 64 65 66 67 68 69 |
# File 'lib/textus/application/context.rb', line 61 def with_role(new_role) self.class.new( store: @store, role: new_role, correlation_id: @correlation_id, clock: @clock, dry_run: @dry_run, ) end |