Class: Uuids::Services::Add

Inherits:
Hexx::Service
  • Object
show all
Defined in:
app/services/add.rb

Overview

Adds the uuid to the record.

Examples:

service = Uuids::Services::Add.new(
  record: #<ActiveRecord::Base ...>,
  value:  "42037503-2753-0570-3257-230403275325",
)
service.subscribe some_listener
service.run

Class Method Summary collapse

Class Method Details

.new(params) ⇒ Object

Constructs the service object.

Examples:

service = Uuids::Services::Add.new(
  record: #<ActiveRecord::Base ...>,
  value:  "42037503-2753-0570-3257-230403275325",
)
service.subscribe some_listener
service.run

Parameters:

  • params (Hash)

    The list of service options.

Options Hash (params):

  • :record (ActiveRecord::Base)

    The record for adding uuid.

  • :value (String)

    The uuid to be added to the record.



33
# File 'app/services/add.rb', line 33

allow_params :record, :value

.runObject

Runs the service and publishes its results.

Examples:

service = Uuids::Services::Add.new(
  record: #<ActiveRecord::Base ...>,
  value:  "42037503-2753-0570-3257-230403275325",
)
service.subscribe some_listener
service.run


50
51
52
# File 'app/services/add.rb', line 50

def run
  create_uuid
end

.subscribe(listener, options = {}) ⇒ Object

Subscribes a listener to receive the service’s notifications.

Examples:

service = Uuids::Services::Add.new(
  record: #<ActiveRecord::Base ...>,
  value:  "42037503-2753-0570-3257-230403275325",
)
service.subscribe some_listener
service.run

Parameters:

  • listener (Object)

    Any object can be subscribed as a listener. It is expected (but not required) the listener to respond to notifications, published by the #run.

  • options (Hash) (defaults to: {})

    The subscription options.

Options Hash (options):

  • :prefix (Symbol) — default: nil

    The prefix to be added to notifications to provide valid listener method names to call.



# File 'app/services/add.rb', line 35