jsonrpc-middleware 0.1.0 → 0.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/.aiexclude +4 -0
- data/.claude/commands/document.md +105 -0
- data/.claude/docs/yard.md +602 -0
- data/.claude/settings.local.json +2 -1
- data/.env.example +5 -0
- data/CHANGELOG.md +22 -2
- data/CLAUDE.md +114 -0
- data/README.md +42 -102
- data/Rakefile +59 -1
- data/examples/README.md +37 -0
- data/examples/procedures.rb +6 -1
- data/examples/rack/README.md +26 -1
- data/examples/rack/app.rb +1 -1
- data/examples/rack-echo/README.md +23 -1
- data/examples/rack-single-file/README.md +37 -0
- data/examples/rack-single-file/config.ru +54 -0
- data/examples/rails/.gitignore +21 -0
- data/examples/rails/.ruby-version +1 -0
- data/examples/rails/Gemfile +15 -0
- data/examples/rails/Gemfile.lock +261 -0
- data/examples/rails/README.md +32 -0
- data/examples/rails/Rakefile +8 -0
- data/examples/rails/app/controllers/application_controller.rb +4 -0
- data/examples/rails/app/controllers/jsonrpc_controller.rb +44 -0
- data/examples/rails/bin/dev +4 -0
- data/examples/rails/bin/rails +6 -0
- data/examples/rails/bin/rake +6 -0
- data/examples/rails/bin/setup +28 -0
- data/examples/rails/config/application.rb +47 -0
- data/examples/rails/config/boot.rb +5 -0
- data/examples/rails/config/credentials.yml.enc +1 -0
- data/examples/rails/config/environment.rb +7 -0
- data/examples/rails/config/environments/development.rb +42 -0
- data/examples/rails/config/environments/production.rb +60 -0
- data/examples/rails/config/environments/test.rb +44 -0
- data/examples/rails/config/initializers/cors.rb +18 -0
- data/examples/rails/config/initializers/filter_parameter_logging.rb +10 -0
- data/examples/rails/config/initializers/inflections.rb +18 -0
- data/examples/rails/config/initializers/jsonrpc.rb +62 -0
- data/examples/rails/config/locales/en.yml +31 -0
- data/examples/rails/config/puma.rb +40 -0
- data/examples/rails/config/routes.rb +14 -0
- data/examples/rails/config.ru +8 -0
- data/examples/rails/public/robots.txt +1 -0
- data/examples/rails-single-file/config.ru +71 -0
- data/examples/sinatra-classic/Gemfile +9 -0
- data/examples/sinatra-classic/Gemfile.lock +95 -0
- data/examples/sinatra-classic/README.md +32 -0
- data/examples/sinatra-classic/app.rb +54 -0
- data/examples/sinatra-classic/config.ru +6 -0
- data/examples/sinatra-modular/Gemfile +9 -0
- data/examples/sinatra-modular/Gemfile.lock +95 -0
- data/examples/sinatra-modular/README.md +32 -0
- data/examples/sinatra-modular/app.rb +57 -0
- data/examples/sinatra-modular/config.ru +6 -0
- data/lib/jsonrpc/batch_request.rb +67 -2
- data/lib/jsonrpc/batch_response.rb +56 -0
- data/lib/jsonrpc/configuration.rb +156 -14
- data/lib/jsonrpc/error.rb +83 -2
- data/lib/jsonrpc/errors/internal_error.rb +14 -2
- data/lib/jsonrpc/errors/invalid_params_error.rb +13 -1
- data/lib/jsonrpc/errors/invalid_request_error.rb +8 -0
- data/lib/jsonrpc/errors/method_not_found_error.rb +8 -0
- data/lib/jsonrpc/errors/parse_error.rb +8 -0
- data/lib/jsonrpc/helpers.rb +212 -21
- data/lib/jsonrpc/middleware.rb +211 -5
- data/lib/jsonrpc/notification.rb +58 -0
- data/lib/jsonrpc/parser.rb +30 -0
- data/lib/jsonrpc/railtie.rb +57 -0
- data/lib/jsonrpc/request.rb +68 -1
- data/lib/jsonrpc/response.rb +76 -0
- data/lib/jsonrpc/validator.rb +67 -6
- data/lib/jsonrpc/version.rb +11 -1
- data/lib/jsonrpc.rb +53 -1
- metadata +49 -1
@@ -0,0 +1,54 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'bundler/inline'
|
4
|
+
|
5
|
+
gemfile do
|
6
|
+
source 'https://rubygems.org'
|
7
|
+
|
8
|
+
gem 'jsonrpc-middleware', path: '../..', require: 'jsonrpc'
|
9
|
+
gem 'puma'
|
10
|
+
gem 'rack'
|
11
|
+
gem 'rackup'
|
12
|
+
end
|
13
|
+
|
14
|
+
JSONRPC.configure do
|
15
|
+
procedure(:echo) do
|
16
|
+
params do
|
17
|
+
required(:message).filled(:string)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
# App is a Rack app that handles JSON-RPC requests, notifications, and batches using JSONRPC::Helpers.
|
23
|
+
class App
|
24
|
+
include JSONRPC::Helpers
|
25
|
+
|
26
|
+
def call(env)
|
27
|
+
@env = env
|
28
|
+
|
29
|
+
if jsonrpc_request?
|
30
|
+
result = handle_single(jsonrpc_request)
|
31
|
+
jsonrpc_response(result)
|
32
|
+
elsif jsonrpc_notification?
|
33
|
+
handle_single(jsonrpc_notification)
|
34
|
+
jsonrpc_notification_response
|
35
|
+
else
|
36
|
+
responses = handle_batch(jsonrpc_batch)
|
37
|
+
jsonrpc_batch_response(responses)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def handle_single(request_or_notification) = request_or_notification.params
|
44
|
+
|
45
|
+
def handle_batch(batch)
|
46
|
+
batch.flat_map do |request_or_notification|
|
47
|
+
result = handle_single(request_or_notification)
|
48
|
+
JSONRPC::Response.new(id: request_or_notification.id, result:) if request_or_notification.is_a?(JSONRPC::Request)
|
49
|
+
end.compact
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
use JSONRPC::Middleware
|
54
|
+
run App.new
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# See https://help.github.com/articles/ignoring-files for more about ignoring files.
|
2
|
+
#
|
3
|
+
# Temporary files generated by your text editor or operating system
|
4
|
+
# belong in git's global ignore instead:
|
5
|
+
# `$XDG_CONFIG_HOME/git/ignore` or `~/.config/git/ignore`
|
6
|
+
|
7
|
+
# Ignore bundler config.
|
8
|
+
/.bundle
|
9
|
+
|
10
|
+
# Ignore all environment files.
|
11
|
+
/.env*
|
12
|
+
|
13
|
+
# Ignore all logfiles and tempfiles.
|
14
|
+
/log/*
|
15
|
+
/tmp/pids
|
16
|
+
|
17
|
+
# Ignore storage (uploaded files in development and any SQLite databases).
|
18
|
+
/storage/*
|
19
|
+
|
20
|
+
# Ignore master key for decrypting credentials and more.
|
21
|
+
/config/master.key
|
@@ -0,0 +1 @@
|
|
1
|
+
ruby-3.4.4
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
source 'https://rubygems.org'
|
4
|
+
|
5
|
+
# Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main"
|
6
|
+
gem 'rails', '~> 8.0.2'
|
7
|
+
# Use the Puma web server [https://github.com/puma/puma]
|
8
|
+
gem 'puma', '>= 6.6'
|
9
|
+
|
10
|
+
gem 'jsonrpc-middleware', path: '../../', require: 'jsonrpc' # Remove 'path' in your code
|
11
|
+
|
12
|
+
group :development, :test do
|
13
|
+
# See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem
|
14
|
+
gem 'debug', platforms: %i[mri windows], require: 'debug/prelude'
|
15
|
+
end
|
@@ -0,0 +1,261 @@
|
|
1
|
+
PATH
|
2
|
+
remote: ../..
|
3
|
+
specs:
|
4
|
+
jsonrpc-middleware (0.1.0)
|
5
|
+
dry-validation (~> 1.11)
|
6
|
+
zeitwerk (~> 2.7)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
actioncable (8.0.2)
|
12
|
+
actionpack (= 8.0.2)
|
13
|
+
activesupport (= 8.0.2)
|
14
|
+
nio4r (~> 2.0)
|
15
|
+
websocket-driver (>= 0.6.1)
|
16
|
+
zeitwerk (~> 2.6)
|
17
|
+
actionmailbox (8.0.2)
|
18
|
+
actionpack (= 8.0.2)
|
19
|
+
activejob (= 8.0.2)
|
20
|
+
activerecord (= 8.0.2)
|
21
|
+
activestorage (= 8.0.2)
|
22
|
+
activesupport (= 8.0.2)
|
23
|
+
mail (>= 2.8.0)
|
24
|
+
actionmailer (8.0.2)
|
25
|
+
actionpack (= 8.0.2)
|
26
|
+
actionview (= 8.0.2)
|
27
|
+
activejob (= 8.0.2)
|
28
|
+
activesupport (= 8.0.2)
|
29
|
+
mail (>= 2.8.0)
|
30
|
+
rails-dom-testing (~> 2.2)
|
31
|
+
actionpack (8.0.2)
|
32
|
+
actionview (= 8.0.2)
|
33
|
+
activesupport (= 8.0.2)
|
34
|
+
nokogiri (>= 1.8.5)
|
35
|
+
rack (>= 2.2.4)
|
36
|
+
rack-session (>= 1.0.1)
|
37
|
+
rack-test (>= 0.6.3)
|
38
|
+
rails-dom-testing (~> 2.2)
|
39
|
+
rails-html-sanitizer (~> 1.6)
|
40
|
+
useragent (~> 0.16)
|
41
|
+
actiontext (8.0.2)
|
42
|
+
actionpack (= 8.0.2)
|
43
|
+
activerecord (= 8.0.2)
|
44
|
+
activestorage (= 8.0.2)
|
45
|
+
activesupport (= 8.0.2)
|
46
|
+
globalid (>= 0.6.0)
|
47
|
+
nokogiri (>= 1.8.5)
|
48
|
+
actionview (8.0.2)
|
49
|
+
activesupport (= 8.0.2)
|
50
|
+
builder (~> 3.1)
|
51
|
+
erubi (~> 1.11)
|
52
|
+
rails-dom-testing (~> 2.2)
|
53
|
+
rails-html-sanitizer (~> 1.6)
|
54
|
+
activejob (8.0.2)
|
55
|
+
activesupport (= 8.0.2)
|
56
|
+
globalid (>= 0.3.6)
|
57
|
+
activemodel (8.0.2)
|
58
|
+
activesupport (= 8.0.2)
|
59
|
+
activerecord (8.0.2)
|
60
|
+
activemodel (= 8.0.2)
|
61
|
+
activesupport (= 8.0.2)
|
62
|
+
timeout (>= 0.4.0)
|
63
|
+
activestorage (8.0.2)
|
64
|
+
actionpack (= 8.0.2)
|
65
|
+
activejob (= 8.0.2)
|
66
|
+
activerecord (= 8.0.2)
|
67
|
+
activesupport (= 8.0.2)
|
68
|
+
marcel (~> 1.0)
|
69
|
+
activesupport (8.0.2)
|
70
|
+
base64
|
71
|
+
benchmark (>= 0.3)
|
72
|
+
bigdecimal
|
73
|
+
concurrent-ruby (~> 1.0, >= 1.3.1)
|
74
|
+
connection_pool (>= 2.2.5)
|
75
|
+
drb
|
76
|
+
i18n (>= 1.6, < 2)
|
77
|
+
logger (>= 1.4.2)
|
78
|
+
minitest (>= 5.1)
|
79
|
+
securerandom (>= 0.3)
|
80
|
+
tzinfo (~> 2.0, >= 2.0.5)
|
81
|
+
uri (>= 0.13.1)
|
82
|
+
base64 (0.3.0)
|
83
|
+
benchmark (0.4.1)
|
84
|
+
bigdecimal (3.2.2)
|
85
|
+
builder (3.3.0)
|
86
|
+
concurrent-ruby (1.3.5)
|
87
|
+
connection_pool (2.5.3)
|
88
|
+
crass (1.0.6)
|
89
|
+
date (3.4.1)
|
90
|
+
debug (1.11.0)
|
91
|
+
irb (~> 1.10)
|
92
|
+
reline (>= 0.3.8)
|
93
|
+
drb (2.2.3)
|
94
|
+
dry-configurable (1.3.0)
|
95
|
+
dry-core (~> 1.1)
|
96
|
+
zeitwerk (~> 2.6)
|
97
|
+
dry-core (1.1.0)
|
98
|
+
concurrent-ruby (~> 1.0)
|
99
|
+
logger
|
100
|
+
zeitwerk (~> 2.6)
|
101
|
+
dry-inflector (1.2.0)
|
102
|
+
dry-initializer (3.2.0)
|
103
|
+
dry-logic (1.6.0)
|
104
|
+
bigdecimal
|
105
|
+
concurrent-ruby (~> 1.0)
|
106
|
+
dry-core (~> 1.1)
|
107
|
+
zeitwerk (~> 2.6)
|
108
|
+
dry-schema (1.14.1)
|
109
|
+
concurrent-ruby (~> 1.0)
|
110
|
+
dry-configurable (~> 1.0, >= 1.0.1)
|
111
|
+
dry-core (~> 1.1)
|
112
|
+
dry-initializer (~> 3.2)
|
113
|
+
dry-logic (~> 1.5)
|
114
|
+
dry-types (~> 1.8)
|
115
|
+
zeitwerk (~> 2.6)
|
116
|
+
dry-types (1.8.3)
|
117
|
+
bigdecimal (~> 3.0)
|
118
|
+
concurrent-ruby (~> 1.0)
|
119
|
+
dry-core (~> 1.0)
|
120
|
+
dry-inflector (~> 1.0)
|
121
|
+
dry-logic (~> 1.4)
|
122
|
+
zeitwerk (~> 2.6)
|
123
|
+
dry-validation (1.11.1)
|
124
|
+
concurrent-ruby (~> 1.0)
|
125
|
+
dry-core (~> 1.1)
|
126
|
+
dry-initializer (~> 3.2)
|
127
|
+
dry-schema (~> 1.14)
|
128
|
+
zeitwerk (~> 2.6)
|
129
|
+
erb (5.0.1)
|
130
|
+
erubi (1.13.1)
|
131
|
+
globalid (1.2.1)
|
132
|
+
activesupport (>= 6.1)
|
133
|
+
i18n (1.14.7)
|
134
|
+
concurrent-ruby (~> 1.0)
|
135
|
+
io-console (0.8.0)
|
136
|
+
irb (1.15.2)
|
137
|
+
pp (>= 0.6.0)
|
138
|
+
rdoc (>= 4.0.0)
|
139
|
+
reline (>= 0.4.2)
|
140
|
+
logger (1.7.0)
|
141
|
+
loofah (2.24.1)
|
142
|
+
crass (~> 1.0.2)
|
143
|
+
nokogiri (>= 1.12.0)
|
144
|
+
mail (2.8.1)
|
145
|
+
mini_mime (>= 0.1.1)
|
146
|
+
net-imap
|
147
|
+
net-pop
|
148
|
+
net-smtp
|
149
|
+
marcel (1.0.4)
|
150
|
+
mini_mime (1.1.5)
|
151
|
+
minitest (5.25.5)
|
152
|
+
net-imap (0.5.9)
|
153
|
+
date
|
154
|
+
net-protocol
|
155
|
+
net-pop (0.1.2)
|
156
|
+
net-protocol
|
157
|
+
net-protocol (0.2.2)
|
158
|
+
timeout
|
159
|
+
net-smtp (0.5.1)
|
160
|
+
net-protocol
|
161
|
+
nio4r (2.7.4)
|
162
|
+
nokogiri (1.18.8-aarch64-linux-gnu)
|
163
|
+
racc (~> 1.4)
|
164
|
+
nokogiri (1.18.8-aarch64-linux-musl)
|
165
|
+
racc (~> 1.4)
|
166
|
+
nokogiri (1.18.8-arm-linux-gnu)
|
167
|
+
racc (~> 1.4)
|
168
|
+
nokogiri (1.18.8-arm-linux-musl)
|
169
|
+
racc (~> 1.4)
|
170
|
+
nokogiri (1.18.8-arm64-darwin)
|
171
|
+
racc (~> 1.4)
|
172
|
+
nokogiri (1.18.8-x86_64-darwin)
|
173
|
+
racc (~> 1.4)
|
174
|
+
nokogiri (1.18.8-x86_64-linux-gnu)
|
175
|
+
racc (~> 1.4)
|
176
|
+
nokogiri (1.18.8-x86_64-linux-musl)
|
177
|
+
racc (~> 1.4)
|
178
|
+
pp (0.6.2)
|
179
|
+
prettyprint
|
180
|
+
prettyprint (0.2.0)
|
181
|
+
psych (5.2.6)
|
182
|
+
date
|
183
|
+
stringio
|
184
|
+
puma (6.6.0)
|
185
|
+
nio4r (~> 2.0)
|
186
|
+
racc (1.8.1)
|
187
|
+
rack (3.1.16)
|
188
|
+
rack-session (2.1.1)
|
189
|
+
base64 (>= 0.1.0)
|
190
|
+
rack (>= 3.0.0)
|
191
|
+
rack-test (2.2.0)
|
192
|
+
rack (>= 1.3)
|
193
|
+
rackup (2.2.1)
|
194
|
+
rack (>= 3)
|
195
|
+
rails (8.0.2)
|
196
|
+
actioncable (= 8.0.2)
|
197
|
+
actionmailbox (= 8.0.2)
|
198
|
+
actionmailer (= 8.0.2)
|
199
|
+
actionpack (= 8.0.2)
|
200
|
+
actiontext (= 8.0.2)
|
201
|
+
actionview (= 8.0.2)
|
202
|
+
activejob (= 8.0.2)
|
203
|
+
activemodel (= 8.0.2)
|
204
|
+
activerecord (= 8.0.2)
|
205
|
+
activestorage (= 8.0.2)
|
206
|
+
activesupport (= 8.0.2)
|
207
|
+
bundler (>= 1.15.0)
|
208
|
+
railties (= 8.0.2)
|
209
|
+
rails-dom-testing (2.3.0)
|
210
|
+
activesupport (>= 5.0.0)
|
211
|
+
minitest
|
212
|
+
nokogiri (>= 1.6)
|
213
|
+
rails-html-sanitizer (1.6.2)
|
214
|
+
loofah (~> 2.21)
|
215
|
+
nokogiri (>= 1.15.7, != 1.16.7, != 1.16.6, != 1.16.5, != 1.16.4, != 1.16.3, != 1.16.2, != 1.16.1, != 1.16.0.rc1, != 1.16.0)
|
216
|
+
railties (8.0.2)
|
217
|
+
actionpack (= 8.0.2)
|
218
|
+
activesupport (= 8.0.2)
|
219
|
+
irb (~> 1.13)
|
220
|
+
rackup (>= 1.0.0)
|
221
|
+
rake (>= 12.2)
|
222
|
+
thor (~> 1.0, >= 1.2.2)
|
223
|
+
zeitwerk (~> 2.6)
|
224
|
+
rake (13.3.0)
|
225
|
+
rdoc (6.14.2)
|
226
|
+
erb
|
227
|
+
psych (>= 4.0.0)
|
228
|
+
reline (0.6.1)
|
229
|
+
io-console (~> 0.5)
|
230
|
+
securerandom (0.4.1)
|
231
|
+
stringio (3.1.7)
|
232
|
+
thor (1.3.2)
|
233
|
+
timeout (0.4.3)
|
234
|
+
tzinfo (2.0.6)
|
235
|
+
concurrent-ruby (~> 1.0)
|
236
|
+
uri (1.0.3)
|
237
|
+
useragent (0.16.11)
|
238
|
+
websocket-driver (0.8.0)
|
239
|
+
base64
|
240
|
+
websocket-extensions (>= 0.1.0)
|
241
|
+
websocket-extensions (0.1.5)
|
242
|
+
zeitwerk (2.7.3)
|
243
|
+
|
244
|
+
PLATFORMS
|
245
|
+
aarch64-linux-gnu
|
246
|
+
aarch64-linux-musl
|
247
|
+
arm-linux-gnu
|
248
|
+
arm-linux-musl
|
249
|
+
arm64-darwin
|
250
|
+
x86_64-darwin
|
251
|
+
x86_64-linux-gnu
|
252
|
+
x86_64-linux-musl
|
253
|
+
|
254
|
+
DEPENDENCIES
|
255
|
+
debug
|
256
|
+
jsonrpc-middleware!
|
257
|
+
puma (>= 6.6)
|
258
|
+
rails (~> 8.0.2)
|
259
|
+
|
260
|
+
BUNDLED WITH
|
261
|
+
2.6.9
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# Rails Calculator
|
2
|
+
|
3
|
+
A JSON-RPC calculator server using Rails with JSONRPC helpers.
|
4
|
+
|
5
|
+
## Running
|
6
|
+
|
7
|
+
```sh
|
8
|
+
bundle install
|
9
|
+
bundle exec rails server # or bin/dev
|
10
|
+
```
|
11
|
+
|
12
|
+
## API
|
13
|
+
|
14
|
+
The server implements a calculator with these procedures:
|
15
|
+
|
16
|
+
- `add` - Add numbers (supports both positional and named arguments)
|
17
|
+
- `subtract` - Subtract two numbers
|
18
|
+
- `multiply` - Multiply two numbers
|
19
|
+
- `divide` - Divide two numbers
|
20
|
+
- `explode` - Test procedure that throws an error
|
21
|
+
|
22
|
+
## Example Requests
|
23
|
+
|
24
|
+
```sh
|
25
|
+
curl -X POST http://localhost:3000 \
|
26
|
+
-H "Content-Type: application/json" \
|
27
|
+
-d '{"jsonrpc": "2.0", "method": "add", "params": {"addends": [1, 2, 3]}, "id": 1}'
|
28
|
+
|
29
|
+
curl -X POST http://localhost:3000 \
|
30
|
+
-H "Content-Type: application/json" \
|
31
|
+
-d '{"jsonrpc": "2.0", "method": "divide", "params": {"dividend": 20, "divisor": 4}, "id": 4}'
|
32
|
+
```
|
@@ -0,0 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Add your own tasks in files placed in lib/tasks ending in .rake,
|
4
|
+
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
|
5
|
+
|
6
|
+
require_relative 'config/application'
|
7
|
+
|
8
|
+
Rails.application.load_tasks
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Define the JSONRPC controller
|
4
|
+
class JsonrpcController < ApplicationController
|
5
|
+
def handle
|
6
|
+
if jsonrpc_request?
|
7
|
+
result = handle_single(jsonrpc_request)
|
8
|
+
render jsonrpc: result
|
9
|
+
elsif jsonrpc_notification?
|
10
|
+
handle_single(jsonrpc_notification)
|
11
|
+
render jsonrpc: nil
|
12
|
+
else
|
13
|
+
responses = handle_batch(jsonrpc_batch)
|
14
|
+
render jsonrpc: responses
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def handle_single(request_or_notification)
|
21
|
+
params = request_or_notification.params
|
22
|
+
|
23
|
+
case request_or_notification.method
|
24
|
+
when 'add'
|
25
|
+
addends = params.is_a?(Array) ? params : params['addends'] # Handle positional and named arguments
|
26
|
+
addends.sum
|
27
|
+
when 'subtract'
|
28
|
+
params['minuend'] - params['subtrahend']
|
29
|
+
when 'multiply'
|
30
|
+
params['multiplicand'] * params['multiplier']
|
31
|
+
when 'divide'
|
32
|
+
params['dividend'] / params['divisor']
|
33
|
+
when 'explode'
|
34
|
+
raise 'An internal error has occurred.'
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def handle_batch(batch)
|
39
|
+
batch.flat_map do |request_or_notification|
|
40
|
+
result = handle_single(request_or_notification)
|
41
|
+
JSONRPC::Response.new(id: request_or_notification.id, result:) if request_or_notification.is_a?(JSONRPC::Request)
|
42
|
+
end.compact
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'fileutils'
|
5
|
+
|
6
|
+
APP_ROOT = File.expand_path('..', __dir__)
|
7
|
+
|
8
|
+
def system!(*)
|
9
|
+
system(*, exception: true)
|
10
|
+
end
|
11
|
+
|
12
|
+
FileUtils.chdir APP_ROOT do
|
13
|
+
# This script is a way to set up or update your development environment automatically.
|
14
|
+
# This script is idempotent, so that you can run it at any time and get an expectable outcome.
|
15
|
+
# Add necessary setup steps to this file.
|
16
|
+
|
17
|
+
puts '== Installing dependencies =='
|
18
|
+
system('bundle check') || system!('bundle install')
|
19
|
+
|
20
|
+
puts "\n== Removing old logs and tempfiles =="
|
21
|
+
system! 'bin/rails log:clear tmp:clear'
|
22
|
+
|
23
|
+
unless ARGV.include?('--skip-server')
|
24
|
+
puts "\n== Starting development server =="
|
25
|
+
$stdout.flush # flush the output before exec(2) so that it displays
|
26
|
+
exec 'bin/dev'
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'boot'
|
4
|
+
|
5
|
+
require 'rails'
|
6
|
+
# Pick the frameworks you want:
|
7
|
+
require 'active_model/railtie'
|
8
|
+
# require "active_job/railtie"
|
9
|
+
# require "active_record/railtie"
|
10
|
+
# require "active_storage/engine"
|
11
|
+
require 'action_controller/railtie'
|
12
|
+
# require "action_mailer/railtie"
|
13
|
+
# require "action_mailbox/engine"
|
14
|
+
# require "action_text/engine"
|
15
|
+
require 'action_view/railtie'
|
16
|
+
# require "action_cable/engine"
|
17
|
+
# require "rails/test_unit/railtie"
|
18
|
+
|
19
|
+
# Require the gems listed in Gemfile, including any gems
|
20
|
+
# you've limited to :test, :development, or :production.
|
21
|
+
Bundler.require(*Rails.groups)
|
22
|
+
|
23
|
+
module Calculator
|
24
|
+
# JSON-RPC calculator in Rails
|
25
|
+
class Application < Rails::Application
|
26
|
+
# Initialize configuration defaults for originally generated Rails version.
|
27
|
+
config.load_defaults 8.0
|
28
|
+
|
29
|
+
# Please, add to the `ignore` list any other `lib` subdirectories that do
|
30
|
+
# not contain `.rb` files, or that should not be reloaded or eager loaded.
|
31
|
+
# Common ones are `templates`, `generators`, or `middleware`, for example.
|
32
|
+
config.autoload_lib(ignore: %w[assets tasks])
|
33
|
+
|
34
|
+
# Configuration for the application, engines, and railties goes here.
|
35
|
+
#
|
36
|
+
# These settings can be overridden in specific environments using the files
|
37
|
+
# in config/environments, which are processed later.
|
38
|
+
#
|
39
|
+
# config.time_zone = "Central Time (US & Canada)"
|
40
|
+
# config.eager_load_paths << Rails.root.join("extras")
|
41
|
+
|
42
|
+
# Only loads a smaller set of middleware suitable for API only apps.
|
43
|
+
# Middleware like session, flash, cookies can be added back manually.
|
44
|
+
# Skip views, helpers and assets when generating a new resource.
|
45
|
+
config.api_only = true
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
36y/1NnsoJQAXYvZO2PBhD+3RDetykRs5RftkLhUg6uDMvM1M5NY1qfELWvFjAukLRcUuafXJLh/yaWW17VHPHOjje1lzthu/nbKazVuA6hubOtToH5sFugssqK65m9GynlJ/zkLMf4fK+GqEpplOAR8v4xN9C7r8UOB7Gz2xHeTyi0odLIPw2/wsXd286bI5GOsA1hTXHmlMU0B7fFkizOXSy7Tns87SyjITG+gIZtCaBAiD6M8WKT8Lr92vV7C+t25HscCZ700rYG8PtgbS9vM2w2aw1h0Zcw7ZcqAd61anNRZWlZDLQ9MQvGTkRG9KZjvvBUwahAVdMlPl0Hv0a2GQQ88CKITgb2zFE0x7FULCVgKe89ThVHML7pUATqSR1L3d1jeHNLnQArwp15SR7eAVEE4KrDGKdEU9hlN5aCVz7kkNJx9UV6RxMdb/bOkrJ1TAbEPW/5SQsOHdvSuNNt9ebcxWponGmRLSrZjy8tIZa6UDyUFMwWB--dFmtfprKoGpwEIx2--Kn/9EtQ3D6HvUb6uW+I6tg==
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_support/core_ext/integer/time'
|
4
|
+
|
5
|
+
Rails.application.configure do
|
6
|
+
# Settings specified here will take precedence over those in config/application.rb.
|
7
|
+
|
8
|
+
# Make code changes take effect immediately without server restart.
|
9
|
+
config.enable_reloading = true
|
10
|
+
|
11
|
+
# Do not eager load code on boot.
|
12
|
+
config.eager_load = false
|
13
|
+
|
14
|
+
# Show full error reports.
|
15
|
+
config.consider_all_requests_local = true
|
16
|
+
|
17
|
+
# Enable server timing.
|
18
|
+
config.server_timing = true
|
19
|
+
|
20
|
+
# Enable/disable Action Controller caching. By default Action Controller caching is disabled.
|
21
|
+
# Run rails dev:cache to toggle Action Controller caching.
|
22
|
+
if Rails.root.join('tmp/caching-dev.txt').exist?
|
23
|
+
config.public_file_server.headers = { 'cache-control' => "public, max-age=#{2.days.to_i}" }
|
24
|
+
else
|
25
|
+
config.action_controller.perform_caching = false
|
26
|
+
end
|
27
|
+
|
28
|
+
# Change to :null_store to avoid any caching.
|
29
|
+
config.cache_store = :memory_store
|
30
|
+
|
31
|
+
# Print deprecation notices to the Rails logger.
|
32
|
+
config.active_support.deprecation = :log
|
33
|
+
|
34
|
+
# Raises error for missing translations.
|
35
|
+
# config.i18n.raise_on_missing_translations = true
|
36
|
+
|
37
|
+
# Annotate rendered view with file names.
|
38
|
+
config.action_view.annotate_rendered_view_with_filenames = true
|
39
|
+
|
40
|
+
# Raise error when a before_action's only/except options reference missing actions.
|
41
|
+
config.action_controller.raise_on_missing_callback_actions = true
|
42
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_support/core_ext/integer/time'
|
4
|
+
|
5
|
+
Rails.application.configure do
|
6
|
+
# Settings specified here will take precedence over those in config/application.rb.
|
7
|
+
|
8
|
+
# Code is not reloaded between requests.
|
9
|
+
config.enable_reloading = false
|
10
|
+
|
11
|
+
# Eager load code on boot for better performance and memory savings (ignored by Rake tasks).
|
12
|
+
config.eager_load = true
|
13
|
+
|
14
|
+
# Full error reports are disabled.
|
15
|
+
config.consider_all_requests_local = false
|
16
|
+
|
17
|
+
# Cache assets for far-future expiry since they are all digest stamped.
|
18
|
+
config.public_file_server.headers = { 'cache-control' => "public, max-age=#{1.year.to_i}" }
|
19
|
+
|
20
|
+
# Enable serving of images, stylesheets, and JavaScripts from an asset server.
|
21
|
+
# config.asset_host = "http://assets.example.com"
|
22
|
+
|
23
|
+
# Assume all access to the app is happening through a SSL-terminating reverse proxy.
|
24
|
+
config.assume_ssl = true
|
25
|
+
|
26
|
+
# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
|
27
|
+
config.force_ssl = true
|
28
|
+
|
29
|
+
# Skip http-to-https redirect for the default health check endpoint.
|
30
|
+
# config.ssl_options = { redirect: { exclude: ->(request) { request.path == "/up" } } }
|
31
|
+
|
32
|
+
# Log to STDOUT with the current request id as a default log tag.
|
33
|
+
config.log_tags = [:request_id]
|
34
|
+
config.logger = ActiveSupport::TaggedLogging.logger($stdout)
|
35
|
+
|
36
|
+
# Change to "debug" to log everything (including potentially personally-identifiable information!)
|
37
|
+
config.log_level = ENV.fetch('RAILS_LOG_LEVEL', 'info')
|
38
|
+
|
39
|
+
# Prevent health checks from clogging up the logs.
|
40
|
+
config.silence_healthcheck_path = '/up'
|
41
|
+
|
42
|
+
# Don't log any deprecations.
|
43
|
+
config.active_support.report_deprecations = false
|
44
|
+
|
45
|
+
# Replace the default in-process memory cache store with a durable alternative.
|
46
|
+
# config.cache_store = :mem_cache_store
|
47
|
+
|
48
|
+
# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
|
49
|
+
# the I18n.default_locale when a translation cannot be found).
|
50
|
+
config.i18n.fallbacks = true
|
51
|
+
|
52
|
+
# Enable DNS rebinding protection and other `Host` header attacks.
|
53
|
+
# config.hosts = [
|
54
|
+
# "example.com", # Allow requests from example.com
|
55
|
+
# /.*\.example\.com/ # Allow requests from subdomains like `www.example.com`
|
56
|
+
# ]
|
57
|
+
#
|
58
|
+
# Skip DNS rebinding protection for the default health check endpoint.
|
59
|
+
# config.host_authorization = { exclude: ->(request) { request.path == "/up" } }
|
60
|
+
end
|