Module: EcsRails::Presence

Defined in:
lib/ecs_rails/presence.rb

Overview

Component presence as a first-class operation: add / has? / remove.

Implements RFC-0009, decided by ADR-0009. Surfaced by the demo: a marker component (Moderator, Administrator) carries no state, so it is never ecs_dirty? (ADR-0003 excludes entity_id as identity), and RFC-0006’s save cascade therefore never writes it. The natural path does nothing at all:

user.moderator # a virtual Moderator user.save! # writes no moderators row — a marker is never dirty user.moderator.persisted? # => false, forever

Presence cannot be inferred from lazy state (reading must stay free, RFC-0006) and a marker has nothing to dirty, so presence is its own verb:

user.add(Moderator) # persist the row now (idempotent, validated) user.has?(Moderator) # => true — a row exists user.moderator? # => the same question, per-component sugar (DSL) user.remove(Moderator) # destroy the row (idempotent)

These are useful for every component — has?(Email), remove(Avatar) — not just empty ones; a marker is simply the case where presence is the only state (ADR-0009). Mirrors Flecs’ add/has/remove vocabulary.

This module is the entity side. The <reader>? predicate is generated per component by the DSL, into generated_component_methods (see EcsRails::DSL#define_component_predicate); it is just has?(ThatComponent).

Defined Under Namespace

Modules: Entity