Class: Async::Service::GenericService
- Inherits:
-
Object
- Object
- Async::Service::GenericService
- Defined in:
- lib/async/service/generic_service.rb
Overview
Captures the stateful behaviour of a specific service. Specifies the interfaces required by derived classes.
Designed to be invoked within an Controller::Container.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#environment ⇒ Object
readonly
Returns the value of attribute environment.
- #The environment which is used to configure the service.(environmentwhichisusedtoconfiguretheservice.) ⇒ Object readonly
Class Method Summary collapse
-
.wrap(environment) ⇒ Object
Convert the given environment into a service if possible.
Instance Method Summary collapse
-
#initialize(environment, evaluator = environment.evaluator) ⇒ GenericService
constructor
Initialize the service from the given environment.
-
#name ⇒ Object
The name of the service - used for informational purposes like logging.
-
#setup(container) ⇒ Object
Setup the service into the specified container.
-
#start ⇒ Object
Start the service.
-
#stop(graceful = true) ⇒ Object
Stop the service.
-
#to_h ⇒ Object
Convert the service evaluator to a hash.
Constructor Details
#initialize(environment, evaluator = environment.evaluator) ⇒ GenericService
Initialize the service from the given environment.
28 29 30 31 |
# File 'lib/async/service/generic_service.rb', line 28 def initialize(environment, evaluator = environment.evaluator) @environment = environment @evaluator = evaluator end |
Instance Attribute Details
#environment ⇒ Object (readonly)
Returns the value of attribute environment.
34 35 36 |
# File 'lib/async/service/generic_service.rb', line 34 def environment @environment end |
#The environment which is used to configure the service.(environmentwhichisusedtoconfiguretheservice.) ⇒ Object (readonly)
34 |
# File 'lib/async/service/generic_service.rb', line 34 attr :environment |
Class Method Details
.wrap(environment) ⇒ Object
Convert the given environment into a service if possible.
16 17 18 19 20 21 22 23 24 |
# File 'lib/async/service/generic_service.rb', line 16 def self.wrap(environment) evaluator = environment.evaluator if evaluator.key?(:service_class) if service_class = evaluator.service_class return service_class.new(environment, evaluator) end end end |
Instance Method Details
#name ⇒ Object
The name of the service - used for informational purposes like logging. e.g. ‘myapp.com`.
44 45 46 |
# File 'lib/async/service/generic_service.rb', line 44 def name @evaluator.name end |
#setup(container) ⇒ Object
Setup the service into the specified container.
55 56 57 |
# File 'lib/async/service/generic_service.rb', line 55 def setup(container) Console.debug(self){"Setting up service #{self.name}..."} end |
#start ⇒ Object
Start the service. Called before the container setup.
49 50 51 |
# File 'lib/async/service/generic_service.rb', line 49 def start Console.debug(self){"Starting service #{self.name}..."} end |
#stop(graceful = true) ⇒ Object
Stop the service. Called after the container is stopped.
60 61 62 |
# File 'lib/async/service/generic_service.rb', line 60 def stop(graceful = true) Console.debug(self){"Stopping service #{self.name}..."} end |
#to_h ⇒ Object
Convert the service evaluator to a hash.
38 39 40 |
# File 'lib/async/service/generic_service.rb', line 38 def to_h @evaluator.to_h end |