quick_dry 0.1.0.0 → 0.1.1.0
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/quick_dry/quick_dry_controller.rb +44 -5
- data/config/routes.rb +4 -4
- data/lib/quick_dry/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0da227b279cfdb0f12bb8db8f0ee51a33db74976
|
4
|
+
data.tar.gz: 87c7bc8aa16565d322aee622ff38ca4bb4c3c4f7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6705761ea31331e1daaa70dec72b12d83bbbd0fde9d844046763902fab4ca7ac76120f5748dc932f3dfb8fa0fa01316d20aff19e2a5b192aa5fbd0f46f44f018
|
7
|
+
data.tar.gz: 6641adae32252525237c579a17538778aa99fc8b17f7ea9b57c4eb1993f1b059318a11dc579c4be365eb83a43efb9f57287f6afbff01a27df61963aa3a763d2a
|
@@ -5,6 +5,23 @@ module QuickDry
|
|
5
5
|
class QuickDryController < ApplicationController
|
6
6
|
protect_from_forgery #unless Rails.env = "development"
|
7
7
|
before_action :instantiate_paths
|
8
|
+
|
9
|
+
# nasty hack until I can get an answer on the official way to remove the instance root keys in a list
|
10
|
+
def serialize stuff
|
11
|
+
if stuff.is_a? Array or stuff.is_a? ActiveRecord::Relation
|
12
|
+
json = render_to_string json:QuickDryArraySerializer.new(stuff, root:get_model.model_name.route_key )
|
13
|
+
hash = JSON.parse(json)
|
14
|
+
temp = []
|
15
|
+
if hash[get_model.model_name.route_key].first.has_key? get_model.model_name.route_key
|
16
|
+
hash[get_model.model_name.route_key].each{|x| temp << x[get_model.model_name.route_key]}
|
17
|
+
hash[get_model.model_name.route_key] = temp
|
18
|
+
return hash.to_json
|
19
|
+
end
|
20
|
+
return json
|
21
|
+
elsif stuff.is_a? get_model
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
8
25
|
|
9
26
|
# GET /table_name
|
10
27
|
# GET /table_name.json
|
@@ -14,7 +31,8 @@ module QuickDry
|
|
14
31
|
@instances = get_model.all
|
15
32
|
# render 'quick_dry/index'
|
16
33
|
respond_to do |format|
|
17
|
-
format.json { render
|
34
|
+
# format.json { render body:@instances.to_json, content_type:'application/json'} # using the json parameter nests objects inside of quick_dry keys
|
35
|
+
format.json { render json:serialize(@instances)}#, each_serializer: QuickDrySerializer}# serializer:QuickDryArraySerializer}
|
18
36
|
format.html { render 'quick_dry/index'}
|
19
37
|
end
|
20
38
|
end
|
@@ -101,10 +119,22 @@ module QuickDry
|
|
101
119
|
format.html { }
|
102
120
|
format.json do
|
103
121
|
body = JSON.parse(request.body.read)
|
104
|
-
if body.is_a? Hash
|
105
|
-
|
106
|
-
|
107
|
-
|
122
|
+
if body.is_a? Hash
|
123
|
+
pascal = model.model_name.singular_route_key.camelize
|
124
|
+
camel = model.model_name.singular_route_key.camelize(:lower)
|
125
|
+
snake = model.model_name.singular_route_key
|
126
|
+
# instance_name
|
127
|
+
if body.has_key? snake
|
128
|
+
params.merge!(body)
|
129
|
+
# instanceName
|
130
|
+
elsif body.has_key? camel
|
131
|
+
params.merge!({snake => body[camel]})
|
132
|
+
# InstanceName
|
133
|
+
elsif body.has_key? pascal
|
134
|
+
params.merge!({snake => body[pascal]})
|
135
|
+
else
|
136
|
+
params[model.model_name.singular_route_key] = body
|
137
|
+
end
|
108
138
|
end
|
109
139
|
end
|
110
140
|
end
|
@@ -192,6 +222,15 @@ module QuickDry
|
|
192
222
|
return {instances:instances,params:params}
|
193
223
|
end
|
194
224
|
|
225
|
+
def default_serializer_options
|
226
|
+
{
|
227
|
+
root: get_model.model_name.route_key#,
|
228
|
+
# model_class: get_model
|
229
|
+
}
|
230
|
+
end
|
231
|
+
|
232
|
+
|
233
|
+
|
195
234
|
# # POST /customer_orders
|
196
235
|
# # POST /customer_orders.json
|
197
236
|
# def create
|
data/config/routes.rb
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
QuickDry::Engine.routes.draw do
|
2
2
|
|
3
3
|
# put these at the end of the routes.rb so as not to interfere with default rails routes
|
4
|
-
get '/:table_name(.:format)', to: 'quick_dry#index', table_name:/[^\/\.]*/,
|
4
|
+
get '/:table_name(.:format)', to: 'quick_dry#index', table_name:/[^\/\.]*/, as: :instances
|
5
5
|
post '/:table_name(.:format)', to: 'quick_dry#create', table_name:/[^\/\.]*/
|
6
|
-
get '/:table_name/:id(.:format)', to: 'quick_dry#show', table_name:/[^\/\.]*/, id:/[\d]*/,as: :instance
|
6
|
+
get '/:table_name/:id(.:format)', to: 'quick_dry#show', table_name:/[^\/\.]*/, id:/[\d]*/, as: :instance
|
7
7
|
put '/:table_name/:id(.:format)', to: 'quick_dry#update', table_name:/[^\/\.]*/, id:/[\d]*/
|
8
8
|
patch '/:table_name/:id(.:format)', to: 'quick_dry#update', table_name:/[^\/\.]*/, id:/[\d]*/
|
9
9
|
delete '/:table_name/:id(.:format)', to: 'quick_dry#destroy',table_name:/[^\/\.]*/, id:/[\d]*/
|
10
|
-
get '/:table_name/:id/edit(.:format)', to: 'quick_dry#edit', table_name:/[^\/\.]*/, id:/[\d]*/,as: :edit_instance
|
11
|
-
get '/:table_name/new(.:format)', to: 'quick_dry#new', table_name:/[^\/\.]*/,
|
10
|
+
get '/:table_name/:id/edit(.:format)', to: 'quick_dry#edit', table_name:/[^\/\.]*/, id:/[\d]*/, as: :edit_instance
|
11
|
+
get '/:table_name/new(.:format)', to: 'quick_dry#new', table_name:/[^\/\.]*/, as: :new_instance
|
12
12
|
|
13
13
|
|
14
14
|
end
|
data/lib/quick_dry/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: quick_dry
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nathan Hanna
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-02-
|
11
|
+
date: 2015-02-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|