railspp 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 65047ba2296e1a10247976a0652895892dbc4cfafbc52ce3eec4e368b3a95275
4
- data.tar.gz: 6bf4edfeed47661342c1b71b3a60e4b5afebd66c839b4593440956fbe9c17cb5
3
+ metadata.gz: d12230e4e45a9cbd1a0205aafff9c972a7f1831aab990a148cecc0c97ce8110d
4
+ data.tar.gz: fe1591b2d6fa3e469e887144bdc8095de02ba55ad7f601b36a65b607c705945d
5
5
  SHA512:
6
- metadata.gz: c65e5067ff212106566bcd1588489e9338f64e555788caf8a9360fce4064d1f9da62f5cbef8871ab1906c10af6821e84ce5260e0e97c1652bc16ceef19346a29
7
- data.tar.gz: 3332b64f99cabbd733085ea13a171c9d5e7735fc9e9f443b53ae06fe7f6a4b9ad852721a2638d878e24d69a1c04c0ca2ba13ecabca2f7fb7dd12399f14e43eba
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 ? 400 : 200
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, 200)
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, 201)
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, 200)
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, 204)
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, 201)
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, 201)
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, 201)
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
- def bulk_destory
60
- model.where(id: bulk_destroy_params[:bulk])
61
- render_json(nil, 204)
75
+ private
76
+
77
+ def array_of_integers array
78
+ array.all? { |e| is_i?(e) }
62
79
  end
63
80
 
64
- private
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
@@ -21,7 +21,7 @@ class MoreUtils
21
21
  class << self
22
22
 
23
23
  def gem_version
24
- "0.3.1"
24
+ "0.3.2"
25
25
  end
26
26
 
27
27
  def get_file_str path
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.1
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.2
107
+ rubygems_version: 3.0.3
108
108
  signing_key:
109
109
  specification_version: 4
110
110
  summary: Scaffold your CRUD operations