activerpc 0.1.0 → 0.1.1
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 +26 -1
- data/app/controllers/active_rpc/rpc_controller.rb +9 -3
- data/lib/active_rpc/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 731fbeef55a0b7a9bacbf22b09caabd6599f66032ac24e34d834889f7c810ef3
|
4
|
+
data.tar.gz: 841090dce51a1285eb0f2e63e17c3f5f6c868c211caef620f7a91e2991bf267b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9c30c2aa2c713da842b21d1ce591ed350856f27bad5c154f1a60b1bfa223c4e4bd4d32ec25f2de30e9a21dcd1d52e9d05b6368dc4161f42e47185ee444c8fdbe
|
7
|
+
data.tar.gz: 0fdc8cc5a86773f43835223976941e90e8222c86191bb18110380e18f0fe3a83ec594e29d6c99024a4da13f9d511e447ef2422e56a037e3ef5928cdf12fe4a54
|
data/README.md
CHANGED
@@ -12,7 +12,7 @@ using standard Rails tools and toolchains.
|
|
12
12
|
Add this line to your application's Gemfile:
|
13
13
|
|
14
14
|
```ruby
|
15
|
-
gem 'activerpc'
|
15
|
+
gem 'activerpc', '~> 0.1'
|
16
16
|
```
|
17
17
|
|
18
18
|
And then execute:
|
@@ -35,6 +35,8 @@ end
|
|
35
35
|
```
|
36
36
|
|
37
37
|
## Usage
|
38
|
+
|
39
|
+
#### Operations
|
38
40
|
The JSONRPC spec supports two kinds of parameters being passed to a method. We
|
39
41
|
feel strongly that only the Hash/Object form should be used rather than the
|
40
42
|
Array/positional form. The reason for this is that it is significantly less
|
@@ -55,6 +57,10 @@ class MyRpcMethod < ActiveRpc::Operation
|
|
55
57
|
def call
|
56
58
|
"Hello #{name}, you are #{age} years old."
|
57
59
|
end
|
60
|
+
|
61
|
+
before_validation do
|
62
|
+
# do something to check on the inputs before validating them
|
63
|
+
end
|
58
64
|
end
|
59
65
|
```
|
60
66
|
|
@@ -73,6 +79,25 @@ def call
|
|
73
79
|
end
|
74
80
|
```
|
75
81
|
|
82
|
+
#### Controller Lifecycle Events
|
83
|
+
You can provide `around`, `before` or `after` hooks to tie into the controller
|
84
|
+
lifecycle, whether for authentication, authorization or whatever else.
|
85
|
+
|
86
|
+
To provide a hook, you need to pass something that responds to the corresponding
|
87
|
+
method to the appropriate setting in the config, e.g.
|
88
|
+
|
89
|
+
```ruby
|
90
|
+
ActiveRpc.configure do |config|
|
91
|
+
config.around_action = Module.new do
|
92
|
+
def self.around(controller) # method name matches the hook type
|
93
|
+
puts controller.request.remote_ip
|
94
|
+
yield
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
```
|
99
|
+
|
100
|
+
#### Development Mode
|
76
101
|
Please note, in development mode you might have issues with the operation classes
|
77
102
|
being autoloaded. The new bootloader in Rails 6 will solve this, but until then you
|
78
103
|
can add something similar to the below to an initialiser.
|
@@ -1,8 +1,14 @@
|
|
1
1
|
module ActiveRpc
|
2
2
|
class RpcController < ActionController::Base
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
if ActiveRpc.config.after_action.present?
|
4
|
+
after_action ActiveRpc.config.after_action
|
5
|
+
end
|
6
|
+
if ActiveRpc.config.around_action.present?
|
7
|
+
around_action ActiveRpc.config.around_action
|
8
|
+
end
|
9
|
+
if ActiveRpc.config.before_action.present?
|
10
|
+
before_action ActiveRpc.config.before_action
|
11
|
+
end
|
6
12
|
|
7
13
|
def create
|
8
14
|
res = nil
|
data/lib/active_rpc/version.rb
CHANGED