Class: Hames::Service
- Inherits:
-
Object
- Object
- Hames::Service
- Extended by:
- Hames::Schema::DSL
- Defined in:
- lib/hames/loader.rb
Overview
Base class for service plugins. A plugin may instead be any object that responds to apply(ctx) (the functional form), with optional #inject.
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Class Method Summary collapse
- .inject(*keys) ⇒ Object
-
.service_key(key = nil) ⇒ Object
Both class-level declarations are inherited: a subclass (a test double, a provider variant) mounts exactly like its parent unless it redeclares.
Instance Method Summary collapse
- #apply(ctx) ⇒ Object
-
#initialize(config = {}) ⇒ Service
constructor
A new instance of Service.
- #inject ⇒ Object
-
#reconfigure(_config) ⇒ Object
Hot-reload hook (plan §M6): the loader replaces config wholesale, then calls this.
-
#replace_config!(config) ⇒ Object
Loader-only: swap the config object under the reader.
- #start(ctx) ⇒ Object
- #stop(ctx) ⇒ Object
Methods included from Hames::Schema::DSL
config_schema, stored_config_schema
Constructor Details
#initialize(config = {}) ⇒ Service
Returns a new instance of Service.
33 34 35 |
# File 'lib/hames/loader.rb', line 33 def initialize(config = {}) @config = config end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
31 32 33 |
# File 'lib/hames/loader.rb', line 31 def config @config end |
Class Method Details
.inject(*keys) ⇒ Object
23 24 25 26 27 28 |
# File 'lib/hames/loader.rb', line 23 def inject(*keys) @inject ||= [] @inject.concat(keys.map(&:to_sym)) unless keys.empty? inherited = superclass <= Hames::Service ? superclass.inject : [] inherited + @inject end |
.service_key(key = nil) ⇒ Object
Both class-level declarations are inherited: a subclass (a test double, a provider variant) mounts exactly like its parent unless it redeclares. inject accumulates down the chain; service_key overrides.
16 17 18 19 20 21 |
# File 'lib/hames/loader.rb', line 16 def service_key(key = nil) @service_key = key.to_sym if key return @service_key if @service_key superclass <= Hames::Service ? superclass.service_key : nil end |
Instance Method Details
#apply(ctx) ⇒ Object
39 40 41 42 |
# File 'lib/hames/loader.rb', line 39 def apply(ctx) ctx.register_service(self.class.service_key, self) if self.class.service_key start(ctx) end |
#inject ⇒ Object
37 |
# File 'lib/hames/loader.rb', line 37 def inject = self.class.inject |
#reconfigure(_config) ⇒ Object
Hot-reload hook (plan §M6): the loader replaces config wholesale, then calls this. Override to re-derive whatever start captured. The default warns — a service running on stale knobs should say so, not hide it.
50 51 52 |
# File 'lib/hames/loader.rb', line 50 def reconfigure(_config) warn "hames: #{self.class} does not support hot-reconfigure; remount the row to apply" end |
#replace_config!(config) ⇒ Object
Loader-only: swap the config object under the reader.
55 56 57 |
# File 'lib/hames/loader.rb', line 55 def replace_config!(config) @config = config end |
#start(ctx) ⇒ Object
44 |
# File 'lib/hames/loader.rb', line 44 def start(ctx); end |
#stop(ctx) ⇒ Object
45 |
# File 'lib/hames/loader.rb', line 45 def stop(ctx); end |