Class: Terret::Fortune::Tool
- Inherits:
-
Hames::Service
- Object
- Hames::Service
- Terret::Fortune::Tool
- Defined in:
- lib/terret/fortune/tool.rb
Overview
Registers the fortune tool: one random line from a vendored list.
An ordinary tool provider -- a Hames service that injects ctx
and registers a Definition in start, the shape gems/terret-tools-std
uses for the whole standard roster.
Constant Summary collapse
- DEFAULT_FILE =
File.("fortunes.txt", __dir__)
- DESCRIPTION =
"Return a single fortune: one short, pithy line chosen at random."
Instance Method Summary collapse
-
#reconfigure(config) ⇒ Object
The list is read once at mount.
- #start(ctx) ⇒ Object
Instance Method Details
#reconfigure(config) ⇒ Object
The list is read once at mount. A swapped path: needs a remount to
apply, and saying so beats letting the base class warn that a service
it thinks is stateful needs one (docs/hames-primer.md ยง5).
29 30 31 |
# File 'lib/terret/fortune/tool.rb', line 29 def reconfigure(config) @fortunes = load_fortunes(config[:path] || DEFAULT_FILE) end |
#start(ctx) ⇒ Object
20 21 22 23 24 |
# File 'lib/terret/fortune/tool.rb', line 20 def start(ctx) @ctx = ctx @fortunes = load_fortunes(config[:path] || DEFAULT_FILE) register_fortune end |