Class: Moleculer::Service::Action
- Inherits:
-
Object
- Object
- Moleculer::Service::Action
- Includes:
- Moleculer::Support
- Defined in:
- lib/moleculer/service/action.rb
Overview
Represents an action
Instance Attribute Summary collapse
-
#name ⇒ String
readonly
The name of the action.
-
#service ⇒ Object
readonly
Returns the value of attribute service.
Instance Method Summary collapse
-
#execute(context, broker) ⇒ Moleculer::Support::Hash
Returns a hash which will be converted into json for the response.
-
#initialize(name, service, method, options = {}) ⇒ Action
constructor
options will reflect the hash.
- #node ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(name, service, method, options = {}) ⇒ Action
options will reflect the hash. provided type.
23 24 25 26 27 28 |
# File 'lib/moleculer/service/action.rb', line 23 def initialize(name, service, method, = {}) @name = name @service = service @method = method @options = end |
Instance Attribute Details
#name ⇒ String (readonly)
Returns the name of the action.
12 13 14 |
# File 'lib/moleculer/service/action.rb', line 12 def name @name end |
#service ⇒ Object (readonly)
Returns the value of attribute service.
12 13 14 |
# File 'lib/moleculer/service/action.rb', line 12 def service @service end |
Instance Method Details
#execute(context, broker) ⇒ Moleculer::Support::Hash
Returns a hash which will be converted into json for the response.
35 36 37 38 39 40 41 42 43 |
# File 'lib/moleculer/service/action.rb', line 35 def execute(context, broker) response = @service.new(broker).public_send(@method, context) # rubocop disabled because in this case we need a specific error handling format raise Errors::InvalidActionResponse.new(response) unless response.is_a? Hash # rubocop:disable Style/RaiseArgs response rescue StandardError => e broker.config.handle_error(e) end |
#node ⇒ Object
45 46 47 |
# File 'lib/moleculer/service/action.rb', line 45 def node @service.node end |