Module: Hecks::Bluebook::Behaviour::Indexed
- Included in:
- Aggregate, Command, Entity, PortOperation
- Defined in:
- lib/hecks/bluebook/behaviour/traits.rb
Overview
A CONSTRUCT THAT ANSWERS FOR ITS OWN DECLARATIONS BY NAME.
Indexed once, since the declarations are final by the time the construct exists — every dispatch asks these finders by name, and a linear scan repeated on every call was doing work the declared shape had already settled at boot.
index_by_name takes the collections to index rather than naming
them, because WHICH collections a construct has is exactly the part
that differs: an aggregate has five, an entity three, a command one.
Instance Method Summary collapse
- #attribute(named) ⇒ Object
- #command(named) ⇒ Object
-
#index_attributes(attributes) ⇒ Object
Keyed by SYMBOL — an attribute is asked for by its declared symbol name everywhere in the runtime.
-
#index_by_hecks_name(collection) ⇒ Object
Keyed by STRING and by
hecks_name— a command, query or value object is a construct whose Rubynameis something else entirely (a constant path, or nothing at all for an anonymous class), so the DECLARED name is the only one worth indexing. - #query(named) ⇒ Object
Instance Method Details
#attribute(named) ⇒ Object
63 |
# File 'lib/hecks/bluebook/behaviour/traits.rb', line 63 def attribute(named) = @attributes_by_name[named.to_sym] |
#command(named) ⇒ Object
64 |
# File 'lib/hecks/bluebook/behaviour/traits.rb', line 64 def command(named) = @commands_by_name[named.to_s] |
#index_attributes(attributes) ⇒ Object
Keyed by SYMBOL — an attribute is asked for by its declared symbol name everywhere in the runtime.
51 52 53 |
# File 'lib/hecks/bluebook/behaviour/traits.rb', line 51 def index_attributes(attributes) @attributes_by_name = attributes.to_h { |held| [held.name, held] } end |
#index_by_hecks_name(collection) ⇒ Object
Keyed by STRING and by hecks_name — a command, query or value
object is a construct whose Ruby name is something else
entirely (a constant path, or nothing at all for an anonymous
class), so the DECLARED name is the only one worth indexing.
59 60 61 |
# File 'lib/hecks/bluebook/behaviour/traits.rb', line 59 def index_by_hecks_name(collection) collection.to_h { |held| [held.hecks_name, held] } end |
#query(named) ⇒ Object
65 |
# File 'lib/hecks/bluebook/behaviour/traits.rb', line 65 def query(named) = @queries_by_name[named.to_s] |