service_caller 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +46 -0
- data/lib/service_caller.rb +13 -0
- data/lib/service_error.rb +16 -0
- data/lib/service_extend/callable.rb +21 -0
- data/lib/service_extend/handler.rb +11 -0
- metadata +49 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: aa23570d96d1da00dd99667ea8995706280f18856b28c84b6b2f7c81d306e7de
|
4
|
+
data.tar.gz: 7e64dac81a0011f73997aa7a42744e188e260e840627c53acf3105ae7966e52b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: df0193c0514f45c08f8496325813d40856e9ff216aea7604516504e7e130f8aec527c13e11ebded15cd9d4c23c97b363fd2e8c38d4f685d222aa7e909c7f460f
|
7
|
+
data.tar.gz: adef65b25e71b55be059d7a4049fe58bb6c994131bcb29e36f76092a510e426d06c5c8f54d4c3939c8cd6423365d3e3c83e9b8ded02a4b1602f74e80a6c2c896
|
data/README.md
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# Service Caller
|
2
|
+
|
3
|
+
### How to Use
|
4
|
+
* install gem
|
5
|
+
```
|
6
|
+
gem install service_caller-0.1.0.gem
|
7
|
+
```
|
8
|
+
|
9
|
+
* require gem
|
10
|
+
```ruby
|
11
|
+
require 'service_caller'
|
12
|
+
```
|
13
|
+
|
14
|
+
* define service & inherit from `ServiceCaller`
|
15
|
+
```ruby
|
16
|
+
class [Custom Service] < ServiceCaller
|
17
|
+
def initialize(*args)
|
18
|
+
...
|
19
|
+
end
|
20
|
+
|
21
|
+
def call
|
22
|
+
...
|
23
|
+
end
|
24
|
+
end
|
25
|
+
```
|
26
|
+
|
27
|
+
* call the service
|
28
|
+
```ruby
|
29
|
+
service = [Custom Service].call(*args)
|
30
|
+
```
|
31
|
+
|
32
|
+
* check if success
|
33
|
+
```ruby
|
34
|
+
service.success?
|
35
|
+
service.failed?
|
36
|
+
```
|
37
|
+
|
38
|
+
* get success result if success
|
39
|
+
```ruby
|
40
|
+
service.result
|
41
|
+
```
|
42
|
+
|
43
|
+
* get error if failed
|
44
|
+
```ruby
|
45
|
+
service.error
|
46
|
+
```
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'service_extend/callable'
|
2
|
+
require 'service_extend/handler'
|
3
|
+
require 'service_error'
|
4
|
+
|
5
|
+
class ServiceCaller
|
6
|
+
include ServiceExtend::Callable
|
7
|
+
extend ServiceExtend::Callable::ClassMethods
|
8
|
+
|
9
|
+
def self.inherited(child_class)
|
10
|
+
child_class.prepend(ServiceExtend::Handler)
|
11
|
+
super
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class ServiceError < StandardError
|
2
|
+
attr_reader :code
|
3
|
+
|
4
|
+
class << self
|
5
|
+
def generate_from_exception(exception)
|
6
|
+
service_err = new(500, "#{exception.class.name}: #{exception.message}")
|
7
|
+
service_err.set_backtrace(exception.backtrace)
|
8
|
+
service_err
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def initialize(code, message)
|
13
|
+
@code = code
|
14
|
+
super(message)
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module ServiceExtend
|
2
|
+
module Callable
|
3
|
+
attr_reader :error, :result
|
4
|
+
|
5
|
+
module ClassMethods
|
6
|
+
def call(*args)
|
7
|
+
service = new(*args)
|
8
|
+
service.call
|
9
|
+
service
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def success?
|
14
|
+
error.nil? || error.empty?
|
15
|
+
end
|
16
|
+
|
17
|
+
def failed?
|
18
|
+
!success?
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: service_caller
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- JiaRou Lee
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-07-24 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: basic implement of service object
|
14
|
+
email: laura34963@kdanmobile.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files:
|
18
|
+
- README.md
|
19
|
+
files:
|
20
|
+
- README.md
|
21
|
+
- lib/service_caller.rb
|
22
|
+
- lib/service_error.rb
|
23
|
+
- lib/service_extend/callable.rb
|
24
|
+
- lib/service_extend/handler.rb
|
25
|
+
homepage: https://github.com/laura34963/service_caller
|
26
|
+
licenses:
|
27
|
+
- MIT
|
28
|
+
metadata: {}
|
29
|
+
post_install_message:
|
30
|
+
rdoc_options:
|
31
|
+
- "--charset=UTF-8"
|
32
|
+
require_paths:
|
33
|
+
- lib
|
34
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - ">="
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: 2.5.1
|
39
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
requirements: []
|
45
|
+
rubygems_version: 3.0.1
|
46
|
+
signing_key:
|
47
|
+
specification_version: 4
|
48
|
+
summary: Ruby Service Basic Class
|
49
|
+
test_files: []
|