Module: Spree::AgentTools::OperationCatalog
- Defined in:
- lib/spree/agent_tools/operation_catalog.rb
Overview
Every Admin API operation an agent may call by name, and what it takes.
A contract like ResourceMap: core declares the shape, and spree_api
fills it from the Admin API's OpenAPI document — core's and every
extension's — and the routes behind it. An operation that gains an
endpoint is a tool in the same commit, with the summary, description and
request body its rswag spec wrote.
See docs/plans/6.0-agent-tools-from-openapi.md.
Defined Under Namespace
Classes: Entry
Class Attribute Summary collapse
-
.deriver ⇒ #call?
How the catalog fills itself the first time it is read.
Class Method Summary collapse
-
.aliases ⇒ Array<Entry>
The 6.0.0 names kept callable through 6.0.x, which no listing shows.
-
.all ⇒ Array<Entry>
The operations offered by name.
-
.derive! ⇒ void
Fills the catalog once, under a mutex.
-
.find(name) ⇒ Entry?
A tool by its name, including a 6.0.0 name no longer listed.
-
.register(**attributes) ⇒ Entry
Registers one operation.
-
.register_alias(**attributes) ⇒ Entry?
Registers a 6.0.0 name for an operation, callable but not listed.
- .reset! ⇒ void
-
.stale! ⇒ void
Marks the catalog for rebuilding on its next read.
Class Attribute Details
.deriver ⇒ #call?
How the catalog fills itself the first time it is read. spree_api
sets it to its walk over the document; an installation without the
API engine has no operations to offer.
113 114 115 |
# File 'lib/spree/agent_tools/operation_catalog.rb', line 113 def deriver @deriver end |
Class Method Details
.aliases ⇒ Array<Entry>
The 6.0.0 names kept callable through 6.0.x, which no listing shows.
124 125 126 127 |
# File 'lib/spree/agent_tools/operation_catalog.rb', line 124 def aliases derive! alias_entries.values end |
.all ⇒ Array<Entry>
Returns the operations offered by name.
116 117 118 119 |
# File 'lib/spree/agent_tools/operation_catalog.rb', line 116 def all derive! entries.values end |
.derive! ⇒ void
This method returns an undefined value.
Fills the catalog once, under a mutex. The flag is set only once the deriver has finished, so a second reader waits on the mutex instead of reading a catalog the deriver has just emptied. Nothing the deriver calls reads the catalog back, so it cannot recurse.
175 176 177 178 179 180 181 182 183 184 |
# File 'lib/spree/agent_tools/operation_catalog.rb', line 175 def derive! return if @derived || deriver.nil? derive_mutex.synchronize do next if @derived deriver.call @derived = true end end |
.find(name) ⇒ Entry?
A tool by its name, including a 6.0.0 name no longer listed.
133 134 135 136 |
# File 'lib/spree/agent_tools/operation_catalog.rb', line 133 def find(name) derive! entries[name.to_s] || alias_entries[name.to_s] end |
.register(**attributes) ⇒ Entry
Registers one operation. Re-registering a name replaces it, because the walk runs again after a code reload.
142 143 144 145 |
# File 'lib/spree/agent_tools/operation_catalog.rb', line 142 def register(**attributes) entry = build(listed: true, **attributes) entries[entry.name] = entry end |
.register_alias(**attributes) ⇒ Entry?
Registers a 6.0.0 name for an operation, callable but not listed. A name an offered operation already has keeps that operation.
151 152 153 154 |
# File 'lib/spree/agent_tools/operation_catalog.rb', line 151 def register_alias(**attributes) entry = build(**attributes, listed: false) alias_entries[entry.name] = entry unless entries.key?(entry.name) end |
.reset! ⇒ void
This method returns an undefined value.
157 158 159 160 |
# File 'lib/spree/agent_tools/operation_catalog.rb', line 157 def reset! @entries = {} @alias_entries = {} end |
.stale! ⇒ void
This method returns an undefined value.
Marks the catalog for rebuilding on its next read.
165 166 167 |
# File 'lib/spree/agent_tools/operation_catalog.rb', line 165 def stale! @derived = false end |