Class: ServiceBase::Service
- Inherits:
-
Dry::Struct
- Object
- Dry::Struct
- ServiceBase::Service
- Extended by:
- Dry::Monads::Result::Mixin::Constructors, ArgumentTypeAnnotations
- Includes:
- Memery
- Defined in:
- lib/service_base/service.rb
Defined Under Namespace
Classes: ServiceNotSuccessful
Class Method Summary collapse
-
.call(args = {}, &block) ⇒ Object
The public class call method.
- .call!(*args) ⇒ Object
-
.pp ⇒ Object
Pretty prints (pp) the description of the service, ie.
- .service_description ⇒ Object
Instance Method Summary collapse
-
#arguments ⇒ Object
Returns a hash of all arguments and their values.
Methods included from ArgumentTypeAnnotations
Class Method Details
.call(args = {}, &block) ⇒ Object
The public class call method.
The default empty hash is important to prevent an argument error when passing no arguments to a service that defines defaults for every argument.
33 34 35 36 37 38 |
# File 'lib/service_base/service.rb', line 33 def call(args = {}, &block) validate_args!(args: args) result = new(args).call match_result(result, &block) end |
.call!(*args) ⇒ Object
40 41 42 43 44 45 |
# File 'lib/service_base/service.rb', line 40 def call!(*args) result = call(*args) raise(ServiceNotSuccessful, result.failure) if result.failure? result end |
.pp ⇒ Object
Pretty prints (pp) the description of the service, ie. MyService.pp
48 49 50 51 52 53 54 55 56 |
# File 'lib/service_base/service.rb', line 48 def pp logger = Logger.new($stdout) logger.info("#{name}: #{service_description}") logger.info('Arguments') schema_definition.each do |arg| logger.info(" #{arg[:name]} (#{arg[:type]}): #{arg[:description]}") end end |
.service_description ⇒ Object
59 60 61 |
# File 'lib/service_base/service.rb', line 59 def service_description @description || 'No description' end |
Instance Method Details
#arguments ⇒ Object
Returns a hash of all arguments and their values
99 100 101 |
# File 'lib/service_base/service.rb', line 99 def arguments attributes end |