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.



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

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


53
54
55
56
57
58
59
# File 'app/services/add.rb', line 53

def run
  run!
rescue => err
  publish :error, err.messages
else
  publish :created, uuid, messages
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 39