backbone_extensions 0.0.15 → 0.0.16

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.
@@ -78,24 +78,15 @@
78
78
  };
79
79
 
80
80
  if (associations[associationType]) {
81
- var parseFunc = _(options.parse).isFunction() &&
82
- function(response) { return {response: options.parse.call(this, response) }; } ||
83
- function(response) {
84
- return (options.through && through.call(this, response)) ||
85
- (options.parseName && parseResponseWith(options.parseName, response)) ||
86
- (options.className && parseResponseWith(options.className, response)) ||
87
- parseResponseWith(associationName, response);
88
- };
89
-
90
- if (!this._parsers) {
91
- var parsers = this._parsers = [];
81
+ var parsers = this._parsers;
82
+ if (_(parsers).isEmpty()) {
92
83
  this.prototype.parse = _(this.prototype.parse).wrap(function(oldParse, response) {
93
84
  var self = this;
94
85
  return _(oldParse.call(self, response)).tap(function(parsedResponse) {
95
86
  _(parsers)
96
87
  .chain()
97
88
  .map(function(parser) {
98
- return _(parser.parseFn.call(self, parsedResponse)).tap(function(result) {
89
+ return _(parser.parseFn.call(self).call(self, parsedResponse)).tap(function(result) {
99
90
  parser.associationFn.call(self, result.response);
100
91
  }).key;
101
92
  })
@@ -107,7 +98,16 @@
107
98
  }
108
99
 
109
100
  this._parsers.push({
110
- parseFn: parseFunc,
101
+ parseFn: function() {
102
+ return _(options.parse).isFunction() &&
103
+ function(response) { return {response: options.parse.call(this, response) }; } ||
104
+ function(response) {
105
+ return (options.through && through.call(this, response)) ||
106
+ (options.parseName && parseResponseWith(options.parseName, response)) ||
107
+ (options.className && parseResponseWith(options.className, response)) ||
108
+ parseResponseWith(associationName, response);
109
+ };
110
+ },
111
111
  associationFn: function(assocResponse) {
112
112
  associations[associationType].call(this, assocResponse, this[associationName](), mergeAssociationOptions(options, this._options));
113
113
  }
@@ -124,6 +124,9 @@
124
124
  associations[associationType] = function(name, options) {
125
125
  var associationName = _.str.camelize(name);
126
126
  options = _({}).extend(defaultOptions, options);
127
+ if (options.parse && !_(this).has('_parsers')) {
128
+ this._parsers = [];
129
+ }
127
130
  buildAssociation.call(this, associationType, associationName, options);
128
131
  parseAssociation.call(this, associationType, associationName, options);
129
132
  return this;
@@ -1,3 +1,3 @@
1
1
  module BackboneExtensions
2
- VERSION = '0.0.15'
2
+ VERSION = '0.0.16'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: backbone_extensions
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.15
4
+ version: 0.0.16
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-01-16 00:00:00.000000000 Z
13
+ date: 2013-01-17 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: fuubar
@@ -126,7 +126,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
126
126
  version: '0'
127
127
  segments:
128
128
  - 0
129
- hash: -3341261840175240858
129
+ hash: -3935989382484356862
130
130
  required_rubygems_version: !ruby/object:Gem::Requirement
131
131
  none: false
132
132
  requirements:
@@ -135,10 +135,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
135
135
  version: '0'
136
136
  segments:
137
137
  - 0
138
- hash: -3341261840175240858
138
+ hash: -3935989382484356862
139
139
  requirements: []
140
140
  rubyforge_project:
141
- rubygems_version: 1.8.21
141
+ rubygems_version: 1.8.24
142
142
  signing_key:
143
143
  specification_version: 3
144
144
  summary: Extensions to backbone javascript library as a rails engine