rails_api_base 1.0.7 → 1.0.8
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/app/controllers/rails_api_base/base_controller.rb +10 -4
- data/lib/rails_api_base/version.rb +1 -1
- metadata +6 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e18fba691675d980ac2aa985b2e390aa45acae166602faf8601ced9820b31dc0
|
|
4
|
+
data.tar.gz: 615cfd471a33904767ef6502690355d984541f57644676905759900076de2307
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b5863ec6fdd7373b4d91d1c05fc6dc0b87f4766ba00f7a565ae499ab8e793812c1ee644f98df81791f7bc575aa9122de15aad153676a278425da3174e600ec85
|
|
7
|
+
data.tar.gz: 3faa7cdf902519e04b11cb6843f988131611be27f5cb595635603d8cfe4ef2541fe3740e8e5bff896399fe7c37f1e878581d7089b50b4e493449da3cf6b24544
|
|
@@ -10,13 +10,13 @@ module RailsApiBase
|
|
|
10
10
|
# === 统一成功响应 ===
|
|
11
11
|
def render_success(data, status: :ok, message: "success", code: nil)
|
|
12
12
|
code ||= response_code_for(action_name, status: status)
|
|
13
|
-
render json: { code: code, msg: message,
|
|
13
|
+
render json: { code: code, msg: message, data: data }, status: status
|
|
14
14
|
end
|
|
15
15
|
|
|
16
16
|
# === 统一错误响应 ===
|
|
17
17
|
def render_error(message: "Unprocessable Entity", status: :unprocessable_entity, errors: nil)
|
|
18
18
|
code = response_code_for(action_name, status: status)
|
|
19
|
-
render json: { code: code, msg: message,
|
|
19
|
+
render json: { code: code, msg: message, errors: errors }, status: status
|
|
20
20
|
end
|
|
21
21
|
|
|
22
22
|
# === 允许子类自定义响应 code ===
|
|
@@ -35,7 +35,7 @@ module RailsApiBase
|
|
|
35
35
|
def index
|
|
36
36
|
result = apply_query_with_meta(collection)
|
|
37
37
|
data = {
|
|
38
|
-
query_config[:meta][:rows_key] => serialize_collection(result[:collection])
|
|
38
|
+
query_config[:meta][:rows_key] => serialize_collection(result[:collection]),
|
|
39
39
|
}
|
|
40
40
|
data.merge!(result[:meta]) if result[:meta]
|
|
41
41
|
render_success(data)
|
|
@@ -112,6 +112,10 @@ module RailsApiBase
|
|
|
112
112
|
controller_name.singularize.classify.constantize
|
|
113
113
|
end
|
|
114
114
|
|
|
115
|
+
def resource_key
|
|
116
|
+
controller_name.singularize.underscore.to_sym
|
|
117
|
+
end
|
|
118
|
+
|
|
115
119
|
def resource
|
|
116
120
|
instance_variable_get("@#{controller_name.singularize}")
|
|
117
121
|
end
|
|
@@ -127,7 +131,9 @@ module RailsApiBase
|
|
|
127
131
|
end
|
|
128
132
|
|
|
129
133
|
def resource_params
|
|
130
|
-
raise NotImplementedError, "Subclass must implement ##{controller_name.singularize}_params"
|
|
134
|
+
# raise NotImplementedError, "Subclass must implement ##{controller_name.singularize}_params"
|
|
135
|
+
permitted_params = params.require(resource_key)
|
|
136
|
+
permitted_params.permit!
|
|
131
137
|
end
|
|
132
138
|
end
|
|
133
139
|
end
|
metadata
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: rails_api_base
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.0.
|
|
4
|
+
version: 1.0.8
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- aric.zheng
|
|
8
|
+
autorequire:
|
|
8
9
|
bindir: bin
|
|
9
10
|
cert_chain: []
|
|
10
|
-
date: 2025-11-
|
|
11
|
+
date: 2025-11-08 00:00:00.000000000 Z
|
|
11
12
|
dependencies:
|
|
12
13
|
- !ruby/object:Gem::Dependency
|
|
13
14
|
name: rails
|
|
@@ -70,6 +71,7 @@ metadata:
|
|
|
70
71
|
homepage_uri: https://js.work
|
|
71
72
|
source_code_uri: https://github.com/afeiship/rails_api_base
|
|
72
73
|
changelog_uri: https://github.com/afeiship/rails_api_base/blob/master/CHANGELOG.md
|
|
74
|
+
post_install_message:
|
|
73
75
|
rdoc_options: []
|
|
74
76
|
require_paths:
|
|
75
77
|
- lib
|
|
@@ -84,7 +86,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
84
86
|
- !ruby/object:Gem::Version
|
|
85
87
|
version: '0'
|
|
86
88
|
requirements: []
|
|
87
|
-
rubygems_version: 3.
|
|
89
|
+
rubygems_version: 3.5.22
|
|
90
|
+
signing_key:
|
|
88
91
|
specification_version: 4
|
|
89
92
|
summary: Standardized JSON API foundation for Rails apps.
|
|
90
93
|
test_files: []
|