Class: EcsRails::Relationships::RelationshipMeta

Inherits:
Struct
  • Object
show all
Defined in:
lib/ecs_rails/relationships.rb

Overview

One recorded relationship, held by NAME so it survives a Rails reload the same way the registry’s EcsRails::Registry::Declaration does (RFC-0002): #backing_class and #target_class resolve via constantize on read, so a metadata entry taken before a reload still resolves to the post-reload constants.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#backing_class_nameString

Returns the dynamically defined backing component, e.g. "Post::AuthorRelationship".

Returns:

  • (String)

    the dynamically defined backing component, e.g. "Post::AuthorRelationship"



91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/ecs_rails/relationships.rb', line 91

RelationshipMeta = Struct.new(:name, :backing_class_name, :foreign_key, :target_class_name) do
  # @return [Class<EcsRails::Component>] the backing component class
  # @raise [NameError] if the constant no longer exists
  def backing_class
    backing_class_name.constantize
  end

  # @return [Class<EcsRails::Entity>] the entity this relationship points at
  # @raise [NameError] if the constant no longer exists
  def target_class
    target_class_name.constantize
  end
end

#foreign_keySymbol

Returns the FK on the backing component, e.g. :author_id.

Returns:

  • (Symbol)

    the FK on the backing component, e.g. :author_id



91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/ecs_rails/relationships.rb', line 91

RelationshipMeta = Struct.new(:name, :backing_class_name, :foreign_key, :target_class_name) do
  # @return [Class<EcsRails::Component>] the backing component class
  # @raise [NameError] if the constant no longer exists
  def backing_class
    backing_class_name.constantize
  end

  # @return [Class<EcsRails::Entity>] the entity this relationship points at
  # @raise [NameError] if the constant no longer exists
  def target_class
    target_class_name.constantize
  end
end

#nameSymbol

Returns the relationship name, e.g. :author.

Returns:

  • (Symbol)

    the relationship name, e.g. :author



91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/ecs_rails/relationships.rb', line 91

RelationshipMeta = Struct.new(:name, :backing_class_name, :foreign_key, :target_class_name) do
  # @return [Class<EcsRails::Component>] the backing component class
  # @raise [NameError] if the constant no longer exists
  def backing_class
    backing_class_name.constantize
  end

  # @return [Class<EcsRails::Entity>] the entity this relationship points at
  # @raise [NameError] if the constant no longer exists
  def target_class
    target_class_name.constantize
  end
end

#target_class_nameString

Returns the entity pointed at, e.g. "User".

Returns:

  • (String)

    the entity pointed at, e.g. "User"



91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/ecs_rails/relationships.rb', line 91

RelationshipMeta = Struct.new(:name, :backing_class_name, :foreign_key, :target_class_name) do
  # @return [Class<EcsRails::Component>] the backing component class
  # @raise [NameError] if the constant no longer exists
  def backing_class
    backing_class_name.constantize
  end

  # @return [Class<EcsRails::Entity>] the entity this relationship points at
  # @raise [NameError] if the constant no longer exists
  def target_class
    target_class_name.constantize
  end
end

Instance Method Details

#backing_classClass<EcsRails::Component>

Returns the backing component class.

Returns:

Raises:

  • (NameError)

    if the constant no longer exists



94
95
96
# File 'lib/ecs_rails/relationships.rb', line 94

def backing_class
  backing_class_name.constantize
end

#target_classClass<EcsRails::Entity>

Returns the entity this relationship points at.

Returns:

Raises:

  • (NameError)

    if the constant no longer exists



100
101
102
# File 'lib/ecs_rails/relationships.rb', line 100

def target_class
  target_class_name.constantize
end