service_caller 1.1.0 → 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4270b7ad52ef57a18ba599c31496415626a298ab824884c416c1b5ff51af75c2
4
- data.tar.gz: 627575a83678d20e7ec951b1ac9c4777acdcf91e2ae620e2b99c59ccef5b46c6
3
+ metadata.gz: 48401571ef678e9a715d9edca52d93dfc564532732c5e90be288ca908149bbf9
4
+ data.tar.gz: 82ace8f205fcc2c999ec78e358a45faf35a001dc7529da582379908b985478da
5
5
  SHA512:
6
- metadata.gz: 1ce323d5562bb0fb08d42121858dfa19c4cf691f5afe27a11c3781ce8475b190ea7b5c4593f71a924908317c2447c2b03b3e6adbcd81471dea41b956970df2ea
7
- data.tar.gz: 796dd3b3e3b64fc4e58b76a12778e2436758b62f4305bda9c2896a3278a340d45c12b220f1379933e0dd43d6aebbcb3319cdb6b1c07832af28611c0d6ea7b657
6
+ metadata.gz: d8fe40ec0f7c44958867ffa7faed7241429cb78328cc13bf6280b61f2cd8616c687a7c90d0cf473bce73eebfb4f9a5b26de3aaeed4df237734036ed15f94d2d9
7
+ data.tar.gz: c3101c3b72ae80e54817bd4cc6ea5850c1e8a0cfbfe171068912b06b50d91cab67c3768414082db6a1b0159480174fbb2c5dbca872b3cd04d8158eb7148364e4
data/README.md CHANGED
@@ -1,34 +1,81 @@
1
1
  # Service Caller
2
2
 
3
- ### How to Use
4
- * install gem
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.x'
9
+ # ruby version 2.6+ or eariler
10
+ gem 'service_caller', '~> 1.1.0'
5
11
  ```
6
- gem install service_caller-0.1.0.gem
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
- * require gem
10
- ```ruby
11
- require 'service_caller'
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.x |
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
- * call the service
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
  ```
@@ -3,8 +3,8 @@ module ServiceExtend
3
3
  attr_reader :error, :result
4
4
 
5
5
  module ClassMethods
6
- def call(*args)
7
- service = new(*args)
6
+ def call(*args, **hsh)
7
+ service = new(*args, **hsh)
8
8
  service.call
9
9
  service
10
10
  end
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.1.0
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - JiaRou Lee
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-08-26 00:00:00.000000000 Z
11
+ date: 2023-05-18 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: basic implement of service object
14
14
  email: laura34963@kdanmobile.com
@@ -25,7 +25,9 @@ files:
25
25
  homepage: https://github.com/kdan-mobile-software-ltd/service_caller
26
26
  licenses:
27
27
  - MIT
28
- metadata: {}
28
+ metadata:
29
+ source_code_uri: https://github.com/kdan-mobile-software-ltd/service_caller
30
+ changelog_uri: https://github.com/kdan-mobile-software-ltd/service_caller/blob/master/CHANGELOG.md
29
31
  post_install_message:
30
32
  rdoc_options:
31
33
  - "--charset=UTF-8"
@@ -35,14 +37,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
35
37
  requirements:
36
38
  - - ">="
37
39
  - !ruby/object:Gem::Version
38
- version: 2.5.1
40
+ version: 2.7.0
39
41
  required_rubygems_version: !ruby/object:Gem::Requirement
40
42
  requirements:
41
43
  - - ">="
42
44
  - !ruby/object:Gem::Version
43
45
  version: '0'
44
46
  requirements: []
45
- rubygems_version: 3.0.3
47
+ rubygems_version: 3.2.22
46
48
  signing_key:
47
49
  specification_version: 4
48
50
  summary: Ruby Service Basic Class