bulk_api 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,10 @@
1
+ # WARNING: Still under heavy maintenance ;)
2
+
3
+ I think I should write that this gem is not yet production
4
+ ready and it will probably take some API changes without deprecation
5
+ warnings, so you should probably wait a bit if you want
6
+ to use that.
7
+
1
8
  # Bulk Rails API
2
9
 
3
10
  Bulk Rails API plugin makes integrating Sproutcore applications with Rails applications dead simple. It handles all the communication and allows to take advantage of bulk operations, which can make your application much faster. To use that plugin you will also need BulkDataSource, which will handle Sproutcore side of communcation.
@@ -36,7 +36,7 @@ module Bulk
36
36
  each do |id, record|
37
37
  next if errors.get(id)
38
38
  response[name] ||= []
39
- response[name] << (only_ids ? record.id : record.as_json(options[:as_json]) )
39
+ response[name] << (only_ids ? record.id : record.as_json(options[:as_json_options]) )
40
40
  end
41
41
 
42
42
  errors.each do |id, error|
@@ -7,6 +7,11 @@ module Bulk
7
7
  ActiveRecord::Base.include_root_in_json = false
8
8
  end
9
9
 
10
+ initializer "require sproutcore Rack app" do
11
+ # it needs to be done after rails load, otherwise haml freaks out
12
+ require 'bulk/sproutcore'
13
+ end
14
+
10
15
  config.paths.add "app/bulk", :eager_load => true
11
16
  config.paths.add "app/sproutcore"
12
17
  end
@@ -38,7 +38,7 @@ module Bulk
38
38
  if base.name == application_resource_class.to_s
39
39
  base.abstract!
40
40
  elsif base.name =~ /(.*)Resource$/
41
- base.resource_name($1.underscore.singularize)
41
+ base.resource_name($1.underscore.pluralize)
42
42
  end
43
43
  end
44
44
 
@@ -74,16 +74,16 @@ module Bulk
74
74
  resource_object = instantiate_resource_class(controller, resource)
75
75
  next unless resource_object
76
76
  collection = resource_object.send(method, hash)
77
- as_json = resource_object.send(:as_json, resource_object.send(:klass))
78
- options = {:only_ids => (method == 'delete'), :as_json => as_json}
79
- response.deep_merge! collection.to_hash(resource_object.plural_resource_name.to_sym, options)
77
+ as_json_options = resource_object.send(:as_json_options, resource_object.send(:klass))
78
+ options = {:only_ids => (method == 'delete'), :as_json_options => as_json_options}
79
+ response.deep_merge! collection.to_hash(resource_object.resource_name.to_sym, options)
80
80
  end
81
81
 
82
82
  { :json => response }
83
83
  rescue AuthenticationError
84
- { :status => 401 }
84
+ { :status => 401, :json => {} }
85
85
  rescue AuthorizationError
86
- { :status => 403 }
86
+ { :status => 403, :json => {} }
87
87
  end
88
88
 
89
89
  def instantiate_resource_class(controller, resource)
@@ -167,15 +167,11 @@ module Bulk
167
167
  collection
168
168
  end
169
169
 
170
- def plural_resource_name
171
- resource_name.to_s.pluralize
172
- end
173
-
174
170
  def resource_name
175
171
  @resource_name || self.class.resource_name
176
172
  end
177
173
 
178
- def as_json(klass)
174
+ def as_json_options(klass)
179
175
  {}
180
176
  end
181
177
 
@@ -2,5 +2,4 @@ module Bulk
2
2
  require 'bulk/collection'
3
3
  require 'bulk/resource'
4
4
  require 'bulk/engine'
5
- require 'bulk/sproutcore'
6
5
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: bulk_api
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.2
5
+ version: 0.0.3
6
6
  platform: ruby
7
7
  authors:
8
8
  - Piotr Sarnacki
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-05-08 00:00:00 +02:00
13
+ date: 2011-05-16 00:00:00 +02:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -30,9 +30,9 @@ dependencies:
30
30
  requirement: &id002 !ruby/object:Gem::Requirement
31
31
  none: false
32
32
  requirements:
33
- - - ~>
33
+ - - ">="
34
34
  - !ruby/object:Gem::Version
35
- version: "1.5"
35
+ version: "0"
36
36
  type: :runtime
37
37
  version_requirements: *id002
38
38
  description: Easy integration of rails apps with sproutcore.