rack-autocrud 0.1.16 → 0.1.17

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/README.md +12 -13
  2. data/lib/rack/autocrud.rb +13 -13
  3. metadata +2 -2
data/README.md CHANGED
@@ -125,23 +125,22 @@ CRUD Processing Hooks
125
125
 
126
126
  There are some basic processing hooks you can define in your endpoint:
127
127
 
128
- | Hook | Description |
129
- | --------------------------------------- | ---------------------------------------------------------------- |
130
- | pre_create(env,request,params) | Called before the record is created |
131
- | post_create(env,request,obj) | Called after the record is saved, if it was saved successfully |
132
- | pre_retrieve(env,request,params) | Called before the record is fetched |
133
- | post_retrieve(env,request,obj) | Called after the record is fetched |
134
- | pre_update(env,request,params) | Called before the record is updated |
135
- | post_update(env,request,params) | Called after the record is updated, if it was saved successfully |
136
- | pre_destroy(env,request,params) | Called before the record is destroyed |
137
- | post_destroy(env,request,obj) | Called after the record is destroyed |
138
- | pre_collect(env,request,params) | Called before the record is collected |
139
- | post_collect(env,request,collection) | Called after the record is collected |
128
+ | Hook | Description |
129
+ | ----------------------------------- | ---------------------------------------------------------------- |
130
+ | pre_create(request,params) | Called before the record is created |
131
+ | post_create(request,obj) | Called after the record is saved, if it was saved successfully |
132
+ | pre_retrieve(request,params) | Called before the record is fetched |
133
+ | post_retrieve(request,obj) | Called after the record is fetched |
134
+ | pre_update(request,params) | Called before the record is updated |
135
+ | post_update(request,params) | Called after the record is updated, if it was saved successfully |
136
+ | pre_destroy(request,params) | Called before the record is destroyed |
137
+ | post_destroy(request,obj) | Called after the record is destroyed |
138
+ | pre_collect(request,params) | Called before the record is collected |
139
+ | post_collect(request,collection) | Called after the record is collected |
140
140
 
141
141
 
142
142
  Parameters:
143
143
 
144
- * *env* is the current Rack environment
145
144
  * *request* is the current request object
146
145
  * *obj* is the ORM object corresponding to the record in question
147
146
  * *collection* is the collection returned by the ORM
data/lib/rack/autocrud.rb CHANGED
@@ -84,7 +84,7 @@ module Rack
84
84
  @sinatra_opts.each { |sopt,val| endpoint_klass.send(:set,sopt,val) }
85
85
 
86
86
  # Patch in the routes
87
- endpoint_klass.class_exec(model_klass,endpoint,env) { |model,endpoint,env|
87
+ endpoint_klass.class_exec(model_klass,endpoint) { |model,endpoint|
88
88
  def set_request_body(new_body,content_type='text/json')
89
89
  env['rack.input'] = StringIO.new(new_body)
90
90
  env['CONTENT_LENGTH'] = new_body.length
@@ -97,7 +97,7 @@ module Rack
97
97
 
98
98
  # Call the pre-create hook
99
99
  if self.respond_to?(:pre_collect)
100
- ret = pre_collect(env,request,params)
100
+ ret = pre_collect(request,params)
101
101
  return ret unless ret.nil?
102
102
  end
103
103
 
@@ -106,17 +106,17 @@ module Rack
106
106
 
107
107
  # Call the post-collect hook
108
108
  if self.respond_to?(:post_collect)
109
- ret = post_collect(env,request,collection)
109
+ ret = post_collect(request,collection)
110
110
  return ret unless ret.nil?
111
111
  end
112
112
 
113
- collection.to_json
113
+ collection.to_json({},request.env)
114
114
  end
115
115
 
116
116
  post '/' do
117
117
  # Call the pre-create hook
118
118
  if self.respond_to?(:pre_create)
119
- ret = pre_create(env,request,params)
119
+ ret = pre_create(request,params)
120
120
  return ret unless ret.nil?
121
121
  end
122
122
 
@@ -134,7 +134,7 @@ module Rack
134
134
 
135
135
  # Call the post-create hook
136
136
  if self.respond_to?(:post_create)
137
- ret = post_create(env,request,obj)
137
+ ret = post_create(request,obj)
138
138
  return ret unless ret.nil?
139
139
  end
140
140
 
@@ -144,7 +144,7 @@ module Rack
144
144
  get '/:id' do
145
145
  # Call the pre-retrieve hook
146
146
  if self.respond_to?(:pre_retrieve)
147
- ret = pre_retrieve(env,request,params)
147
+ ret = pre_retrieve(request,params)
148
148
  return ret unless ret.nil?
149
149
  end
150
150
 
@@ -152,17 +152,17 @@ module Rack
152
152
 
153
153
  # Call the post-retrieve hook
154
154
  if self.respond_to?(:post_retrieve)
155
- ret = post_retrieve(env,request,obj)
155
+ ret = post_retrieve(request,obj)
156
156
  return ret unless ret.nil?
157
157
  end
158
158
 
159
- obj.to_json
159
+ obj.to_json({},request.env)
160
160
  end
161
161
 
162
162
  put '/:id' do
163
163
  # Call the pre-update hook
164
164
  if self.respond_to?(:pre_update)
165
- ret = pre_update(env,request,params)
165
+ ret = pre_update(request,params)
166
166
  return ret unless ret.nil?
167
167
  end
168
168
 
@@ -179,7 +179,7 @@ module Rack
179
179
 
180
180
  # Call the post-update hook
181
181
  if self.respond_to?(:post_update)
182
- ret = post_update(env,request,params)
182
+ ret = post_update(request,params)
183
183
  return ret unless ret.nil?
184
184
  end
185
185
 
@@ -189,7 +189,7 @@ module Rack
189
189
  delete '/:id' do
190
190
  # Call the pre-destroy hook
191
191
  if self.respond_to?(:pre_destroy)
192
- ret = pre_destroy(env,request,params)
192
+ ret = pre_destroy(request,params)
193
193
  return ret unless ret.nil?
194
194
  end
195
195
 
@@ -198,7 +198,7 @@ module Rack
198
198
 
199
199
  # Call the post-destroy hook
200
200
  if self.respond_to?(:post_destroy)
201
- ret = post_destroy(env,request,obj)
201
+ ret = post_destroy(request,obj)
202
202
  return ret unless ret.nil?
203
203
  end
204
204
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-autocrud
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.16
4
+ version: 0.1.17
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-24 00:00:00.000000000 Z
12
+ date: 2013-01-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json