Class: Rapid::Examples::HelloWorldService

Inherits:
Services::Service show all
Defined in:
lib/ury_rapid/examples/hello_world_service.rb

Overview

A simple example service

The HelloWorldService does nothing except provide a sub-model with one item, a constant called 'message' that shows a programmable message.

Its configuration DSL exposes one configurable item, 'message', that overrides the default message ('Hello, World!', of course) with the one provided.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(environment) ⇒ HelloWorldService

Initialises the service

Examples:

Create a new HelloWorldService

service = HelloWorldService.new(view)

22
23
24
25
26
27
28
29
# File 'lib/ury_rapid/examples/hello_world_service.rb', line 22

def initialize(environment)
  # We need to initialise Rapid::Services::Service with the
  # environment
  super(environment)

  # The default message, overridden using #message.
  @message = 'Hello, World!'
end

Instance Attribute Details

#message=(value) ⇒ void (writeonly) Also known as: message

This method returns an undefined value.

Sets the message exposed by this HelloWorldService

Examples:

Set the message to 'Good Morning, Vietnam!'

# In config.rb
message 'Good Morning, Vietnam!'

66
67
68
# File 'lib/ury_rapid/examples/hello_world_service.rb', line 66

def message=(value)
  @message = value
end

Instance Method Details

#runvoid

This method returns an undefined value.

Runs the service on the EventMachine loop

Since we have no EventMachine-bound connections, timers, or I/O tasks, this is empty.

Examples:

Run the HelloWorldService.

service.run

41
42
43
44
45
46
47
48
49
# File 'lib/ury_rapid/examples/hello_world_service.rb', line 41

def run
  # #insert_components is an instance-exec, so this won't be available
  # as an instance variable.
  m = @message

  environment.insert_components('/') do
    constant :message, m, :message
  end
end