backbone_extensions 0.0.13 → 0.0.14

Sign up to get free protection for your applications and to get access to all the features.
@@ -25,18 +25,18 @@
25
25
  }
26
26
 
27
27
  function createAssociation() {
28
- var collectionName = _.str.classify(associationName), className = options.className && _.str.classify(options.className),
28
+ var self = this, collectionName = _.str.classify(associationName), className = options.className && _.str.classify(options.className),
29
29
  newOptions = mergeAssociationOptions(options, this._options);
30
30
 
31
31
  if (options.inverseOf) {
32
- newOptions[_.str.camelize(options.inverseOf)] = _(function() { return this; }).bind(this);
32
+ newOptions[_.str.camelize(options.inverseOf)] = function() { return self; };
33
33
  }
34
34
 
35
35
  return _((options['class'] && new options['class'](null, newOptions)) ||
36
36
  (className && namespace[className] && new namespace[className](null, newOptions)) ||
37
- (namespace[collectionName] && new namespace[collectionName](null, newOptions))).tap(_(function(association) {
38
- through.call(this, association);
39
- }).bind(this));
37
+ (namespace[collectionName] && new namespace[collectionName](null, newOptions))).tap(function(association) {
38
+ through.call(self, association);
39
+ });
40
40
  }
41
41
 
42
42
  var associations = {
@@ -79,29 +79,30 @@
79
79
 
80
80
  if (associations[associationType]) {
81
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
- };
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
89
 
90
90
  if (!this._parsers) {
91
91
  var parsers = this._parsers = [];
92
92
  this.prototype.parse = _(this.prototype.parse).wrap(function(oldParse, response) {
93
- return _(oldParse.call(this, response)).tap(_(function(parsedResponse) {
93
+ var self = this;
94
+ return _(oldParse.call(self, response)).tap(function(parsedResponse) {
94
95
  _(parsers)
95
96
  .chain()
96
97
  .map(function(parser) {
97
- return _(parser.parseFn.call(this, parsedResponse)).tap(_(function(result) {
98
- parser.associationFn.call(this, result.response);
99
- }).bind(this)).key;
100
- }, this)
98
+ return _(parser.parseFn.call(self, parsedResponse)).tap(function(result) {
99
+ parser.associationFn.call(self, result.response);
100
+ }).key;
101
+ })
101
102
  .each(function(key) {
102
103
  return key && delete parsedResponse[key];
103
104
  });
104
- }).bind(this));
105
+ });
105
106
  });
106
107
  }
107
108
 
@@ -121,32 +122,33 @@
121
122
  var associations = _({
122
123
  belongsTo: {}, hasMany: {parse: true}, hasOne: {parse: true}
123
124
  }).reduce(function(associations, defaultOptions, associationType) {
124
- associations[associationType] = function(name, options) {
125
- var associationName = _.str.camelize(name);
126
- options = _({}).extend(defaultOptions, options);
127
- buildAssociation.call(this, associationType, associationName, options);
128
- parseAssociation.call(this, associationType, associationName, options);
129
- return this;
130
- };
131
- return associations;
132
- }, {});
125
+ associations[associationType] = function(name, options) {
126
+ var associationName = _.str.camelize(name);
127
+ options = _({}).extend(defaultOptions, options);
128
+ buildAssociation.call(this, associationType, associationName, options);
129
+ parseAssociation.call(this, associationType, associationName, options);
130
+ return this;
131
+ };
132
+ return associations;
133
+ }, {});
133
134
 
134
135
  _(source).extend(associations, {
135
136
  associations: function() {
137
+ var self = this;
136
138
  _(arguments).chain().toArray().compact().each(function(options) {
137
139
  _(associations).chain().keys().each(function(associationType) {
138
140
  if (options[associationType]) {
139
- associations[associationType].call(source, options[associationType], _(options).omit(associationType));
141
+ associations[associationType].call(self, options[associationType], _(options).omit(associationType));
140
142
  }
141
143
  });
142
144
  });
143
145
  },
144
146
 
145
147
  extend: _(source.extend).wrap(function(oldExtend, protoProps, classProps) {
146
- return _(oldExtend.call(this, protoProps, classProps)).tap(function() {
148
+ return _(oldExtend.call(this, protoProps, classProps)).tap(function(Klass) {
147
149
  var args = (protoProps || {}).associations;
148
150
  if (args) {
149
- source.associations.apply(source, _([args]).flatten());
151
+ Klass.associations.apply(Klass, _([args]).flatten());
150
152
  }
151
153
  });
152
154
  })
@@ -1,3 +1,3 @@
1
1
  module BackboneExtensions
2
- VERSION = '0.0.13'
2
+ VERSION = '0.0.14'
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.13
4
+ version: 0.0.14
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -126,7 +126,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
126
126
  version: '0'
127
127
  segments:
128
128
  - 0
129
- hash: 1033708220958971973
129
+ hash: 2812514914481620134
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: 1033708220958971973
138
+ hash: 2812514914481620134
139
139
  requirements: []
140
140
  rubyforge_project:
141
- rubygems_version: 1.8.24
141
+ rubygems_version: 1.8.21
142
142
  signing_key:
143
143
  specification_version: 3
144
144
  summary: Extensions to backbone javascript library as a rails engine