service_caller 1.1.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +92 -7
- data/lib/service_extend/callable.rb +2 -2
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: baf3a2b14016c3d6c5d8edaaeb685b471fe044f341b499c881ce80d255fd9793
|
4
|
+
data.tar.gz: 7b0eb03312f9b820097f4f3cd2104aa8ec9c9bd203163f037fd2b1b97ba7d9bc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f96a41886c346c180dde240521dcdbfbbfe297a71f448e608120aeb51881adb1c45cda1ce03b6fd595b0a212b887c70a330d36c2eda60d7109cba0aca5db0482
|
7
|
+
data.tar.gz: 28aa75a07f70bf226d454366d8b76f20350c9c5fa28956b68d27c28566deb109fb8de8fd9129dfb65d79358924ed6df73ad9bf4ab5778f8afc79a025d2cfa1f6
|
data/README.md
CHANGED
@@ -1,34 +1,81 @@
|
|
1
1
|
# Service Caller
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
## Installation
|
4
|
+
1. Add `service_caller` in your app's `Gemfile`.
|
5
|
+
|
6
|
+
``` ruby
|
7
|
+
# ruby version 2.7+ or later
|
8
|
+
gem 'service_caller', '~> 1.2.0'
|
9
|
+
# ruby version 2.6+ or eariler
|
10
|
+
gem 'service_caller', '~> 1.1.0'
|
5
11
|
```
|
6
|
-
|
12
|
+
|
13
|
+
2. Then, in your project directory, install the gem manually from your shell, run:
|
14
|
+
|
15
|
+
``` bash
|
16
|
+
# Download and install
|
17
|
+
$ bundle install
|
7
18
|
```
|
8
19
|
|
9
|
-
|
10
|
-
|
11
|
-
|
20
|
+
## Upgrading
|
21
|
+
|
22
|
+
If your project is already using an older version of service_caller, upgrade to the latest version with:
|
23
|
+
|
24
|
+
``` bash
|
25
|
+
$ bundle update service_caller
|
12
26
|
```
|
13
27
|
|
28
|
+
## Support of Ruby and Rails Version
|
29
|
+
|
30
|
+
| Ruby Version | Rails Verision | Service Caller Version |
|
31
|
+
| - | - | - |
|
32
|
+
| 2.6 or eariler | 5.x | 1.1.0 |
|
33
|
+
| 2.7, 3.0 later | 6.x | 1.2.0 |
|
34
|
+
|
35
|
+
## Usage
|
36
|
+
|
14
37
|
* define service & inherit from `ServiceCaller`
|
38
|
+
* **For ruby 2.6 or earlier** (ruby 2.7 may show deprecated warning message)
|
15
39
|
```ruby
|
16
40
|
class [Custom Service] < ServiceCaller
|
17
41
|
def initialize(*args)
|
18
42
|
...
|
43
|
+
@a = a
|
44
|
+
@b = b
|
19
45
|
end
|
20
46
|
|
21
47
|
def call
|
22
48
|
...
|
49
|
+
@result = "Your service result which you want to return"
|
23
50
|
end
|
24
51
|
end
|
25
52
|
```
|
53
|
+
* **For ruby 2.7 or ruby 3.0**
|
54
|
+
``` ruby
|
55
|
+
class [Custom Service] < ServiceCaller
|
56
|
+
def initialize(*args, **hsh)
|
57
|
+
...
|
58
|
+
@a = a
|
59
|
+
@b = b
|
60
|
+
end
|
26
61
|
|
27
|
-
|
62
|
+
def call
|
63
|
+
...
|
64
|
+
@result = "Your service result which you want to return"
|
65
|
+
end
|
66
|
+
end
|
67
|
+
```
|
68
|
+
|
69
|
+
* call the service (**For ruby 2.6 or earlier**)
|
28
70
|
```ruby
|
29
71
|
service = [Custom Service].call(*args)
|
30
72
|
```
|
31
73
|
|
74
|
+
* call the service (**For ruby 2.7 or ruby 3.0**)
|
75
|
+
```ruby
|
76
|
+
service = [Custom Service].call(*args, **hsh)
|
77
|
+
```
|
78
|
+
|
32
79
|
* check if success
|
33
80
|
```ruby
|
34
81
|
service.success?
|
@@ -43,4 +90,42 @@ end
|
|
43
90
|
* get error if failed
|
44
91
|
```ruby
|
45
92
|
service.error
|
93
|
+
```
|
94
|
+
|
95
|
+
### Example
|
96
|
+
|
97
|
+
``` ruby
|
98
|
+
class CalBmi < ServiceCaller
|
99
|
+
def initialize(member_name, height: 1.55, weight: 52)
|
100
|
+
@member_name = member_name
|
101
|
+
@height = height
|
102
|
+
@weight = weight
|
103
|
+
end
|
104
|
+
|
105
|
+
def call
|
106
|
+
bmi = calculate_bmi
|
107
|
+
raise ServiceError.new(:member_name_not_found, error_msg: 'not enter the name') if @member_name.blank?
|
108
|
+
@result = "#{@member_name}'s BMI is #{bmi}"
|
109
|
+
end
|
110
|
+
|
111
|
+
private
|
112
|
+
|
113
|
+
def calculate_bmi
|
114
|
+
(@weight / @height**2).round(2)
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
|
119
|
+
# Call the BMI Service
|
120
|
+
|
121
|
+
body_insight = {height: 1.80, weight: 73}
|
122
|
+
bmi = CalBmi.call('william', **body_insight)
|
123
|
+
|
124
|
+
bmi.success? # it will show the caller is success or failed
|
125
|
+
bmi.result # it will show you => william's BMI is 22.53
|
126
|
+
|
127
|
+
bmi = CalBmi.call('', **body_insight)
|
128
|
+
bmi.error # if failed, the service will raise the custom error => #<ServiceError: member_name_not_found>
|
129
|
+
bmi.error.key # :member_name_not_found
|
130
|
+
bmi.error.error_obj # {:error_msg=>"not enter the name"}
|
46
131
|
```
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: service_caller
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- JiaRou Lee
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-10-05 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: basic implement of service object
|
14
14
|
email: laura34963@kdanmobile.com
|
@@ -35,14 +35,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
35
35
|
requirements:
|
36
36
|
- - ">="
|
37
37
|
- !ruby/object:Gem::Version
|
38
|
-
version: 2.
|
38
|
+
version: 2.7.0
|
39
39
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
40
40
|
requirements:
|
41
41
|
- - ">="
|
42
42
|
- !ruby/object:Gem::Version
|
43
43
|
version: '0'
|
44
44
|
requirements: []
|
45
|
-
rubygems_version: 3.
|
45
|
+
rubygems_version: 3.2.22
|
46
46
|
signing_key:
|
47
47
|
specification_version: 4
|
48
48
|
summary: Ruby Service Basic Class
|