Class: ServicePattern::Service
- Inherits:
-
Object
- Object
- ServicePattern::Service
- Defined in:
- lib/service_pattern/service.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.call(*args) ⇒ Object
2 3 4 5 6 7 8 9 10 11 12 |
# File 'lib/service_pattern/service.rb', line 2 def self.call(*args) service = new(*args) begin can_execute_response = service.can_execute? return can_execute_response unless can_execute_response.success? service.execute! rescue => e ServicePattern::Response.new(errors: ["#{e.class.name}: #{e.}"], success: false) end end |
.execute!(*args) ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/service_pattern/service.rb', line 14 def self.execute!(*args) service = new(*args) can_execute_response = service.can_execute? raise ServicePattern::CantExecuteError, can_execute_response.errors.join(". ") unless can_execute_response.success? service.execute! end |
Instance Method Details
#can_execute? ⇒ Boolean
22 23 24 |
# File 'lib/service_pattern/service.rb', line 22 def can_execute? ServicePattern::Response.new(success: true) end |
#execute!(*_args) ⇒ Object
26 27 28 |
# File 'lib/service_pattern/service.rb', line 26 def execute!(*_args) raise NoMethodError, "You should implement the `execute!` method on your service" end |