backbone_extensions 0.0.3 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,12 +1,40 @@
1
1
  (function(Backbone, $) {
2
+ function decorateModels(self, models) {
3
+ var decoratee = models instanceof Backbone.Collection ? models.models : models,
4
+ proto = _(self)
5
+ .chain()
6
+ .functions()
7
+ .without('collection', 'constructor', 'initialize', 'model')
8
+ .inject(function(result, method) { result[method] = self[method]; return result; }, {})
9
+ .value();
10
+
11
+ if (decoratee instanceof Array) {
12
+ _(proto).each(function(fn, name) {
13
+ self[name] = function() {
14
+ var args = arguments;
15
+ return _(decoratee).map(function(model) {
16
+ return fn.apply(model, args);
17
+ });
18
+ };
19
+ });
20
+ } else {
21
+ _(proto).each(function(fn, name) {
22
+ self[name] = function() {
23
+ return fn.apply(decoratee, arguments);
24
+ };
25
+ });
26
+ }
27
+ }
28
+
2
29
  function Decorator(models, options) {
3
- this._decorateModels.apply(this, arguments);
30
+ decorateModels(this, models);
4
31
  this.initialize.apply(this, arguments);
5
32
  }
6
33
 
7
34
  _(Decorator).extend({
8
35
  extend: function(protoProps, classProps) {
9
36
  var Klass = Backbone.Model.extend.apply(this, arguments);
37
+
10
38
  if (protoProps.model) {
11
39
  protoProps.model.prototype.decorator = function() {
12
40
  return new Klass(this);
@@ -24,34 +52,6 @@
24
52
  }, Backbone.include ? Backbone.include : {});
25
53
 
26
54
  _(Decorator.prototype).extend({
27
- _decorateModels: function(models, options) {
28
- var self = this,
29
- decoratee = models,
30
- proto = _(this)
31
- .chain()
32
- .functions()
33
- .inject(function(result, method) { result[method] = self[method]; return result; }, {})
34
- .omit('collection', 'constructor', 'initialize', 'model', '_decorateModels').value();
35
- if (models instanceof Backbone.Collection) {
36
- decoratee = decoratee.models;
37
- }
38
- if (decoratee instanceof Array) {
39
- _(proto).each(function(fn, name) {
40
- self[name] = function() {
41
- var args = arguments;
42
- return _(decoratee).map(function(model) {
43
- return fn.apply(model, args);
44
- });
45
- };
46
- });
47
- } else {
48
- _(proto).each(function(fn, name) {
49
- self[name] = function() {
50
- return fn.apply(decoratee, arguments);
51
- };
52
- });
53
- }
54
- },
55
55
  initialize: $.noop
56
56
  });
57
57
 
@@ -1,3 +1,3 @@
1
1
  module BackboneExtensions
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.5"
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.3
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -122,7 +122,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
122
122
  version: '0'
123
123
  segments:
124
124
  - 0
125
- hash: 617698378639900851
125
+ hash: -446599863856035963
126
126
  required_rubygems_version: !ruby/object:Gem::Requirement
127
127
  none: false
128
128
  requirements:
@@ -131,7 +131,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
131
131
  version: '0'
132
132
  segments:
133
133
  - 0
134
- hash: 617698378639900851
134
+ hash: -446599863856035963
135
135
  requirements: []
136
136
  rubyforge_project:
137
137
  rubygems_version: 1.8.19