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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: aedda840a4c0ca6b0b6f29b9a1036bc9cd7a91fd
4
- data.tar.gz: 1a0a95676c84e29d862bd1bedcb63c5619f1ee31
3
+ metadata.gz: 0da227b279cfdb0f12bb8db8f0ee51a33db74976
4
+ data.tar.gz: 87c7bc8aa16565d322aee622ff38ca4bb4c3c4f7
5
5
  SHA512:
6
- metadata.gz: 9a7247d9402663b8a3fb8f14e14f6f769aea33193089856521d0a1d1617ef66384cfdb83e867ca11ea6d2903bc2cf5041e3c27a6a398655d26643c75a2071a37
7
- data.tar.gz: 1aab9e24a2d373db71bcd804eaa2adae36014d8fad40da2cbabd92776db70a522b39caa312741da042f22d9bed9f4f79a9003231dbac2e884513fb4fbe47e2cf
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 json:@instances}
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 and body.has_key? model.model_name.singular_route_key
105
- params.merge!(body)
106
- elsif body.is_a? Hash
107
- params[model.model_name.singular_route_key] = body
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:/[^\/\.]*/, as: :instances
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:/[^\/\.]*/, as: :new_instance
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
@@ -1,3 +1,3 @@
1
1
  module QuickDry
2
- VERSION = "0.1.0.0" # added json functionality to all relevant standard controller methods
2
+ VERSION = "0.1.1.0" # tweaked to make compatible with a default ember front end with the default RESTAdapter
3
3
  end
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.0.0
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-10 00:00:00.000000000 Z
11
+ date: 2015-02-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails