Class: Ecoportal::API::GraphQL::Logic::Connection
- Inherits:
-
Logic::BaseModel
- Object
- Logic::BaseModel
- Ecoportal::API::GraphQL::Logic::Connection
- Includes:
- Enumerable
- Defined in:
- lib/ecoportal/api/graphql/logic/connection.rb
Direct Known Subclasses
Connection::Action, Connection::ActionCategory, Connection::Activity, Connection::ActivityLog, Connection::AuthLog, Connection::ContractorEntity, Connection::MinimalDashboard, Connection::Page, Connection::PagesWorkflowCommand, Connection::PersonMemberChangelog, Connection::PersonMemberConnection, Connection::PresetView, Connection::PreviewPage
Defined Under Namespace
Classes: GenericNode
Class Method Summary collapse
-
.nodes_of(klass) ⇒ Object
Bind a connection subclass to its concrete node type.
Instance Method Summary collapse
Class Method Details
.nodes_of(klass) ⇒ Object
Bind a connection subclass to its concrete node type.
The base embeds_many :nodes, klass: :node_class builds a SINGLE dynamic
CollectionModel ("nodes::node_class") that every subclass inherits and shares.
The v2 collection layer memoizes the resolved class on that shared collection
(items_klass.rb:62-63), so the FIRST connection instantiated in a process poisons
every other connection's instance nodes typing (e.g. a MinimalDashboard connection
returning AuthLog nodes). Declaring embeds_many :nodes per subclass with the concrete
class gives each subclass its OWN collection ("nodes::Model::X") bound to a real Class —
no shared symbol, nothing to memoize wrongly.
Use nodes_of Model::X in a subclass instead of class_resolver :node_class, Model::X.
33 34 35 36 |
# File 'lib/ecoportal/api/graphql/logic/connection.rb', line 33 def self.nodes_of(klass) class_resolver :node_class, klass :nodes, klass: klass end |
Instance Method Details
#each(&block) ⇒ Object
42 43 44 45 46 |
# File 'lib/ecoportal/api/graphql/logic/connection.rb', line 42 def each(&block) return to_enum(:each) unless block nodes.each(&block) end |
#empty? ⇒ Boolean
38 39 40 |
# File 'lib/ecoportal/api/graphql/logic/connection.rb', line 38 def empty? count < 1 end |