angularjs-rails-resource 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  module Angularjs
2
2
  module Rails
3
3
  module Resource
4
- VERSION = "0.1.5"
4
+ VERSION = "0.1.6"
5
5
  end
6
6
  end
7
7
  end
@@ -115,11 +115,13 @@
115
115
  interceptors = config.responseInterceptors || ['railsFieldRenamingInterceptor', 'railsRootWrappingInterceptor'];
116
116
 
117
117
  function RailsResource(value) {
118
+ value || (value = {});
118
119
  var immediatePromise = function(data) {
119
120
  return {
121
+ resource: RailsResource,
120
122
  response: data,
121
123
  then: function(callback) {
122
- this.response = callback(this.response);
124
+ this.response = callback(this.response, this.resource);
123
125
  return immediatePromise(this.response);
124
126
  }
125
127
  }
@@ -140,6 +142,25 @@
140
142
  RailsResource.responseInterceptors = [];
141
143
  RailsResource.defaultParams = config.defaultParams;
142
144
 
145
+ // Add a function to run on response / initialize data
146
+ // model methods and this are not yet available at this point
147
+ RailsResource.beforeResponse = function(fn) {
148
+ RailsResource.responseInterceptors.push(function(promise) {
149
+ return promise.then(function(response) {
150
+ fn(response.data, promise.resource);
151
+ return response;
152
+ });
153
+ });
154
+ };
155
+
156
+ // Add a function to run on request data
157
+ RailsResource.beforeRequest = function(fn) {
158
+ RailsResource.requestTransformers.push(function(data, resource) {
159
+ fn(data, resource);
160
+ return data;
161
+ });
162
+ };
163
+
143
164
  // copied from $HttpProvider to support interceptors being dependency names or anonymous factory functions
144
165
  angular.forEach(interceptors, function (interceptor) {
145
166
  RailsResource.responseInterceptors.push(
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: angularjs-rails-resource
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-04-24 00:00:00.000000000 Z
13
+ date: 2013-06-01 00:00:00.000000000 Z
14
14
  dependencies: []
15
15
  description: A small AngularJS add-on for integrating with Rails via JSON more easily.
16
16
  email: