Module: EcsRails

Defined in:
lib/ecs_rails.rb,
lib/ecs_rails/dsl.rb,
lib/ecs_rails/lazy.rb,
lib/ecs_rails/config.rb,
lib/ecs_rails/entity.rb,
lib/ecs_rails/errors.rb,
lib/ecs_rails/railtie.rb,
lib/ecs_rails/version.rb,
lib/ecs_rails/presence.rb,
lib/ecs_rails/querying.rb,
lib/ecs_rails/registry.rb,
lib/ecs_rails/component.rb,
lib/ecs_rails/preloading.rb,
lib/ecs_rails/validations.rb,
lib/ecs_rails/relationships.rb,
lib/generators/ecs_rails/install/install_generator.rb,
lib/generators/ecs_rails/component/component_generator.rb,
lib/generators/ecs_rails/relationship/relationship_generator.rb

Overview

ECS Rails — an Entity-Component-System reimagining of ActiveRecord.

Replaces one-table-per-model with one-table-per-component. An Entity is a lightweight identity row; all state and behaviour live in small, reusable Components composed onto it.

The gem is published as ecs_on_rails, but the require path and module are ecs_rails / EcsRails — see the README for why.

Examples:

Composing an entity from components

class User < ApplicationEntity
  component Name
  component Email
  component Moderator        # a marker: no data, presence is the meaning
end

user = User.create!          # one row in `entities`, no component rows
user.email                   # => #<Email> — virtual, not persisted
user.email.address = "a@b.com"
user.save!                   # now `emails` gets a row

See Also:

Defined Under Namespace

Modules: DSL, Generators, Lazy, Preloading, Presence, Querying, Relationships, Validations Classes: Component, Config, DelegationConflict, DuplicateComponent, Entity, Error, InvalidComponent, InvalidRelationship, Railtie, Registry

Constant Summary collapse

VERSION =

The gem version. Published on RubyGems as ecs_on_rails.

Returns:

  • (String)

    the semantic version, e.g. "0.2.2"

"0.2.2"

Class Method Summary collapse

Class Method Details

.configEcsRails::Config

The process-wide generator configuration (ADR-0010). Layout only — the runtime does not consult it; the generators and the initializer they emit do.

Returns:

See Also:

  • #configure


70
71
72
# File 'lib/ecs_rails.rb', line 70

def config
  @config ||= Config.new
end

.configure {|config| ... } ⇒ EcsRails::Config

Yields the config for block-style setup, as a host app’s config/initializers/ecs_rails.rb does.

Examples:

Restoring the pre-ADR-0010 single-directory layout

EcsRails.configure { |config| config.entities_path = "app/models" }

Yield Parameters:

Returns:



82
83
84
# File 'lib/ecs_rails.rb', line 82

def configure
  yield config
end

.registryEcsRails::Registry

The process-wide component registry, populated by the EcsRails::DSL#component DSL at class-load time.

Keyed by class name rather than class object, so it survives Rails reloading (RFC-0002).

Returns:

See Also:



60
61
62
# File 'lib/ecs_rails.rb', line 60

def registry
  @registry ||= Registry.new
end