backbone_extensions 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -11,7 +11,7 @@ Installing
11
11
  1. Add the gem to bundler or install: gem 'backbone_extensions' or `gem install backbone_extensions`
12
12
  2. In your application.js //= require underscore
13
13
  3. In your application.js //= require backbone
14
- 4. In your application.js //= require underscore_extensions/include
15
- 5. In your application.js //= require underscore_extensions/decorator
14
+ 4. In your application.js //= require backbone_extensions/include
15
+ 5. In your application.js //= require backbone_extensions/decorator
16
16
 
17
17
  Copyright (c) 2012 Ryan Dy, released under the MIT license
@@ -1,27 +1,7 @@
1
1
  (function(Backbone, $) {
2
2
  function Decorator(models, options) {
3
- var self = this,
4
- decoratee = models, proto = _(Object.getPrototypeOf(this)).omit('collection', 'constructor', 'initialize', 'model');
5
- if (models instanceof Backbone.Collection) {
6
- decoratee = decoratee.models;
7
- }
8
- if (decoratee instanceof Array) {
9
- _(proto).each(function(fn, name) {
10
- self[name] = function() {
11
- var args = arguments;
12
- return _(decoratee).map(function(model) {
13
- return fn.apply(model, args);
14
- });
15
- };
16
- });
17
- } else {
18
- _(proto).each(function(fn, name) {
19
- self[name] = function() {
20
- return fn.apply(decoratee, arguments);
21
- };
22
- });
23
- }
24
- self.initialize.apply(self, arguments);
3
+ this._decorateModels.apply(this, arguments);
4
+ this.initialize.apply(this, arguments);
25
5
  }
26
6
 
27
7
  _(Decorator).extend({
@@ -43,7 +23,37 @@
43
23
  }
44
24
  }, Backbone.include ? Backbone.include : {});
45
25
 
46
- _(Decorator.prototype).extend({initialize: $.noop});
26
+ _(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
+ initialize: $.noop
56
+ });
47
57
 
48
58
  Backbone.Decorator = Decorator;
49
59
  })(Backbone, jQuery);
@@ -1,3 +1,3 @@
1
1
  module BackboneExtensions
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
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.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-28 00:00:00.000000000 Z
12
+ date: 2012-11-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: fuubar
@@ -122,7 +122,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
122
122
  version: '0'
123
123
  segments:
124
124
  - 0
125
- hash: -3383809449744806495
125
+ hash: 617698378639900851
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: -3383809449744806495
134
+ hash: 617698378639900851
135
135
  requirements: []
136
136
  rubyforge_project:
137
137
  rubygems_version: 1.8.19