Class: Hames::Service
- Inherits:
-
Object
- Object
- Hames::Service
- 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
Instance Method Summary collapse
- #apply(ctx) ⇒ Object
-
#initialize(config = {}) ⇒ Service
constructor
A new instance of Service.
- #inject ⇒ Object
- #start(ctx) ⇒ Object
- #stop(ctx) ⇒ Object
Constructor Details
#initialize(config = {}) ⇒ Service
Returns a new instance of Service.
22 23 24 |
# File 'lib/hames/loader.rb', line 22 def initialize(config = {}) @config = config end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
20 21 22 |
# File 'lib/hames/loader.rb', line 20 def config @config end |
Class Method Details
.inject(*keys) ⇒ Object
13 14 15 16 17 |
# File 'lib/hames/loader.rb', line 13 def inject(*keys) @inject ||= [] @inject.concat(keys.map(&:to_sym)) unless keys.empty? @inject end |
.service_key(key = nil) ⇒ Object
8 9 10 11 |
# File 'lib/hames/loader.rb', line 8 def service_key(key = nil) @service_key = key.to_sym if key @service_key end |
Instance Method Details
#apply(ctx) ⇒ Object
28 29 30 31 |
# File 'lib/hames/loader.rb', line 28 def apply(ctx) ctx.register_service(self.class.service_key, self) if self.class.service_key start(ctx) end |
#inject ⇒ Object
26 |
# File 'lib/hames/loader.rb', line 26 def inject = self.class.inject |
#start(ctx) ⇒ Object
33 |
# File 'lib/hames/loader.rb', line 33 def start(ctx); end |
#stop(ctx) ⇒ Object
34 |
# File 'lib/hames/loader.rb', line 34 def stop(ctx); end |