zleb 0.1.6
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 +7 -0
- data/.gitignore +11 -0
- data/.rake_tasks~ +7 -0
- data/.rspec +3 -0
- data/.ruby-version +1 -0
- data/.travis.yml +6 -0
- data/Gemfile +9 -0
- data/Gemfile.lock +131 -0
- data/LICENSE.txt +21 -0
- data/README.md +40 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/build.sh +1 -0
- data/config/errors.yml +218 -0
- data/lib/zleb/controller.rb +33 -0
- data/lib/zleb/plugins/api_route.rb +21 -0
- data/lib/zleb/plugins/basic_restful_action.rb +212 -0
- data/lib/zleb/plugins/dry_schema_enhance.rb +44 -0
- data/lib/zleb/plugins/http_auth.rb +70 -0
- data/lib/zleb/plugins/method_route.rb +59 -0
- data/lib/zleb/plugins/params_check.rb +312 -0
- data/lib/zleb/plugins/params_snake_keys.rb +33 -0
- data/lib/zleb/plugins/render_static.rb +142 -0
- data/lib/zleb/plugins/schema_compiler.rb +293 -0
- data/lib/zleb/plugins/uni_logger.rb +18 -0
- data/lib/zleb/symbolize_helper.rb +19 -0
- data/lib/zleb/version.rb +3 -0
- data/lib/zleb.rb +133 -0
- data/push.sh +3 -0
- data/zleb.gemspec +43 -0
- metadata +248 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 99c996b6bada8154522d4a5f3b86f57d6f261fdd5f9b0dd7acf9f175f809ab71
|
|
4
|
+
data.tar.gz: 8eacdc3dfe744e344b30cc163bd9a4486770622d451a7d39681ae1d7d78f953d
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: '08007014375d2ff5d452d338059891bcdde37a876eb966e509686b678e5d6ac7872f468aa5d6c5abb5bab61b254d906c9019c3c8760ff29ac3338c9beb132998'
|
|
7
|
+
data.tar.gz: bbd9fe508ee3945a819972aa81b54efb32a825ed3913a3f4f184c94f5f303f9d5a20954b931680992f4b5c2d453e981a4e11035f556eaa20d941975296462f64
|
data/.gitignore
ADDED
data/.rake_tasks~
ADDED
data/.rspec
ADDED
data/.ruby-version
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
ruby-3.1.1
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
zleb (0.1.6)
|
|
5
|
+
awrence (~> 1.2, >= 1.2.1)
|
|
6
|
+
concurrent-ruby
|
|
7
|
+
dry-container (~> 0.7)
|
|
8
|
+
dry-schema (= 1.13.3)
|
|
9
|
+
dry-validation (~> 1.6)
|
|
10
|
+
plissken (~> 1.4, >= 1.4.1)
|
|
11
|
+
puma (~> 6.4)
|
|
12
|
+
roda (~> 3.52)
|
|
13
|
+
roda-symbolized_params (~> 0.0.2)
|
|
14
|
+
semantic_logger (~> 4.7, >= 4.7.4)
|
|
15
|
+
|
|
16
|
+
GEM
|
|
17
|
+
remote: https://gems.ruby-china.com/
|
|
18
|
+
specs:
|
|
19
|
+
awrence (1.2.1)
|
|
20
|
+
bigdecimal (4.1.0-java)
|
|
21
|
+
concurrent-ruby (1.3.6)
|
|
22
|
+
diff-lcs (1.6.2)
|
|
23
|
+
dry-configurable (1.3.0)
|
|
24
|
+
dry-core (~> 1.1)
|
|
25
|
+
zeitwerk (~> 2.6)
|
|
26
|
+
dry-container (0.11.0)
|
|
27
|
+
concurrent-ruby (~> 1.0)
|
|
28
|
+
dry-core (1.2.0)
|
|
29
|
+
concurrent-ruby (~> 1.0)
|
|
30
|
+
logger
|
|
31
|
+
zeitwerk (~> 2.6)
|
|
32
|
+
dry-inflector (1.3.1)
|
|
33
|
+
dry-initializer (3.2.0)
|
|
34
|
+
dry-logic (1.6.0)
|
|
35
|
+
bigdecimal
|
|
36
|
+
concurrent-ruby (~> 1.0)
|
|
37
|
+
dry-core (~> 1.1)
|
|
38
|
+
zeitwerk (~> 2.6)
|
|
39
|
+
dry-schema (1.13.3)
|
|
40
|
+
concurrent-ruby (~> 1.0)
|
|
41
|
+
dry-configurable (~> 1.0, >= 1.0.1)
|
|
42
|
+
dry-core (~> 1.0, < 2)
|
|
43
|
+
dry-initializer (~> 3.0)
|
|
44
|
+
dry-logic (>= 1.4, < 2)
|
|
45
|
+
dry-types (>= 1.7, < 2)
|
|
46
|
+
zeitwerk (~> 2.6)
|
|
47
|
+
dry-types (1.9.1)
|
|
48
|
+
bigdecimal (>= 3.0)
|
|
49
|
+
concurrent-ruby (~> 1.0)
|
|
50
|
+
dry-core (~> 1.0)
|
|
51
|
+
dry-inflector (~> 1.0)
|
|
52
|
+
dry-logic (~> 1.4)
|
|
53
|
+
zeitwerk (~> 2.6)
|
|
54
|
+
dry-validation (1.10.0)
|
|
55
|
+
concurrent-ruby (~> 1.0)
|
|
56
|
+
dry-core (~> 1.0, < 2)
|
|
57
|
+
dry-initializer (~> 3.0)
|
|
58
|
+
dry-schema (>= 1.12, < 2)
|
|
59
|
+
zeitwerk (~> 2.6)
|
|
60
|
+
logger (1.7.0)
|
|
61
|
+
nio4r (2.7.5-java)
|
|
62
|
+
plissken (1.4.1)
|
|
63
|
+
puma (6.6.1-java)
|
|
64
|
+
nio4r (~> 2.0)
|
|
65
|
+
rack (3.2.5)
|
|
66
|
+
rack-test (2.2.0)
|
|
67
|
+
rack (>= 1.3)
|
|
68
|
+
rake (12.3.3)
|
|
69
|
+
roda (3.102.0)
|
|
70
|
+
rack
|
|
71
|
+
roda-symbolized_params (0.0.2)
|
|
72
|
+
rspec (3.13.2)
|
|
73
|
+
rspec-core (~> 3.13.0)
|
|
74
|
+
rspec-expectations (~> 3.13.0)
|
|
75
|
+
rspec-mocks (~> 3.13.0)
|
|
76
|
+
rspec-core (3.13.6)
|
|
77
|
+
rspec-support (~> 3.13.0)
|
|
78
|
+
rspec-expectations (3.13.5)
|
|
79
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
80
|
+
rspec-support (~> 3.13.0)
|
|
81
|
+
rspec-mocks (3.13.8)
|
|
82
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
83
|
+
rspec-support (~> 3.13.0)
|
|
84
|
+
rspec-support (3.13.7)
|
|
85
|
+
semantic_logger (4.17.0)
|
|
86
|
+
concurrent-ruby (~> 1.0)
|
|
87
|
+
zeitwerk (2.7.5)
|
|
88
|
+
|
|
89
|
+
PLATFORMS
|
|
90
|
+
universal-java
|
|
91
|
+
|
|
92
|
+
DEPENDENCIES
|
|
93
|
+
rack-test
|
|
94
|
+
rake (~> 12.0)
|
|
95
|
+
rspec (~> 3.0)
|
|
96
|
+
zleb!
|
|
97
|
+
|
|
98
|
+
CHECKSUMS
|
|
99
|
+
awrence (1.2.1) sha256=dd1d214c12a91f449d1ef81d7ee3babc2816944e450752e7522c65521872483e
|
|
100
|
+
bigdecimal (4.1.0-java) sha256=1623930ea8e5187d4229f2857f129a83247ccd1cade71a4bc7d8bf3b41bbba59
|
|
101
|
+
concurrent-ruby (1.3.6) sha256=6b56837e1e7e5292f9864f34b69c5a2cbc75c0cf5338f1ce9903d10fa762d5ab
|
|
102
|
+
diff-lcs (1.6.2) sha256=9ae0d2cba7d4df3075fe8cd8602a8604993efc0dfa934cff568969efb1909962
|
|
103
|
+
dry-configurable (1.3.0) sha256=882d862858567fc1210d2549d4c090f34370fc1bb7c5c1933de3fe792e18afa8
|
|
104
|
+
dry-container (0.11.0) sha256=23be9381644d47343f3bf13b082b4255994ada0bfd88e0737eaaadc99d035229
|
|
105
|
+
dry-core (1.2.0) sha256=0cc5a7da88df397f153947eeeae42e876e999c1e30900f3c536fb173854e96a1
|
|
106
|
+
dry-inflector (1.3.1) sha256=7fb0c2bb04f67638f25c52e7ba39ab435d922a3a5c3cd196120f63accb682dcc
|
|
107
|
+
dry-initializer (3.2.0) sha256=37d59798f912dc0a1efe14a4db4a9306989007b302dcd5f25d0a2a20c166c4e3
|
|
108
|
+
dry-logic (1.6.0) sha256=da6fedbc0f90fc41f9b0cc7e6f05f5d529d1efaef6c8dcc8e0733f685745cea2
|
|
109
|
+
dry-schema (1.13.3) sha256=ff0ec847c7986ddb76145f9426ddacaa68c28b170c0f626fb8d30fcb431393e3
|
|
110
|
+
dry-types (1.9.1) sha256=baebeecdb9f8395d6c9d227b62011279440943e3ef2468fe8ccc1ba11467f178
|
|
111
|
+
dry-validation (1.10.0) sha256=352afd75629772570f54f03d3e7847ac345e628bf345874d49f1dabacc8ceaac
|
|
112
|
+
logger (1.7.0) sha256=196edec7cc44b66cfb40f9755ce11b392f21f7967696af15d274dde7edff0203
|
|
113
|
+
nio4r (2.7.5-java) sha256=d14779d2a9b012ec0148a53344fbb2ed2a3c4d90c5dd923bf281135ab983b2c9
|
|
114
|
+
plissken (1.4.1) sha256=d8cf78eefb50e4109130e476f599e6f9c0912b7d8733fe167f8cff9dcf7ae50d
|
|
115
|
+
puma (6.6.1-java) sha256=b5384f7320e3ceb5aa41c729f5ebbde360394aa8f77fcb82a092d63f8512c9c4
|
|
116
|
+
rack (3.2.5) sha256=4cbd0974c0b79f7a139b4812004a62e4c60b145cba76422e288ee670601ed6d3
|
|
117
|
+
rack-test (2.2.0) sha256=005a36692c306ac0b4a9350355ee080fd09ddef1148a5f8b2ac636c720f5c463
|
|
118
|
+
rake (12.3.3) sha256=f7694adb4fe638da35452300cee6c545e9c377a0e3190018ac04d590b3c26ab3
|
|
119
|
+
roda (3.102.0) sha256=b2156fff6d2b1b52bfac39e4ccde0d820a26594f069c3d9e99cc0853f7ee7dcc
|
|
120
|
+
roda-symbolized_params (0.0.2) sha256=966f501f3775dbd4830e48ce99d14387ee8543ceea79f0ee58bd317db488179d
|
|
121
|
+
rspec (3.13.2) sha256=206284a08ad798e61f86d7ca3e376718d52c0bc944626b2349266f239f820587
|
|
122
|
+
rspec-core (3.13.6) sha256=a8823c6411667b60a8bca135364351dda34cd55e44ff94c4be4633b37d828b2d
|
|
123
|
+
rspec-expectations (3.13.5) sha256=33a4d3a1d95060aea4c94e9f237030a8f9eae5615e9bd85718fe3a09e4b58836
|
|
124
|
+
rspec-mocks (3.13.8) sha256=086ad3d3d17533f4237643de0b5c42f04b66348c28bf6b9c2d3f4a3b01af1d47
|
|
125
|
+
rspec-support (3.13.7) sha256=0640e5570872aafefd79867901deeeeb40b0c9875a36b983d85f54fb7381c47c
|
|
126
|
+
semantic_logger (4.17.0) sha256=c54b60d8596abe2e22bd4f20648d4f6c46e4287fba357779c7932335c8d130e9
|
|
127
|
+
zeitwerk (2.7.5) sha256=d8da92128c09ea6ec62c949011b00ed4a20242b255293dd66bf41545398f73dd
|
|
128
|
+
zleb (0.1.6)
|
|
129
|
+
|
|
130
|
+
BUNDLED WITH
|
|
131
|
+
4.0.9
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 saidev
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# Zleb
|
|
2
|
+
|
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/zleb`. To experiment with that code, run `bin/console` for an interactive prompt.
|
|
4
|
+
|
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
Add this line to your application's Gemfile:
|
|
10
|
+
|
|
11
|
+
```ruby
|
|
12
|
+
gem 'zleb'
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
And then execute:
|
|
16
|
+
|
|
17
|
+
$ bundle install
|
|
18
|
+
|
|
19
|
+
Or install it yourself as:
|
|
20
|
+
|
|
21
|
+
$ gem install zleb
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
TODO: Write usage instructions here
|
|
26
|
+
|
|
27
|
+
## Development
|
|
28
|
+
|
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
30
|
+
|
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
|
32
|
+
|
|
33
|
+
## Contributing
|
|
34
|
+
|
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/zleb.
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
## License
|
|
39
|
+
|
|
40
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require "bundler/setup"
|
|
4
|
+
require "zleb"
|
|
5
|
+
|
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
|
8
|
+
|
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
|
10
|
+
# require "pry"
|
|
11
|
+
# Pry.start
|
|
12
|
+
|
|
13
|
+
require "irb"
|
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/build.sh
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
rake build
|
data/config/errors.yml
ADDED
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
en:
|
|
2
|
+
dry_validation:
|
|
3
|
+
or: "or"
|
|
4
|
+
|
|
5
|
+
errors:
|
|
6
|
+
unexpected_key: "is not allowed"
|
|
7
|
+
|
|
8
|
+
array?: "must be an array"
|
|
9
|
+
|
|
10
|
+
empty?: "must be empty"
|
|
11
|
+
|
|
12
|
+
excludes?: "must not include %{value}"
|
|
13
|
+
|
|
14
|
+
excluded_from?:
|
|
15
|
+
arg:
|
|
16
|
+
default: "must not be one of: %{list}"
|
|
17
|
+
range: "must not be one of: %{list_left} - %{list_right}"
|
|
18
|
+
|
|
19
|
+
exclusion?: "must not be one of: %{list}"
|
|
20
|
+
|
|
21
|
+
eql?: "must be equal to %{left}"
|
|
22
|
+
|
|
23
|
+
not_eql?: "must not be equal to %{left}"
|
|
24
|
+
|
|
25
|
+
filled?: "must be filled"
|
|
26
|
+
|
|
27
|
+
format?: "is in invalid format"
|
|
28
|
+
|
|
29
|
+
number?: "must be a number"
|
|
30
|
+
|
|
31
|
+
odd?: "must be odd"
|
|
32
|
+
|
|
33
|
+
even?: "must be even"
|
|
34
|
+
|
|
35
|
+
gt?: "must be greater than %{num}"
|
|
36
|
+
|
|
37
|
+
gteq?: "must be greater than or equal to %{num}"
|
|
38
|
+
|
|
39
|
+
hash?: "must be a hash"
|
|
40
|
+
|
|
41
|
+
included_in?:
|
|
42
|
+
arg:
|
|
43
|
+
default: "must be one of: %{list}"
|
|
44
|
+
range: "must be one of: %{list_left} - %{list_right}"
|
|
45
|
+
|
|
46
|
+
inclusion?: "must be one of: %{list}"
|
|
47
|
+
|
|
48
|
+
includes?: "must include %{value}"
|
|
49
|
+
|
|
50
|
+
bool?: "must be boolean"
|
|
51
|
+
|
|
52
|
+
true?: "must be true"
|
|
53
|
+
|
|
54
|
+
false?: "must be false"
|
|
55
|
+
|
|
56
|
+
int?: "must be an integer"
|
|
57
|
+
|
|
58
|
+
float?: "must be a float"
|
|
59
|
+
|
|
60
|
+
decimal?: "must be a decimal"
|
|
61
|
+
|
|
62
|
+
date?: "must be a date"
|
|
63
|
+
|
|
64
|
+
date_time?: "must be a date time"
|
|
65
|
+
|
|
66
|
+
time?: "must be a time"
|
|
67
|
+
|
|
68
|
+
key?: "is missing1"
|
|
69
|
+
|
|
70
|
+
attr?: "is missing2"
|
|
71
|
+
|
|
72
|
+
lt?: "must be less than %{num}"
|
|
73
|
+
|
|
74
|
+
lteq?: "must be less than or equal to %{num}"
|
|
75
|
+
|
|
76
|
+
max_size?: "size cannot be greater than %{num}"
|
|
77
|
+
|
|
78
|
+
max_bytesize?: "bytesize cannot be greater than %{num}"
|
|
79
|
+
|
|
80
|
+
min_size?: "size cannot be less than %{num}"
|
|
81
|
+
|
|
82
|
+
min_bytesize?: "bytesize cannot be less than %{num}"
|
|
83
|
+
|
|
84
|
+
nil?: "cannot be defined"
|
|
85
|
+
|
|
86
|
+
str?: "must be a string"
|
|
87
|
+
|
|
88
|
+
type?: "must be %{type}"
|
|
89
|
+
|
|
90
|
+
size?:
|
|
91
|
+
arg:
|
|
92
|
+
default: "size must be %{size}"
|
|
93
|
+
range: "size must be within %{size_left} - %{size_right}"
|
|
94
|
+
|
|
95
|
+
value:
|
|
96
|
+
string:
|
|
97
|
+
arg:
|
|
98
|
+
default: "length must be %{size}"
|
|
99
|
+
range: "length must be within %{size_left} - %{size_right}"
|
|
100
|
+
|
|
101
|
+
bytesize?:
|
|
102
|
+
arg:
|
|
103
|
+
default: "must be %{size} bytes long"
|
|
104
|
+
range: "must be within %{size_left} - %{size_right} bytes long"
|
|
105
|
+
|
|
106
|
+
uuid_v4?: "is not a valid UUID"
|
|
107
|
+
|
|
108
|
+
not:
|
|
109
|
+
empty?: "cannot be empty"
|
|
110
|
+
cn:
|
|
111
|
+
dry_validation:
|
|
112
|
+
or: "或者"
|
|
113
|
+
|
|
114
|
+
errors:
|
|
115
|
+
unexpected_key: "不背允许的"
|
|
116
|
+
|
|
117
|
+
array?: "必须是一个数组"
|
|
118
|
+
|
|
119
|
+
empty?: "必须为空"
|
|
120
|
+
|
|
121
|
+
excludes?: "必须不包含 %{value}"
|
|
122
|
+
|
|
123
|
+
excluded_from?:
|
|
124
|
+
arg:
|
|
125
|
+
default: "必须不在: %{list} 当中"
|
|
126
|
+
range: "必须不在: %{list_left} - %{list_right} 之间"
|
|
127
|
+
|
|
128
|
+
exclusion?: "必须不在: %{list} 当中"
|
|
129
|
+
|
|
130
|
+
eql?: "必须等于 %{left}"
|
|
131
|
+
|
|
132
|
+
not_eql?: "必须不等于 %{left}"
|
|
133
|
+
|
|
134
|
+
filled?: "必须提供"
|
|
135
|
+
|
|
136
|
+
format?: "不是一个正确的格式"
|
|
137
|
+
|
|
138
|
+
number?: "必须是一个数字"
|
|
139
|
+
|
|
140
|
+
odd?: "必须是奇数"
|
|
141
|
+
|
|
142
|
+
even?: "必须是偶数"
|
|
143
|
+
|
|
144
|
+
gt?: "必须大于 %{num}"
|
|
145
|
+
|
|
146
|
+
gteq?: "必须大于或者等于 %{num}"
|
|
147
|
+
|
|
148
|
+
hash?: "必须是一个 hash"
|
|
149
|
+
|
|
150
|
+
included_in?:
|
|
151
|
+
arg:
|
|
152
|
+
default: "必须在: %{list} 当中"
|
|
153
|
+
range: "必须在: %{list_left} - %{list_right} 之间"
|
|
154
|
+
|
|
155
|
+
inclusion?: "必须在: %{list} 当中"
|
|
156
|
+
|
|
157
|
+
includes?: "必须包含 %{value}"
|
|
158
|
+
|
|
159
|
+
bool?: "必须是一个布尔值"
|
|
160
|
+
|
|
161
|
+
true?: "必须是 true"
|
|
162
|
+
|
|
163
|
+
false?: "必须是 false"
|
|
164
|
+
|
|
165
|
+
int?: "必须是一个整数"
|
|
166
|
+
|
|
167
|
+
float?: "必须是一个浮点数"
|
|
168
|
+
|
|
169
|
+
decimal?: "必须是一个十进制数"
|
|
170
|
+
|
|
171
|
+
date?: "必须是一个日期"
|
|
172
|
+
|
|
173
|
+
date_time?: "必须是一个日期时间"
|
|
174
|
+
|
|
175
|
+
time?: "必须是一个时间"
|
|
176
|
+
|
|
177
|
+
key?: "没有提供"
|
|
178
|
+
|
|
179
|
+
attr?: "没有提供"
|
|
180
|
+
|
|
181
|
+
lt?: "必须小于 %{num}"
|
|
182
|
+
|
|
183
|
+
lteq?: "必须小于等于 %{num}"
|
|
184
|
+
|
|
185
|
+
max_size?: "大小不能大于 %{num}"
|
|
186
|
+
|
|
187
|
+
max_bytesize?: "字节大小不能大于 %{num}"
|
|
188
|
+
|
|
189
|
+
min_size?: "大小不能小于 %{num}"
|
|
190
|
+
|
|
191
|
+
min_bytesize?: "字节大小不能小于 %{num}"
|
|
192
|
+
|
|
193
|
+
nil?: "不能有值"
|
|
194
|
+
|
|
195
|
+
str?: "必须是一个字符串"
|
|
196
|
+
|
|
197
|
+
type?: "类型必须是 %{type}"
|
|
198
|
+
|
|
199
|
+
size?:
|
|
200
|
+
arg:
|
|
201
|
+
default: "大小必须是 %{size}"
|
|
202
|
+
range: "大小必须在 %{size_left} - %{size_right} 之间"
|
|
203
|
+
|
|
204
|
+
value:
|
|
205
|
+
string:
|
|
206
|
+
arg:
|
|
207
|
+
default: "长度必须是 %{size}"
|
|
208
|
+
range: "长度必须是 %{size_left} - %{size_right} 之间"
|
|
209
|
+
|
|
210
|
+
bytesize?:
|
|
211
|
+
arg:
|
|
212
|
+
default: "字节大小必须是 %{size} "
|
|
213
|
+
range: "字节大小必须在 %{size_left} - %{size_right} 之间"
|
|
214
|
+
|
|
215
|
+
uuid_v4?: "不是一个正确的 UUID"
|
|
216
|
+
|
|
217
|
+
not:
|
|
218
|
+
empty?: "不能为空"
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
module Zleb
|
|
2
|
+
class Controller
|
|
3
|
+
attr_reader :request, :response, :headers, :params, :scope
|
|
4
|
+
def initialize(opts = {})
|
|
5
|
+
@request = opts[:request]
|
|
6
|
+
@response = opts[:response]
|
|
7
|
+
@headers = opts[:headers]
|
|
8
|
+
@params = opts[:params]
|
|
9
|
+
@scope = opts[:scope]
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def init
|
|
13
|
+
# called after new and before method
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def params_sym
|
|
17
|
+
@params_sym = @params_sym ||
|
|
18
|
+
if params
|
|
19
|
+
SymbolizeHelper.symbolize_recursive(params)
|
|
20
|
+
else
|
|
21
|
+
params
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def throw_error(message, code)
|
|
26
|
+
response.status = code
|
|
27
|
+
response['Content-Type'] = 'application/json'
|
|
28
|
+
response.write(message.to_json)
|
|
29
|
+
throw :halt, response.finish
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
require 'semantic_logger'
|
|
2
|
+
|
|
3
|
+
class Roda
|
|
4
|
+
module RodaPlugins
|
|
5
|
+
module ApiRoute
|
|
6
|
+
|
|
7
|
+
def self.load_dependencies(app, _opts = OPTS)
|
|
8
|
+
app.plugin :hash_routes
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
module ClassMethods
|
|
13
|
+
def api(segment, &block)
|
|
14
|
+
hash_branch(:api, segment, &block)
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
register_plugin(:api_route, ApiRoute)
|
|
20
|
+
end
|
|
21
|
+
end
|