Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/brett-richardson/base_service
Base Service for Ruby Objects
https://github.com/brett-richardson/base_service
oop ruby ruby-gem ruby-library ruby-on-rails rubygem services solid
Last synced: about 1 month ago
JSON representation
Base Service for Ruby Objects
- Host: GitHub
- URL: https://github.com/brett-richardson/base_service
- Owner: brett-richardson
- License: mit
- Created: 2016-07-24T16:31:14.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2016-07-26T21:25:13.000Z (over 8 years ago)
- Last Synced: 2024-11-13T21:21:05.369Z (about 2 months ago)
- Topics: oop, ruby, ruby-gem, ruby-library, ruby-on-rails, rubygem, services, solid
- Language: Ruby
- Size: 10.7 KB
- Stars: 2
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: MIT-LICENSE
Awesome Lists containing this project
README
BaseService
===========The client should extend this module, in order to implement this common
service object pattern.### Advanced Syntax
```ruby
MyService.new(param1, param2).call do |on|
on.success { |result| puts "Success #{result}" }on.failure { |error| puts "Generic failure #{error}" }
on.failure(:param1_error) { |error| puts "Problem with param1 #{param1}" }
on.failure(:param2_error) { |error| puts "Problem with param1 #{param1}" }
end```
### Semi-Advanced Syntax
```ruby
MyService.new(param1, param2).call do |on|
puts "Result: #{on.result}"
end```
## Support for (depreacted) legacy behaviour
No command-query separation. :(
```ruby
result = MyService.new(param1, param2).call
```
## Example Service
```ruby
class MyService
include BaseServicedef initialize(param1, param2)
@param1, @param2 = param1, param2
endprivate
attr_reader :param1, :param2def perform
return failure "no param1", :param1_error unless param1.present?
return failure "no param2", :param2_error unless param2.present?
return failure "neither param1 or 2" unless param1.present? && param2.present?return "success!"
end
end```