Class: EcsRails::Relationships::RelationshipMeta
- Inherits:
-
Struct
- Object
- Struct
- EcsRails::Relationships::RelationshipMeta
- 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
-
#backing_class_name ⇒ String
The dynamically defined backing component, e.g.
-
#foreign_key ⇒ Symbol
The FK on the backing component, e.g.
-
#name ⇒ Symbol
The relationship name, e.g.
-
#target_class_name ⇒ String
The entity pointed at, e.g.
Instance Method Summary collapse
-
#backing_class ⇒ Class<EcsRails::Component>
The backing component class.
-
#target_class ⇒ Class<EcsRails::Entity>
The entity this relationship points at.
Instance Attribute Details
#backing_class_name ⇒ String
Returns 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_key ⇒ Symbol
Returns 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 |
#name ⇒ Symbol
Returns 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_name ⇒ String
Returns 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_class ⇒ Class<EcsRails::Component>
Returns the backing component class.
94 95 96 |
# File 'lib/ecs_rails/relationships.rb', line 94 def backing_class backing_class_name.constantize end |
#target_class ⇒ Class<EcsRails::Entity>
Returns the entity this relationship points at.
100 101 102 |
# File 'lib/ecs_rails/relationships.rb', line 100 def target_class target_class_name.constantize end |