serviceable 0.6.1 → 0.6.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.
Files changed (2) hide show
  1. data/lib/serviceable.rb +15 -6
  2. metadata +4 -4
@@ -26,6 +26,7 @@ module Serviceable
26
26
 
27
27
  before_filter :assign_new_instance, only: :create
28
28
  before_filter :assign_existing_instance, only: [ :show, :update, :destroy ]
29
+ before_filter :did_assign_instance, only: [ :show, :update ]
29
30
  before_filter :assign_collection, only: [ :index, :count ]
30
31
  before_filter :did_assign_collection, only: [ :index, :count ]
31
32
 
@@ -46,8 +47,8 @@ module Serviceable
46
47
  define_method("create") do
47
48
  respond_to do |format|
48
49
  if @instance.save
49
- format.json { render json: @instance }
50
- format.xml { render xml: @instance }
50
+ format.json { render json: @instance, status: :created }
51
+ format.xml { render xml: @instance, status: :created }
51
52
  else
52
53
  format.json { render json: { errors: @instance.errors.full_messages }, status: :unprocessable_entity }
53
54
  format.xml { render xml: { errors: @instance.errors.full_messages }, status: :unprocessable_entity }
@@ -149,13 +150,17 @@ module Serviceable
149
150
  requested_methods = requested_methods.map(&:to_s).map(&:to_sym)
150
151
  allowed_methods = allowed_methods.map(&:to_s).map(&:to_sym)
151
152
  whitelisted_methods = requested_methods & allowed_methods
153
+ if options && options[:methods]
154
+ mandatory_methods = array_for(options[:methods])
155
+ whitelisted_methods = whitelisted_methods + mandatory_methods
156
+ end
152
157
  merged_options = merged_options.merge({methods: whitelisted_methods}) if whitelisted_methods.any?
153
158
  merged_options = deep_split(merged_options.compact)
154
159
  return merged_options
155
160
  end
156
161
 
157
162
  define_method("assign_existing_instance") do
158
- @instance = object.to_s.camelize.constantize
163
+ @instance = object.to_s.camelize.constantize.scoped
159
164
  if params[:include].kind_of?(Hash)
160
165
  @instance = @instance.includes(params[:include].keys)
161
166
  end
@@ -169,6 +174,10 @@ module Serviceable
169
174
  @instance = object.to_s.camelize.constantize.new(params[object])
170
175
  end
171
176
 
177
+ define_method("did_assign_instance") do
178
+ # do nothing
179
+ end
180
+
172
181
  # query string params can be used to filter collections
173
182
  #
174
183
  # filters apply on associated collections using the following conventions:
@@ -224,11 +233,11 @@ module Serviceable
224
233
 
225
234
  define_method("array_for") do |obj|
226
235
  if obj.kind_of?(Hash)
227
- arr = params[:methods].keys
236
+ arr = obj.keys
228
237
  elsif obj.kind_of?(Array)
229
- arr = params[:methods]
238
+ arr = obj
230
239
  elsif obj.kind_of?(String)
231
- arr = params[:methods].split(',')
240
+ arr = obj.split(',')
232
241
  else
233
242
  arr = Array(obj)
234
243
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: serviceable
3
3
  version: !ruby/object:Gem::Version
4
- hash: 5
4
+ hash: 3
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 6
9
- - 1
10
- version: 0.6.1
9
+ - 2
10
+ version: 0.6.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Aubrey Goodman
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2013-09-05 00:00:00 Z
18
+ date: 2013-10-02 00:00:00 Z
19
19
  dependencies: []
20
20
 
21
21
  description: Decorate your controller classes with acts_as_service :model_name, and instantly support JSON/XML CRUD interface. Allow client to specify response contents using query string filter parameters.