Module: EcsRails::Lazy

Defined in:
lib/ecs_rails/lazy.rb

Overview

Lazy / virtual components: a component costs nothing until it holds something.

Implements RFC-0006 and closes the gap RFC-0004 knowingly left in architecture.md §3 — entity.email now always returns an Email.

user = User.create!          # one INSERT, into entities. Nothing else.
user.email                   # => #<Email address: nil, verified: false>
user.email.persisted?        # => false        — no row, and none wanted
user.save!                   # still no emails row

user.email.address = "[email protected]"
user.save!                   # *now* one INSERT into emails

The whole feature is two questions: which component instance does the reader hand back (Entity#ecs_component), and does that instance deserve a row (Component#ecs_dirty?). Everything else here is bookkeeping in service of those two.

Defined Under Namespace

Modules: Component, Entity