Module: Textus::Protocol::Handlers::Write

Includes:
Concern
Defined in:
lib/textus/protocol/handlers/write.rb

Class Method Summary collapse

Methods included from Concern

included, #response

Class Method Details

.data_mv(from:, to:, ctx:, call:, dry_run: false) ⇒ Object



51
52
53
# File 'lib/textus/protocol/handlers/write.rb', line 51

def data_mv(from:, to:, ctx:, call:, dry_run: false)
  Ops::DataMv.new.call(from:, to:, ctx:, dry_run:)
end

.delete(key:, ctx:, call:, if_etag: nil) ⇒ Object



15
16
17
18
# File 'lib/textus/protocol/handlers/write.rb', line 15

def delete(key:, ctx:, call:, if_etag: nil)
  ctx.delete(key:, if_etag:, call:)
  response(ok: true, key:, deleted: true)
end

.key_delete(key:, ctx:, call:, if_etag: nil) ⇒ Object



20
21
22
# File 'lib/textus/protocol/handlers/write.rb', line 20

def key_delete(key:, ctx:, call:, if_etag: nil)
  delete(key:, ctx:, call:, if_etag:)
end

.key_delete_prefix(prefix:, ctx:, call:, dry_run: false) ⇒ Object



42
43
44
45
46
47
48
49
# File 'lib/textus/protocol/handlers/write.rb', line 42

def key_delete_prefix(prefix:, ctx:, call:, dry_run: false)
  planner = Ops::BulkPlanner.new
  plan = planner.plan_delete(prefix:, ctx:)
  return plan.to_h if dry_run

  plan.steps.each { |s| delete(key: s["key"], ctx:, call:) }
  plan.to_h
end

.key_mv_prefix(from_prefix:, to_prefix:, ctx:, call:, dry_run: false) ⇒ Object



33
34
35
36
37
38
39
40
# File 'lib/textus/protocol/handlers/write.rb', line 33

def key_mv_prefix(from_prefix:, to_prefix:, ctx:, call:, dry_run: false)
  planner = Ops::BulkPlanner.new
  plan = planner.plan_mv(from_prefix:, to_prefix:, ctx:)
  return plan.to_h if dry_run

  plan.steps.each { |s| move(old_key: s["from"], new_key: s["to"], ctx:, call:) }
  plan.to_h
end

.move(old_key:, new_key:, ctx:, call:, if_etag: nil, dry_run: false) ⇒ Object



24
25
26
27
28
29
30
31
# File 'lib/textus/protocol/handlers/write.rb', line 24

def move(old_key:, new_key:, ctx:, call:, if_etag: nil, dry_run: false)
  mctx = ctx.move(from_key: old_key, to_key: new_key, call:, if_etag:, dry_run:)
  base = response(ok: true, from_key: mctx.from_key, to_key: mctx.to_key,
                  from_path: mctx.from_path, to_path: mctx.to_path)
  return base.merge("dry_run" => true) if mctx.dry_run

  base.merge("uid" => mctx.envelope.uid, "envelope" => mctx.envelope.to_h_for_wire)
end

.put(key:, ctx:, call:, meta: nil, if_etag: nil, format: nil, data: nil) ⇒ Object



9
10
11
12
13
# File 'lib/textus/protocol/handlers/write.rb', line 9

def put(key:, ctx:, call:, meta: nil, if_etag: nil, format: nil, data: nil)
  body, content = data.is_a?(Hash) ? [nil, data] : [data, nil]
  env = ctx.put(key:, meta: meta || {}, body:, content:, if_etag:, call:, format:)
  response(ok: true, key:, uid: env.uid, etag: env.etag)
end