Class: EcsRails::Registry::Declaration
- Inherits:
-
Object
- Object
- EcsRails::Registry::Declaration
- Defined in:
- lib/ecs_rails/registry.rb
Overview
One component Foo declaration on one entity class.
A value object over names. #entity_class / #component_class resolve on every call, so a Declaration handed out before a reload still resolves to the post-reload constants.
Instance Attribute Summary collapse
-
#component_class_name ⇒ String
readonly
The declared component’s class name.
-
#entity_class_name ⇒ String
readonly
The declaring entity’s class name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
(also: #eql?)
True if both declare the same component on the same entity with the same options.
-
#component_class ⇒ Class<EcsRails::Component>
Resolved live, so a reloaded constant is picked up.
-
#entity_class ⇒ Class<EcsRails::Entity>
Resolved live, so a reloaded constant is picked up.
-
#hash ⇒ Integer
A hash consistent with #==, so Declarations work as Hash keys and in Sets.
-
#initialize(entity_class_name:, component_class_name:, options: {}) ⇒ Declaration
constructor
A new instance of Declaration.
-
#inspect ⇒ String
E.g.
Constructor Details
#initialize(entity_class_name:, component_class_name:, options: {}) ⇒ Declaration
Returns a new instance of Declaration.
40 41 42 43 44 45 |
# File 'lib/ecs_rails/registry.rb', line 40 def initialize(entity_class_name:, component_class_name:, options: {}) @entity_class_name = entity_class_name @component_class_name = component_class_name @options = .dup.freeze freeze end |
Instance Attribute Details
#component_class_name ⇒ String (readonly)
Returns the declared component’s class name.
35 |
# File 'lib/ecs_rails/registry.rb', line 35 attr_reader :entity_class_name, :component_class_name, :options |
#entity_class_name ⇒ String (readonly)
Returns the declaring entity’s class name.
35 36 37 |
# File 'lib/ecs_rails/registry.rb', line 35 def entity_class_name @entity_class_name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
35 |
# File 'lib/ecs_rails/registry.rb', line 35 attr_reader :entity_class_name, :component_class_name, :options |
Instance Method Details
#==(other) ⇒ Boolean Also known as: eql?
Returns true if both declare the same component on the same entity with the same options.
66 67 68 69 70 71 |
# File 'lib/ecs_rails/registry.rb', line 66 def ==(other) other.is_a?(Declaration) && entity_class_name == other.entity_class_name && component_class_name == other.component_class_name && == other. end |
#component_class ⇒ Class<EcsRails::Component>
Resolved live, so a reloaded constant is picked up.
59 60 61 |
# File 'lib/ecs_rails/registry.rb', line 59 def component_class component_class_name.constantize end |
#entity_class ⇒ Class<EcsRails::Entity>
Resolved live, so a reloaded constant is picked up.
51 52 53 |
# File 'lib/ecs_rails/registry.rb', line 51 def entity_class entity_class_name.constantize end |
#hash ⇒ Integer
Returns a hash consistent with #==, so Declarations work as Hash keys and in Sets.
76 77 78 |
# File 'lib/ecs_rails/registry.rb', line 76 def hash [self.class, entity_class_name, component_class_name, ].hash end |
#inspect ⇒ String
Returns e.g. #<...Declaration User => Email {}>.
81 82 83 |
# File 'lib/ecs_rails/registry.rb', line 81 def inspect "#<#{self.class} #{entity_class_name} => #{component_class_name} #{.inspect}>" end |