Class: Textus::Handlers::Write::ProposeEntry

Inherits:
Object
  • Object
show all
Defined in:
lib/textus/handlers/write/propose_entry.rb

Instance Method Summary collapse

Constructor Details

#initialize(container:) ⇒ ProposeEntry

Returns a new instance of ProposeEntry.



5
6
7
# File 'lib/textus/handlers/write/propose_entry.rb', line 5

def initialize(container:)
  @container = container
end

Instance Method Details

#call(command, call) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/textus/handlers/write/propose_entry.rb', line 9

def call(command, call)
  zone = @container.manifest.policy.propose_lane_for(call.role)
  unless zone
    return Value::Result.failure(:propose_forbidden,
                                 "role '#{call.role}' has no writable propose_lane",
                                 details: { "role" => call.role })
  end

  key = "#{zone}.#{command.key}"
  mentry = @container.manifest.resolver.resolve(key).entry
  writer = Store::Entry::Writer.from(container: @container, call: call)
  envelope = writer.put(
    key, mentry: mentry,
         payload: Textus::Value::Payload.new(meta: command.meta || {}, body: command.body, content: command.content)
  )
  Value::Result.success(envelope)
end