underscore_extensions 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile
CHANGED
File without changes
|
@@ -3,6 +3,18 @@
|
|
3
3
|
_.mixin(_.str.exports());
|
4
4
|
}
|
5
5
|
|
6
|
+
var objectProto = Object.prototype, hasProperty = objectProto.hasOwnProperty;
|
7
|
+
function has(obj, key) {
|
8
|
+
var result, argLength = arguments.length;
|
9
|
+
if (argLength === 1) {
|
10
|
+
return true;
|
11
|
+
}
|
12
|
+
else if (argLength === 2 && (result = obj && hasProperty.call(obj, key))) {
|
13
|
+
return result;
|
14
|
+
}
|
15
|
+
return (result = obj && hasProperty.call(obj, key)) && has.apply(this, [obj[key]].concat(_(arguments).rest(2)));
|
16
|
+
}
|
17
|
+
|
6
18
|
function namespace(obj, ns) {
|
7
19
|
return _(ns).inject(function(base, n) {
|
8
20
|
var _baseN = _(base[n]);
|
@@ -14,6 +26,14 @@
|
|
14
26
|
}
|
15
27
|
|
16
28
|
_.mixin({
|
29
|
+
has: function(obj, key) {
|
30
|
+
var isArray = _(key).isArray();
|
31
|
+
if (arguments.length === 2 && !isArray) {
|
32
|
+
return hasProperty.call(obj, key);
|
33
|
+
} else {
|
34
|
+
return has.apply(this, isArray && [obj].concat(key) || arguments);
|
35
|
+
}
|
36
|
+
},
|
17
37
|
namespace: function(obj, ns) {
|
18
38
|
if (arguments.length === 2) {
|
19
39
|
if (_(ns).isArray()) {
|
@@ -52,6 +52,22 @@ describe('_', function() {
|
|
52
52
|
});
|
53
53
|
});
|
54
54
|
|
55
|
+
describe('#has', function() {
|
56
|
+
it('should check each property on the object', function() {
|
57
|
+
var obj = {foo: {bar: {baz: true}}};
|
58
|
+
expect(_(obj).has('foo', 'fizz')).toBe(false);
|
59
|
+
expect(_(obj).has('foo', 'bar', 'baz')).toBe(true);
|
60
|
+
expect(_(obj).has('foo', 'bar', 'baz', 'buzz')).toBe(false);
|
61
|
+
});
|
62
|
+
|
63
|
+
it('should check array arguments on the object', function() {
|
64
|
+
var obj = {foo: {bar: {baz: true}}};
|
65
|
+
expect(_(obj).has(['foo', 'fizz'])).toBe(false);
|
66
|
+
expect(_(obj).has(['foo', 'bar', 'baz'])).toBe(true);
|
67
|
+
expect(_(obj).has(['foo', 'bar', 'baz', 'buzz'])).toBe(false);
|
68
|
+
});
|
69
|
+
});
|
70
|
+
|
55
71
|
describe('#pluralize', function() {
|
56
72
|
it("should pluralize a model name", function() {
|
57
73
|
expect(_('point').pluralize()).toEqual('points');
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: underscore_extensions
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.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: 2013-01-
|
12
|
+
date: 2013-01-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: fuubar
|
@@ -106,7 +106,7 @@ files:
|
|
106
106
|
- Gemfile
|
107
107
|
- README.markdown
|
108
108
|
- Rakefile
|
109
|
-
- config/
|
109
|
+
- config/jslint.yml
|
110
110
|
- lib/assets/javascripts/underscore.extensions.js
|
111
111
|
- lib/underscore_extensions.rb
|
112
112
|
- lib/underscore_extensions/version.rb
|
@@ -131,7 +131,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
131
131
|
version: '0'
|
132
132
|
segments:
|
133
133
|
- 0
|
134
|
-
hash:
|
134
|
+
hash: -1223180764248458327
|
135
135
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
136
136
|
none: false
|
137
137
|
requirements:
|
@@ -140,7 +140,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
140
140
|
version: '0'
|
141
141
|
segments:
|
142
142
|
- 0
|
143
|
-
hash:
|
143
|
+
hash: -1223180764248458327
|
144
144
|
requirements: []
|
145
145
|
rubyforge_project: underscore_extensions
|
146
146
|
rubygems_version: 1.8.24
|