feat(nexxa): estado en su Postgres propio con Nexxa::Estado (motores archivo|pg), mutar atómico y dispensa en un paso; 1.7.0 (P335/F17)
Tests ADN / test (push) Canceled after 0s

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Co-Authored-By: GEMMA <noreply@gemma.dtic>
This commit is contained in:
Ricardo Monla
2026-10-05 02:37:26 -03:00
co-authored by Claude Opus 5.5 GEMMA
parent 4df538283f
commit 84d51ed669
13 changed files with 904 additions and 270 deletions
+17 -15
View File
@@ -11,35 +11,37 @@
require 'json'
require 'time'
require_relative 'lib_estado'
module Nexxa
module Checkins
STATE_FILE = File.expand_path('checkins.json', __dir__).freeze
STATE_FILE = Estado.ruta('checkins')
# Estado vía Nexxa::Estado (P335/Fase 17)
def self.leer
return {} unless File.exist?(STATE_FILE)
JSON.parse(File.read(STATE_FILE))
rescue JSON::ParserError
{}
Estado.leer('checkins', STATE_FILE, {})
end
def self.guardar(state)
File.write(STATE_FILE, JSON.pretty_generate(state) + "\n")
File.chmod(0o600, STATE_FILE)
Estado.guardar('checkins', STATE_FILE, state)
end
def self.mutar(&)
Estado.mutar('checkins', STATE_FILE, {}, &)
end
# El individuo llega autenticado (individuo_autenticado(req) en server.rb,
# vía Nexxa::Tokens.verificar) — nunca confiar en un id que venga en el
# body, el token YA identifica quién reporta.
def self.registrar(individuo, estado:, detalle: nil)
state = leer
state[individuo] = {
'estado' => estado.to_s,
'detalle' => detalle,
'ultimo_reporte' => Time.now.utc.iso8601
}
guardar(state)
mutar do |state|
state[individuo] = {
'estado' => estado.to_s,
'detalle' => detalle,
'ultimo_reporte' => Time.now.utc.iso8601
}
state
end
state[individuo]
end