Sha256: 581f15a9a46ca75b623e609634cb6341ab04120a9fea7a9c56febf7c5db5120f
Contents?: true
Size: 1.27 KB
Versions: 1
Compression:
Stored size: 1.27 KB
Contents
module Slayer class Service attr_accessor :result # Internal: Service Class Methods class << self def call(*args, &block) # Run the Service and capture the result result = new.tap { |s| s.run(*args, &block) }.result # Throw an exception if we don't return a result raise ServiceNotImplemented unless result.is_a? Result return result end end # Run the Service, rescue from Failures def run(*args, &block) begin run!(*args, &block) rescue ServiceFailure end end # Run the Service def run!(*args, &block) call(*args, &block) end # Fail the Service def fail! result:, message: @result = Result.new(result, message) @result.fail! end # Pass the Service def pass! result:, message: @result = Result.new(result, message) end # Call the service def call raise NotImplementedError, "Services must define method `#call`." end # Do nothing def rollback end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
slayer-0.1.0 | lib/slayer/service.rb |