railspp 0.3.1 → 0.3.2
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/lib/templates/global_controller.txt +31 -12
- data/lib/utils/strings.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d12230e4e45a9cbd1a0205aafff9c972a7f1831aab990a148cecc0c97ce8110d
|
4
|
+
data.tar.gz: fe1591b2d6fa3e469e887144bdc8095de02ba55ad7f601b36a65b607c705945d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d1fa597926e8388daa48d2b38090414790127124ead518fbf94904414ecdce96956f60d7645bc23680946508b18f77b6e130aec0e4f09d0c96ec3f8add14cdd7
|
7
|
+
data.tar.gz: 7289d0afed1f69822d27b38fb6c69399c4b10b2d0e30bfc208ceb2184d89414e587dafaa542f609e78640fd93a2266211d988e0dd72bea0aa189225533dc2d2a
|
@@ -14,7 +14,7 @@ class GlobalController < ApplicationController
|
|
14
14
|
resp = index_response
|
15
15
|
past_pages = resp[:last_page] < resp[:current_page]
|
16
16
|
error = {error: "Past the amount of pages available"}
|
17
|
-
status = past_pages ?
|
17
|
+
status = past_pages ? :bad_request : :ok
|
18
18
|
data = past_pages ? error : resp
|
19
19
|
data = handle_includes(data) if params[:include] && !past_pages
|
20
20
|
render_json(data, status)
|
@@ -23,45 +23,64 @@ class GlobalController < ApplicationController
|
|
23
23
|
def show
|
24
24
|
data = model.find(params[:id] || 0)
|
25
25
|
data = handle_includes(data) if params[:include]
|
26
|
-
render_json(data,
|
26
|
+
render_json(data, :ok)
|
27
27
|
end
|
28
28
|
|
29
29
|
def create
|
30
30
|
data = model.create(create_params)
|
31
|
-
render_json(data,
|
31
|
+
render_json(data, :created)
|
32
32
|
end
|
33
33
|
|
34
34
|
def update
|
35
35
|
data = model.where(id: params[:id] || 0).update(update_params).first
|
36
|
-
render_json(data,
|
36
|
+
render_json(data, :ok)
|
37
37
|
end
|
38
38
|
|
39
39
|
def destroy
|
40
40
|
model.destroy(params[:id] || 0)
|
41
|
-
render_json(nil,
|
41
|
+
render_json(nil, :no_content)
|
42
42
|
end
|
43
43
|
|
44
44
|
def bulk_csv_create
|
45
45
|
data = model.create(csv_to_json)
|
46
|
-
render_json(data,
|
46
|
+
render_json(data, :created)
|
47
47
|
end
|
48
48
|
|
49
49
|
def bulk_create
|
50
50
|
data = model.create(bulk_create_params[:bulk])
|
51
|
-
render_json(data,
|
51
|
+
render_json(data, :created)
|
52
52
|
end
|
53
53
|
|
54
54
|
def bulk_update
|
55
55
|
data = model.where(id: bulk_update_params[:bulk].map {|e| e[:id] }).update(bulk_update_params[:bulk])
|
56
|
-
render_json(data,
|
56
|
+
render_json(data, :ok)
|
57
|
+
end
|
58
|
+
|
59
|
+
def bulk_destroy
|
60
|
+
ids = comma_separated(:ids)
|
61
|
+
are_ids = array_of_integers(ids)
|
62
|
+
if ids.is_a?(Array) && are_ids
|
63
|
+
array = model.where(id: ids)
|
64
|
+
if array.length == ids.length
|
65
|
+
array.delete_all
|
66
|
+
render_json(nil, :no_content)
|
67
|
+
else
|
68
|
+
render_json({ error: "Not all ids are valid" }, :bad_request)
|
69
|
+
end
|
70
|
+
else
|
71
|
+
render_json({ error: "Must pass in a string of ids that are comma separated" }, :bad_request)
|
72
|
+
end
|
57
73
|
end
|
58
74
|
|
59
|
-
|
60
|
-
|
61
|
-
|
75
|
+
private
|
76
|
+
|
77
|
+
def array_of_integers array
|
78
|
+
array.all? { |e| is_i?(e) }
|
62
79
|
end
|
63
80
|
|
64
|
-
|
81
|
+
def is_i? string
|
82
|
+
!!(string =~ /\A[-+]?[0-9]+\z/)
|
83
|
+
end
|
65
84
|
|
66
85
|
def csv_to_json param_key=:file, separated_by=","
|
67
86
|
lines = params[param_key].split("\n")
|
data/lib/utils/strings.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: railspp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Layne Faler
|
@@ -104,7 +104,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
104
104
|
- !ruby/object:Gem::Version
|
105
105
|
version: '0'
|
106
106
|
requirements: []
|
107
|
-
rubygems_version: 3.0.
|
107
|
+
rubygems_version: 3.0.3
|
108
108
|
signing_key:
|
109
109
|
specification_version: 4
|
110
110
|
summary: Scaffold your CRUD operations
|