apique 1.1.2 → 1.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/lib/apique/editable.rb +33 -4
- data/lib/apique/pickable.rb +1 -1
- data/lib/apique/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 513c3a8d2c413a70b5f0cc6060812209a966e34c
|
4
|
+
data.tar.gz: 39982ba0c78f57a14d57186a815bd09adc274b24
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d113e980a25c9da529a4dee28ea87dab9d52600dd7959dd36d2d739355e1021c76e175f6ffed5443be1ac12b677c31ae85f1b26765230365d210de6ef66ea55d
|
7
|
+
data.tar.gz: e027b55435aa903e570993fcde4db27ab161648213bb1874f9be973e8877293ec39cb7f6c33ab561c6791763d0cd309a02a06aff85fc4c6193b86a106c6047af
|
data/.gitignore
CHANGED
data/lib/apique/editable.rb
CHANGED
@@ -18,7 +18,7 @@ module Apique::Editable
|
|
18
18
|
# POST /api/{plural_resource_name}
|
19
19
|
def create
|
20
20
|
if get_resource.save
|
21
|
-
render :
|
21
|
+
render json: get_resource, status: :created
|
22
22
|
else
|
23
23
|
render json: {errors: get_resource.errors}
|
24
24
|
end
|
@@ -27,7 +27,7 @@ module Apique::Editable
|
|
27
27
|
# PATCH/PUT /api/{plural_resource_name}/{id}
|
28
28
|
def update
|
29
29
|
if get_resource.update(update_api_params)
|
30
|
-
render :
|
30
|
+
render json: get_resource
|
31
31
|
else
|
32
32
|
render json: {errors: get_resource.errors}
|
33
33
|
end
|
@@ -55,13 +55,42 @@ module Apique::Editable
|
|
55
55
|
|
56
56
|
### Basic getters-setters ###
|
57
57
|
|
58
|
+
# Puts the resource into an instance variable.
|
59
|
+
# @raise [Apique::RecordNotFound] if there is no resource found.
|
60
|
+
# @return [Object]
|
61
|
+
def set_resource(resource = nil)
|
62
|
+
resource ||= params[:id] ? resource_class.find(params[:id]) : resource_class.new(apique_create_params)
|
63
|
+
unless resource
|
64
|
+
raise RecordNotFound, "could not find a record of type #{resource_class} with id = #{params[:id]}"
|
65
|
+
end
|
66
|
+
|
67
|
+
instance_variable_set(resource_variable_name, resource)
|
68
|
+
end
|
69
|
+
|
70
|
+
# @virtual
|
71
|
+
# Filters incoming params for <model>.create statements.
|
72
|
+
def create_params
|
73
|
+
end
|
74
|
+
|
75
|
+
# @virtual
|
76
|
+
# Filters incoming params for <record>.update statements.
|
77
|
+
# Works also for <model>.create statements IF #create_params is not defined on a subclass.
|
78
|
+
# It is very recommended to redefine it unless you're sure no one would attack your API with mass-assignment.
|
79
|
+
def update_params
|
80
|
+
params[resource_name.tr('~', '_')].to_unsafe_h
|
81
|
+
end
|
82
|
+
|
58
83
|
# Only allow a trusted parameter "white list" through.
|
59
84
|
# If a single resource is loaded for #create or #update,
|
60
85
|
# then the controller for the resource must implement
|
61
86
|
# the method "update_params" to limit permitted
|
62
87
|
# parameters for the individual model.
|
63
|
-
def
|
64
|
-
@resource_params ||=
|
88
|
+
def apique_update_params
|
89
|
+
@resource_params ||= update_params
|
90
|
+
end
|
91
|
+
|
92
|
+
def apique_create_params
|
93
|
+
@resource_params ||= create_params || update_params
|
65
94
|
end
|
66
95
|
|
67
96
|
end
|
data/lib/apique/pickable.rb
CHANGED
@@ -48,7 +48,7 @@ module Apique::Pickable
|
|
48
48
|
alias_method :subject_resource, :get_resource
|
49
49
|
|
50
50
|
# Puts the resource into an instance variable.
|
51
|
-
# @raise [
|
51
|
+
# @raise [Apique::RecordNotFound] if there is no resource found.
|
52
52
|
# @return [Object]
|
53
53
|
def set_resource(resource = nil)
|
54
54
|
resource ||= resource_class.find(params[:id])
|
data/lib/apique/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: apique
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sergey Baev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-06-
|
11
|
+
date: 2017-06-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -126,7 +126,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
126
126
|
version: '0'
|
127
127
|
requirements: []
|
128
128
|
rubyforge_project:
|
129
|
-
rubygems_version: 2.
|
129
|
+
rubygems_version: 2.5.1
|
130
130
|
signing_key:
|
131
131
|
specification_version: 4
|
132
132
|
summary: Rails CRUD API replacement
|