yellow-brick-road 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rst +42 -20
- data/lib/generators/templates/yellow_brick_road.rb.erb +19 -0
- data/lib/generators/yellow_brick_road/install_generator.rb +14 -0
- data/lib/yellow-brick-road/config.rb +41 -8
- data/lib/yellow-brick-road/directive_processor.rb +6 -5
- data/lib/yellow-brick-road/engine.rb +2 -3
- data/lib/yellow-brick-road/soy_processor.rb +1 -1
- data/lib/yellow-brick-road/version.rb +1 -1
- data/test/dummy/app/assets/javascripts/closure-deps.js +1 -1
- data/test/dummy/config/initializers/yellow_brick_road.rb +18 -1
- data/test/dummy/log/development.log +2208 -0
- data/test/dummy/tmp/cache/assets/C33/E00/sprockets%2F50c54266987e056bca666f8951752841 +2556 -0
- data/test/dummy/tmp/cache/assets/C48/990/sprockets%2F182c7921a46c3b8603c7f5595a111407 +823 -0
- data/test/dummy/tmp/cache/assets/C53/B40/sprockets%2F48cf0c035092dc945559526a279061c6 +204 -0
- data/test/dummy/tmp/cache/assets/C60/DB0/sprockets%2F3f00684578f2a3246581db667309ed89 +187 -0
- data/test/dummy/tmp/cache/assets/C60/E40/sprockets%2F3c5422f721521f492a5f02ca00b70009 +457 -0
- data/test/dummy/tmp/cache/assets/C73/DE0/sprockets%2F21f1f4574326846114a3c106873cebc3 +0 -0
- data/test/dummy/tmp/cache/assets/C7E/9F0/sprockets%2F89862076204c62c4593ac20de32da909 +4 -4
- data/test/dummy/tmp/cache/assets/C80/6F0/sprockets%2F56459a0713f8610d7d261f8be93073a2 +115 -0
- data/test/dummy/tmp/cache/assets/C8D/E10/sprockets%2F34b84bc4732937f885707002eda3896e +511 -0
- data/test/dummy/tmp/cache/assets/C93/CB0/sprockets%2F539b403b24833ca478a6f5877f37687c +239 -0
- data/test/dummy/tmp/cache/assets/C9A/C70/sprockets%2F10933dc6d342f604514713510b9ef0ab +806 -0
- data/test/dummy/tmp/cache/assets/CA0/7C0/sprockets%2Ff591bc0af8f085501241305c04907d3e +590 -0
- data/test/dummy/tmp/cache/assets/CA1/4A0/sprockets%2F5a9ad311e7d225b530b597041714b1e9 +2539 -0
- data/test/dummy/tmp/cache/assets/CA7/310/sprockets%2F45664cf816315200b574e029fde6f10a +0 -0
- data/test/dummy/tmp/cache/assets/CA7/A80/sprockets%2F1f32590957635a5a4f35442bc22f4ca4 +0 -0
- data/test/dummy/tmp/cache/assets/CAE/1D0/sprockets%2F2e62c7733d38a817a1532a744c6287bd +72 -0
- data/test/dummy/tmp/cache/assets/CB2/3C0/sprockets%2F9c35c290501a896b82c31448a39f3d5d +142 -0
- data/test/dummy/tmp/cache/assets/CB3/F20/sprockets%2F558b00e493fb501f7d95761e7eb40273 +2539 -0
- data/test/dummy/tmp/cache/assets/CBE/550/sprockets%2Fd680cac830e0b3408ba910f0b0421147 +2 -2
- data/test/dummy/tmp/cache/assets/CCD/480/sprockets%2Ffe7e11511634a2d03e1a20980b4593cf +0 -0
- data/test/dummy/tmp/cache/assets/CD0/080/sprockets%2Ffd5cbb87741244521d013d11c55573fa +204 -0
- data/test/dummy/tmp/cache/assets/CD2/020/sprockets%2Ff97740ba22118a2c91e992aac041843b +811 -0
- data/test/dummy/tmp/cache/assets/CD8/D90/sprockets%2F55dd841661d646f0024261a08ecf8ec0 +823 -0
- data/test/dummy/tmp/cache/assets/CE3/0D0/sprockets%2F301f97a178fd839a81bd663a6e22b616 +811 -0
- data/test/dummy/tmp/cache/assets/CE4/330/sprockets%2Fbd23466639af99164ab8e1c93721f14b +127 -0
- data/test/dummy/tmp/cache/assets/CE6/8A0/sprockets%2F3c0e7c5fa31563c8e820d6771e09918d +103 -0
- data/test/dummy/tmp/cache/assets/CEB/120/sprockets%2F857a0dde6829f7a27b93a840e1c60469 +522 -0
- data/test/dummy/tmp/cache/assets/CEE/CF0/sprockets%2F376f94b987d8156056c4e1d38ec06bf0 +0 -0
- data/test/dummy/tmp/cache/assets/CF2/C10/sprockets%2Fc64ef8a9dd0a1c3101d662750105c11a +806 -0
- data/test/dummy/tmp/cache/assets/CF3/CD0/sprockets%2F4bb42a5a6b504190f10d20b1c5f93d54 +1529 -0
- data/test/dummy/tmp/cache/assets/CF6/890/sprockets%2F36007a87f140155b5a04f2ca6b262dcc +494 -0
- data/test/dummy/tmp/cache/assets/CF6/9D0/sprockets%2F34b7199e9d33994c8ec7a442d60ca985 +173 -0
- data/test/dummy/tmp/cache/assets/CFA/A90/sprockets%2F901ba405a6d6747f6412ed4d0e0ac620 +256 -0
- data/test/dummy/tmp/cache/assets/CFC/E70/sprockets%2F8ee639668b5f0e629fbe0d62d1394689 +173 -0
- data/test/dummy/tmp/cache/assets/D04/1B0/sprockets%2F418f2b3b6b08b320f6db268a0991c54c +0 -0
- data/test/dummy/tmp/cache/assets/D05/920/sprockets%2F909507434dcc270db4853e4c147f0aac +5 -4
- data/test/dummy/tmp/cache/assets/D07/DB0/sprockets%2F0c17d7dac64290e385c91eb6f1570b31 +511 -0
- data/test/dummy/tmp/cache/assets/D07/EE0/sprockets%2F4999982b09e0b786894fce44f5d783cc +1371 -0
- data/test/dummy/tmp/cache/assets/D09/380/sprockets%2F14383e18fa2faac6b561a29d8e132863 +0 -0
- data/test/dummy/tmp/cache/assets/D0D/200/sprockets%2F545a7e34cce1d4272d83d58fd4215d42 +1277 -0
- data/test/dummy/tmp/cache/assets/D0E/870/sprockets%2F84996444f4f1f3fdc0248131cfb1a3b6 +794 -0
- data/test/dummy/tmp/cache/assets/D15/F60/sprockets%2Fa28394e3f80365b5bc86794dd46daa22 +0 -0
- data/test/dummy/tmp/cache/assets/D18/950/sprockets%2Fcf650d67c5d431ffdb38552e562299b2 +474 -0
- data/test/dummy/tmp/cache/assets/D18/E10/sprockets%2Fec7c58f640556b401fcd66528352dc9d +474 -0
- data/test/dummy/tmp/cache/assets/D20/660/sprockets%2F0d2875475ced01df962f3d758cda7792 +103 -0
- data/test/dummy/tmp/cache/assets/D22/AB0/sprockets%2F0b08e7f81651aaf739a93d61ae99779c +283 -0
- data/test/dummy/tmp/cache/assets/D2E/B20/sprockets%2Feed5412a17a52b1a335925e2af1f75d3 +0 -0
- data/test/dummy/tmp/cache/assets/D36/700/sprockets%2Fd219bf9db2eacc105bb294755093a437 +505 -0
- data/test/dummy/tmp/cache/assets/D3B/A10/sprockets%2Fcf38b51682d84a04da7b8a7313de52c6 +207 -0
- data/test/dummy/tmp/cache/assets/D3C/0E0/sprockets%2Fe9d7aba138d602c4a6ac701bc9615977 +505 -0
- data/test/dummy/tmp/cache/assets/D3E/FF0/sprockets%2F6bd8ccd3e02f397c20f349d5c0960e51 +0 -0
- data/test/dummy/tmp/cache/assets/D41/B30/sprockets%2Fba1b93913dd01d83ac9a96df334456f8 +0 -0
- data/test/dummy/tmp/cache/assets/D41/DA0/sprockets%2Fe8d00810698a9fcee032022fefd084f7 +0 -0
- data/test/dummy/tmp/cache/assets/D44/CF0/sprockets%2Ffa31a45f04884493c909c5a67fcbdf23 +1371 -0
- data/test/dummy/tmp/cache/assets/D47/BE0/sprockets%2F0b5ebdf6dec160a264698e7f745061e8 +142 -0
- data/test/dummy/tmp/cache/assets/D4C/F30/sprockets%2Ff90155c10f59a3fe44959ac09bf817fe +2556 -0
- data/test/dummy/tmp/cache/assets/D4E/7C0/sprockets%2Ff01b58512d01eda23fd5cb23a2b28b60 +1529 -0
- data/test/dummy/tmp/cache/assets/D4E/860/sprockets%2F86eed0c77c47d0970345bbabb58d8939 +1277 -0
- data/test/dummy/tmp/cache/assets/D4E/C30/sprockets%2F52420c10c73ca310d026565eafdadb4e +1545 -0
- data/test/dummy/tmp/cache/assets/D4E/F60/sprockets%2F9893a3c5aeb1a9e77469f4751b4d3c3f +115 -0
- data/test/dummy/tmp/cache/assets/D4F/E60/sprockets%2F17ee65de1f78c3dd5c165a9867e810b6 +165 -0
- data/test/dummy/tmp/cache/assets/D57/0D0/sprockets%2Fa29e6e8106d9d5ed1e2889126cfbf877 +300 -0
- data/test/dummy/tmp/cache/assets/D5C/650/sprockets%2Fe1c381da3cc213a639e956ae3315a2bd +607 -0
- data/test/dummy/tmp/cache/assets/D61/860/sprockets%2Fbf032a3b4aad2c2e25704e65c966cf45 +794 -0
- data/test/dummy/tmp/cache/assets/D63/B20/sprockets%2F31fc70ce66bb80fb9421be34eb3b0287 +0 -0
- data/test/dummy/tmp/cache/assets/D64/D60/sprockets%2Fa544ea03bf0a45948a053ba76ec2a79f +239 -0
- data/test/dummy/tmp/cache/assets/D6B/F90/sprockets%2F66636712ecb1fcc777dccf7643a0e1b1 +127 -0
- data/test/dummy/tmp/cache/assets/D6E/AD0/sprockets%2Fc91cdc6a72c729d7a64119198b3d2eab +0 -0
- data/test/dummy/tmp/cache/assets/D6F/140/sprockets%2F9ddc51f4388dd5243a28dba1ce47572b +53 -0
- data/test/dummy/tmp/cache/assets/D72/800/sprockets%2F92baa375d54e16fe0a5c7f079a1ce992 +165 -0
- data/test/dummy/tmp/cache/assets/D74/220/sprockets%2F3f888bda53179cb945eab35fbd31a708 +53 -0
- data/test/dummy/tmp/cache/assets/D78/5F0/sprockets%2F638ed6af667d4fc5147f72ff34aa2d33 +0 -0
- data/test/dummy/tmp/cache/assets/D7D/640/sprockets%2F95a7c5580f957c31e1ab9d0773ed5fde +607 -0
- data/test/dummy/tmp/cache/assets/D84/210/sprockets%2Fabd0103ccec2b428ac62c94e4c40b384 +6 -5
- data/test/dummy/tmp/cache/assets/D89/020/sprockets%2Fa06df6166e70324e712e54b1cafca0ae +187 -0
- data/test/dummy/tmp/cache/assets/D8A/9F0/sprockets%2Fc06547ca33ee3d03be14ce045ae1c9e2 +207 -0
- data/test/dummy/tmp/cache/assets/D9E/B80/sprockets%2F9561df1d45c7ff4aa8ac3e2df0c99121 +0 -0
- data/test/dummy/tmp/cache/assets/DA3/F30/sprockets%2Fe015d6ccdfcf022e47c83d7906f728ae +457 -0
- data/test/dummy/tmp/cache/assets/DAE/190/sprockets%2F433c7b21968be8d1f9bfdbdf7a637c57 +0 -0
- data/test/dummy/tmp/cache/assets/DB3/600/sprockets%2F9b70ae73f15ba693886eeef4eb5d6c75 +0 -0
- data/test/dummy/tmp/cache/assets/DB4/510/sprockets%2F29cdae8e29c88fd9ddbd4831419560fe +1260 -0
- data/test/dummy/tmp/cache/assets/DC1/4A0/sprockets%2F0b63dfcf163f2faeb612724eb4545bcc +1354 -0
- data/test/dummy/tmp/cache/assets/DC4/C10/sprockets%2Fcf48f4cbad3db33146eab4c577c1d209 +300 -0
- data/test/dummy/tmp/cache/assets/DC4/CA0/sprockets%2Fd0da8a60ea4dc16b9fd3e2a50d88633c +0 -0
- data/test/dummy/tmp/cache/assets/DC7/8C0/sprockets%2F1ad68dcc9ef598d3811ba2ac5c0ea182 +1354 -0
- data/test/dummy/tmp/cache/assets/DC7/C00/sprockets%2Fba755ff3a81c3192f0e45a4f7c0c7dcb +0 -0
- data/test/dummy/tmp/cache/assets/DCA/760/sprockets%2F717c4cea10bf601090ffdfe4e668e4cb +283 -0
- data/test/dummy/tmp/cache/assets/DCA/DE0/sprockets%2F51dcced9ec2b3cd4b1cc2949f860c361 +590 -0
- data/test/dummy/tmp/cache/assets/DD7/E70/sprockets%2F2595d8c8d1d5f4deb096247fb3bfc7ab +256 -0
- data/test/dummy/tmp/cache/assets/DE1/9D0/sprockets%2F8befd77af580ee16ec42ec95b1766ff3 +1545 -0
- data/test/dummy/tmp/cache/assets/E00/D80/sprockets%2F9debc27161f7bccf2d84a36b8c36c4bf +522 -0
- data/test/dummy/tmp/cache/assets/E00/E60/sprockets%2Fac159b94b0a6d621e4f6cde9b4de87bb +0 -0
- data/test/dummy/tmp/cache/assets/E04/890/sprockets%2F2f5173deea6c795b8fdde723bb4b63af +0 -0
- data/test/dummy/tmp/cache/assets/E1B/D00/sprockets%2F886dff4afe55f9d3f8abe434f2689add +72 -0
- data/test/dummy/tmp/cache/assets/E1B/F20/sprockets%2Fa4bbc04eb83ebf94fd8134c3abd220dd +494 -0
- data/test/dummy/tmp/cache/assets/E71/0C0/sprockets%2F5ffdc0daa0a1f9638c787897ceefcdee +1260 -0
- metadata +186 -10
- data/test/dummy/tmp/pids/server.pid +0 -1
Binary file
|
@@ -0,0 +1,283 @@
|
|
1
|
+
o: ActiveSupport::Cache::Entry :@compressedF:@expires_in0:@created_atf1325538161.8997781:@value{ I"length:EFiA)I"digest;
|
2
|
+
F"%226247a455556e9cf216d2450ff3dca9I"source;
|
3
|
+
FI"A)// Copyright 2008 The Closure Library Authors. All Rights Reserved.
|
4
|
+
//
|
5
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
// you may not use this file except in compliance with the License.
|
7
|
+
// You may obtain a copy of the License at
|
8
|
+
//
|
9
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
//
|
11
|
+
// Unless required by applicable law or agreed to in writing, software
|
12
|
+
// distributed under the License is distributed on an "AS-IS" BASIS,
|
13
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
// See the License for the specific language governing permissions and
|
15
|
+
// limitations under the License.
|
16
|
+
|
17
|
+
/**
|
18
|
+
* @fileoverview Utilities to check the preconditions, postconditions and
|
19
|
+
* invariants runtime.
|
20
|
+
*
|
21
|
+
* Methods in this package should be given special treatment by the compiler
|
22
|
+
* for type-inference. For example, <code>goog.asserts.assert(foo)</code>
|
23
|
+
* will restrict <code>foo</code> to a truthy value.
|
24
|
+
*
|
25
|
+
* The compiler has an option to disable asserts. So code like:
|
26
|
+
* <code>
|
27
|
+
* var x = goog.asserts.assert(foo()); goog.asserts.assert(bar());
|
28
|
+
* </code>
|
29
|
+
* will be transformed into:
|
30
|
+
* <code>
|
31
|
+
* var x = foo();
|
32
|
+
* </code>
|
33
|
+
* The compiler will leave in foo() (because its return value is used),
|
34
|
+
* but it will remove bar() because it assumes it does not have side-effects.
|
35
|
+
*
|
36
|
+
*/
|
37
|
+
|
38
|
+
|
39
|
+
goog.provide('goog.asserts');
|
40
|
+
goog.provide('goog.asserts.AssertionError');
|
41
|
+
|
42
|
+
goog.require('goog.debug.Error');
|
43
|
+
goog.require('goog.string');
|
44
|
+
|
45
|
+
|
46
|
+
/**
|
47
|
+
* @define {boolean} Whether to strip out asserts or to leave them in.
|
48
|
+
*/
|
49
|
+
goog.asserts.ENABLE_ASSERTS = goog.DEBUG;
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
/**
|
54
|
+
* Error object for failed assertions.
|
55
|
+
* @param {string} messagePattern The pattern that was used to form message.
|
56
|
+
* @param {!Array.<*>} messageArgs The items to substitute into the pattern.
|
57
|
+
* @constructor
|
58
|
+
* @extends {goog.debug.Error}
|
59
|
+
*/
|
60
|
+
goog.asserts.AssertionError = function(messagePattern, messageArgs) {
|
61
|
+
messageArgs.unshift(messagePattern);
|
62
|
+
goog.debug.Error.call(this, goog.string.subs.apply(null, messageArgs));
|
63
|
+
// Remove the messagePattern afterwards to avoid permenantly modifying the
|
64
|
+
// passed in array.
|
65
|
+
messageArgs.shift();
|
66
|
+
|
67
|
+
/**
|
68
|
+
* The message pattern used to format the error message. Error handlers can
|
69
|
+
* use this to uniquely identify the assertion.
|
70
|
+
* @type {string}
|
71
|
+
*/
|
72
|
+
this.messagePattern = messagePattern;
|
73
|
+
};
|
74
|
+
goog.inherits(goog.asserts.AssertionError, goog.debug.Error);
|
75
|
+
|
76
|
+
|
77
|
+
/** @override */
|
78
|
+
goog.asserts.AssertionError.prototype.name = 'AssertionError';
|
79
|
+
|
80
|
+
|
81
|
+
/**
|
82
|
+
* Throws an exception with the given message and "Assertion failed" prefixed
|
83
|
+
* onto it.
|
84
|
+
* @param {string} defaultMessage The message to use if givenMessage is empty.
|
85
|
+
* @param {Array.<*>} defaultArgs The substitution arguments for defaultMessage.
|
86
|
+
* @param {string|undefined} givenMessage Message supplied by the caller.
|
87
|
+
* @param {Array.<*>} givenArgs The substitution arguments for givenMessage.
|
88
|
+
* @throws {goog.asserts.AssertionError} When the value is not a number.
|
89
|
+
* @private
|
90
|
+
*/
|
91
|
+
goog.asserts.doAssertFailure_ =
|
92
|
+
function(defaultMessage, defaultArgs, givenMessage, givenArgs) {
|
93
|
+
var message = 'Assertion failed';
|
94
|
+
if (givenMessage) {
|
95
|
+
message += ': ' + givenMessage;
|
96
|
+
var args = givenArgs;
|
97
|
+
} else if (defaultMessage) {
|
98
|
+
message += ': ' + defaultMessage;
|
99
|
+
args = defaultArgs;
|
100
|
+
}
|
101
|
+
// The '' + works around an Opera 10 bug in the unit tests. Without it,
|
102
|
+
// a stack trace is added to var message above. With this, a stack trace is
|
103
|
+
// not added until this line (it causes the extra garbage to be added after
|
104
|
+
// the assertion message instead of in the middle of it).
|
105
|
+
throw new goog.asserts.AssertionError('' + message, args || []);
|
106
|
+
};
|
107
|
+
|
108
|
+
|
109
|
+
/**
|
110
|
+
* Checks if the condition evaluates to true if goog.asserts.ENABLE_ASSERTS is
|
111
|
+
* true.
|
112
|
+
* @param {*} condition The condition to check.
|
113
|
+
* @param {string=} opt_message Error message in case of failure.
|
114
|
+
* @param {...*} var_args The items to substitute into the failure message.
|
115
|
+
* @return {*} The value of the condition.
|
116
|
+
* @throws {goog.asserts.AssertionError} When the condition evaluates to false.
|
117
|
+
*/
|
118
|
+
goog.asserts.assert = function(condition, opt_message, var_args) {
|
119
|
+
if (goog.asserts.ENABLE_ASSERTS && !condition) {
|
120
|
+
goog.asserts.doAssertFailure_('', null, opt_message,
|
121
|
+
Array.prototype.slice.call(arguments, 2));
|
122
|
+
}
|
123
|
+
return condition;
|
124
|
+
};
|
125
|
+
|
126
|
+
|
127
|
+
/**
|
128
|
+
* Fails if goog.asserts.ENABLE_ASSERTS is true. This function is useful in case
|
129
|
+
* when we want to add a check in the unreachable area like switch-case
|
130
|
+
* statement:
|
131
|
+
*
|
132
|
+
* <pre>
|
133
|
+
* switch(type) {
|
134
|
+
* case FOO: doSomething(); break;
|
135
|
+
* case BAR: doSomethingElse(); break;
|
136
|
+
* default: goog.assert.fail('Unrecognized type: ' + type);
|
137
|
+
* // We have only 2 types - "default:" section is unreachable code.
|
138
|
+
* }
|
139
|
+
* </pre>
|
140
|
+
*
|
141
|
+
* @param {string=} opt_message Error message in case of failure.
|
142
|
+
* @param {...*} var_args The items to substitute into the failure message.
|
143
|
+
* @throws {goog.asserts.AssertionError} Failure.
|
144
|
+
*/
|
145
|
+
goog.asserts.fail = function(opt_message, var_args) {
|
146
|
+
if (goog.asserts.ENABLE_ASSERTS) {
|
147
|
+
throw new goog.asserts.AssertionError(
|
148
|
+
'Failure' + (opt_message ? ': ' + opt_message : ''),
|
149
|
+
Array.prototype.slice.call(arguments, 1));
|
150
|
+
}
|
151
|
+
};
|
152
|
+
|
153
|
+
|
154
|
+
/**
|
155
|
+
* Checks if the value is a number if goog.asserts.ENABLE_ASSERTS is true.
|
156
|
+
* @param {*} value The value to check.
|
157
|
+
* @param {string=} opt_message Error message in case of failure.
|
158
|
+
* @param {...*} var_args The items to substitute into the failure message.
|
159
|
+
* @return {number} The value, guaranteed to be a number when asserts enabled.
|
160
|
+
* @throws {goog.asserts.AssertionError} When the value is not a number.
|
161
|
+
*/
|
162
|
+
goog.asserts.assertNumber = function(value, opt_message, var_args) {
|
163
|
+
if (goog.asserts.ENABLE_ASSERTS && !goog.isNumber(value)) {
|
164
|
+
goog.asserts.doAssertFailure_('Expected number but got %s: %s.',
|
165
|
+
[goog.typeOf(value), value], opt_message,
|
166
|
+
Array.prototype.slice.call(arguments, 2));
|
167
|
+
}
|
168
|
+
return /** @type {number} */ (value);
|
169
|
+
};
|
170
|
+
|
171
|
+
|
172
|
+
/**
|
173
|
+
* Checks if the value is a string if goog.asserts.ENABLE_ASSERTS is true.
|
174
|
+
* @param {*} value The value to check.
|
175
|
+
* @param {string=} opt_message Error message in case of failure.
|
176
|
+
* @param {...*} var_args The items to substitute into the failure message.
|
177
|
+
* @return {string} The value, guaranteed to be a string when asserts enabled.
|
178
|
+
* @throws {goog.asserts.AssertionError} When the value is not a string.
|
179
|
+
*/
|
180
|
+
goog.asserts.assertString = function(value, opt_message, var_args) {
|
181
|
+
if (goog.asserts.ENABLE_ASSERTS && !goog.isString(value)) {
|
182
|
+
goog.asserts.doAssertFailure_('Expected string but got %s: %s.',
|
183
|
+
[goog.typeOf(value), value], opt_message,
|
184
|
+
Array.prototype.slice.call(arguments, 2));
|
185
|
+
}
|
186
|
+
return /** @type {string} */ (value);
|
187
|
+
};
|
188
|
+
|
189
|
+
|
190
|
+
/**
|
191
|
+
* Checks if the value is a function if goog.asserts.ENABLE_ASSERTS is true.
|
192
|
+
* @param {*} value The value to check.
|
193
|
+
* @param {string=} opt_message Error message in case of failure.
|
194
|
+
* @param {...*} var_args The items to substitute into the failure message.
|
195
|
+
* @return {!Function} The value, guaranteed to be a function when asserts
|
196
|
+
* enabled.
|
197
|
+
* @throws {goog.asserts.AssertionError} When the value is not a function.
|
198
|
+
*/
|
199
|
+
goog.asserts.assertFunction = function(value, opt_message, var_args) {
|
200
|
+
if (goog.asserts.ENABLE_ASSERTS && !goog.isFunction(value)) {
|
201
|
+
goog.asserts.doAssertFailure_('Expected function but got %s: %s.',
|
202
|
+
[goog.typeOf(value), value], opt_message,
|
203
|
+
Array.prototype.slice.call(arguments, 2));
|
204
|
+
}
|
205
|
+
return /** @type {!Function} */ (value);
|
206
|
+
};
|
207
|
+
|
208
|
+
|
209
|
+
/**
|
210
|
+
* Checks if the value is an Object if goog.asserts.ENABLE_ASSERTS is true.
|
211
|
+
* @param {*} value The value to check.
|
212
|
+
* @param {string=} opt_message Error message in case of failure.
|
213
|
+
* @param {...*} var_args The items to substitute into the failure message.
|
214
|
+
* @return {!Object} The value, guaranteed to be a non-null object.
|
215
|
+
* @throws {goog.asserts.AssertionError} When the value is not an object.
|
216
|
+
*/
|
217
|
+
goog.asserts.assertObject = function(value, opt_message, var_args) {
|
218
|
+
if (goog.asserts.ENABLE_ASSERTS && !goog.isObject(value)) {
|
219
|
+
goog.asserts.doAssertFailure_('Expected object but got %s: %s.',
|
220
|
+
[goog.typeOf(value), value],
|
221
|
+
opt_message, Array.prototype.slice.call(arguments, 2));
|
222
|
+
}
|
223
|
+
return /** @type {!Object} */ (value);
|
224
|
+
};
|
225
|
+
|
226
|
+
|
227
|
+
/**
|
228
|
+
* Checks if the value is an Array if goog.asserts.ENABLE_ASSERTS is true.
|
229
|
+
* @param {*} value The value to check.
|
230
|
+
* @param {string=} opt_message Error message in case of failure.
|
231
|
+
* @param {...*} var_args The items to substitute into the failure message.
|
232
|
+
* @return {!Array} The value, guaranteed to be a non-null array.
|
233
|
+
* @throws {goog.asserts.AssertionError} When the value is not an array.
|
234
|
+
*/
|
235
|
+
goog.asserts.assertArray = function(value, opt_message, var_args) {
|
236
|
+
if (goog.asserts.ENABLE_ASSERTS && !goog.isArray(value)) {
|
237
|
+
goog.asserts.doAssertFailure_('Expected array but got %s: %s.',
|
238
|
+
[goog.typeOf(value), value], opt_message,
|
239
|
+
Array.prototype.slice.call(arguments, 2));
|
240
|
+
}
|
241
|
+
return /** @type {!Array} */ (value);
|
242
|
+
};
|
243
|
+
|
244
|
+
|
245
|
+
/**
|
246
|
+
* Checks if the value is a boolean if goog.asserts.ENABLE_ASSERTS is true.
|
247
|
+
* @param {*} value The value to check.
|
248
|
+
* @param {string=} opt_message Error message in case of failure.
|
249
|
+
* @param {...*} var_args The items to substitute into the failure message.
|
250
|
+
* @return {boolean} The value, guaranteed to be a boolean when asserts are
|
251
|
+
* enabled.
|
252
|
+
* @throws {goog.asserts.AssertionError} When the value is not a boolean.
|
253
|
+
*/
|
254
|
+
goog.asserts.assertBoolean = function(value, opt_message, var_args) {
|
255
|
+
if (goog.asserts.ENABLE_ASSERTS && !goog.isBoolean(value)) {
|
256
|
+
goog.asserts.doAssertFailure_('Expected boolean but got %s: %s.',
|
257
|
+
[goog.typeOf(value), value], opt_message,
|
258
|
+
Array.prototype.slice.call(arguments, 2));
|
259
|
+
}
|
260
|
+
return /** @type {boolean} */ (value);
|
261
|
+
};
|
262
|
+
|
263
|
+
|
264
|
+
/**
|
265
|
+
* Checks if the value is an instance of the user-defined type if
|
266
|
+
* goog.asserts.ENABLE_ASSERTS is true.
|
267
|
+
* @param {*} value The value to check.
|
268
|
+
* @param {!Function} type A user-defined constructor.
|
269
|
+
* @param {string=} opt_message Error message in case of failure.
|
270
|
+
* @param {...*} var_args The items to substitute into the failure message.
|
271
|
+
* @throws {goog.asserts.AssertionError} When the value is not an instance of
|
272
|
+
* type.
|
273
|
+
*/
|
274
|
+
goog.asserts.assertInstanceof = function(value, type, opt_message, var_args) {
|
275
|
+
if (goog.asserts.ENABLE_ASSERTS && !(value instanceof type)) {
|
276
|
+
goog.asserts.doAssertFailure_('instanceof check failed.', null,
|
277
|
+
opt_message, Array.prototype.slice.call(arguments, 3));
|
278
|
+
}
|
279
|
+
};
|
280
|
+
|
281
|
+
;
|
282
|
+
FI"
|
283
|
+
F"%6d1163dce166bc398445852c1e98d4fb
|
@@ -0,0 +1,590 @@
|
|
1
|
+
o: ActiveSupport::Cache::Entry :@compressedF:@expires_in0:@created_atf1325549268.0414011:@value{ I"length:EFi�AI"digest;
|
2
|
+
F"%e2977c5b38c5ec8860b855f7afd757baI"source;
|
3
|
+
FI"�A// Copyright 2006 The Closure Library Authors. All Rights Reserved.
|
4
|
+
//
|
5
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
// you may not use this file except in compliance with the License.
|
7
|
+
// You may obtain a copy of the License at
|
8
|
+
//
|
9
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
//
|
11
|
+
// Unless required by applicable law or agreed to in writing, software
|
12
|
+
// distributed under the License is distributed on an "AS-IS" BASIS,
|
13
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
// See the License for the specific language governing permissions and
|
15
|
+
// limitations under the License.
|
16
|
+
|
17
|
+
/**
|
18
|
+
* @fileoverview Utilities for manipulating objects/maps/hashes.
|
19
|
+
*/
|
20
|
+
|
21
|
+
|
22
|
+
goog.provide('goog.object');
|
23
|
+
|
24
|
+
|
25
|
+
/**
|
26
|
+
* Calls a function for each element in an object/map/hash.
|
27
|
+
*
|
28
|
+
* @param {Object} obj The object over which to iterate.
|
29
|
+
* @param {Function} f The function to call for every element. This function
|
30
|
+
* takes 3 arguments (the element, the index and the object)
|
31
|
+
* and the return value is irrelevant.
|
32
|
+
* @param {Object=} opt_obj This is used as the 'this' object within f.
|
33
|
+
*/
|
34
|
+
goog.object.forEach = function(obj, f, opt_obj) {
|
35
|
+
for (var key in obj) {
|
36
|
+
f.call(opt_obj, obj[key], key, obj);
|
37
|
+
}
|
38
|
+
};
|
39
|
+
|
40
|
+
|
41
|
+
/**
|
42
|
+
* Calls a function for each element in an object/map/hash. If that call returns
|
43
|
+
* true, adds the element to a new object.
|
44
|
+
*
|
45
|
+
* @param {Object} obj The object over which to iterate.
|
46
|
+
* @param {Function} f The function to call for every element. This
|
47
|
+
* function takes 3 arguments (the element, the index and the object)
|
48
|
+
* and should return a boolean. If the return value is true the
|
49
|
+
* element is added to the result object. If it is false the
|
50
|
+
* element is not included.
|
51
|
+
* @param {Object=} opt_obj This is used as the 'this' object within f.
|
52
|
+
* @return {!Object} a new object in which only elements that passed the test
|
53
|
+
* are present.
|
54
|
+
*/
|
55
|
+
goog.object.filter = function(obj, f, opt_obj) {
|
56
|
+
var res = {};
|
57
|
+
for (var key in obj) {
|
58
|
+
if (f.call(opt_obj, obj[key], key, obj)) {
|
59
|
+
res[key] = obj[key];
|
60
|
+
}
|
61
|
+
}
|
62
|
+
return res;
|
63
|
+
};
|
64
|
+
|
65
|
+
|
66
|
+
/**
|
67
|
+
* For every element in an object/map/hash calls a function and inserts the
|
68
|
+
* result into a new object.
|
69
|
+
*
|
70
|
+
* @param {Object} obj The object over which to iterate.
|
71
|
+
* @param {Function} f The function to call for every element. This function
|
72
|
+
* takes 3 arguments (the element, the index and the object)
|
73
|
+
* and should return something. The result will be inserted
|
74
|
+
* into a new object.
|
75
|
+
* @param {Object=} opt_obj This is used as the 'this' object within f.
|
76
|
+
* @return {!Object} a new object with the results from f.
|
77
|
+
*/
|
78
|
+
goog.object.map = function(obj, f, opt_obj) {
|
79
|
+
var res = {};
|
80
|
+
for (var key in obj) {
|
81
|
+
res[key] = f.call(opt_obj, obj[key], key, obj);
|
82
|
+
}
|
83
|
+
return res;
|
84
|
+
};
|
85
|
+
|
86
|
+
|
87
|
+
/**
|
88
|
+
* Calls a function for each element in an object/map/hash. If any
|
89
|
+
* call returns true, returns true (without checking the rest). If
|
90
|
+
* all calls return false, returns false.
|
91
|
+
*
|
92
|
+
* @param {Object} obj The object to check.
|
93
|
+
* @param {Function} f The function to call for every element. This function
|
94
|
+
* takes 3 arguments (the element, the index and the object) and should
|
95
|
+
* return a boolean.
|
96
|
+
* @param {Object=} opt_obj This is used as the 'this' object within f.
|
97
|
+
* @return {boolean} true if any element passes the test.
|
98
|
+
*/
|
99
|
+
goog.object.some = function(obj, f, opt_obj) {
|
100
|
+
for (var key in obj) {
|
101
|
+
if (f.call(opt_obj, obj[key], key, obj)) {
|
102
|
+
return true;
|
103
|
+
}
|
104
|
+
}
|
105
|
+
return false;
|
106
|
+
};
|
107
|
+
|
108
|
+
|
109
|
+
/**
|
110
|
+
* Calls a function for each element in an object/map/hash. If
|
111
|
+
* all calls return true, returns true. If any call returns false, returns
|
112
|
+
* false at this point and does not continue to check the remaining elements.
|
113
|
+
*
|
114
|
+
* @param {Object} obj The object to check.
|
115
|
+
* @param {Function} f The function to call for every element. This function
|
116
|
+
* takes 3 arguments (the element, the index and the object) and should
|
117
|
+
* return a boolean.
|
118
|
+
* @param {Object=} opt_obj This is used as the 'this' object within f.
|
119
|
+
* @return {boolean} false if any element fails the test.
|
120
|
+
*/
|
121
|
+
goog.object.every = function(obj, f, opt_obj) {
|
122
|
+
for (var key in obj) {
|
123
|
+
if (!f.call(opt_obj, obj[key], key, obj)) {
|
124
|
+
return false;
|
125
|
+
}
|
126
|
+
}
|
127
|
+
return true;
|
128
|
+
};
|
129
|
+
|
130
|
+
|
131
|
+
/**
|
132
|
+
* Returns the number of key-value pairs in the object map.
|
133
|
+
*
|
134
|
+
* @param {Object} obj The object for which to get the number of key-value
|
135
|
+
* pairs.
|
136
|
+
* @return {number} The number of key-value pairs in the object map.
|
137
|
+
*/
|
138
|
+
goog.object.getCount = function(obj) {
|
139
|
+
// JS1.5 has __count__ but it has been deprecated so it raises a warning...
|
140
|
+
// in other words do not use. Also __count__ only includes the fields on the
|
141
|
+
// actual object and not in the prototype chain.
|
142
|
+
var rv = 0;
|
143
|
+
for (var key in obj) {
|
144
|
+
rv++;
|
145
|
+
}
|
146
|
+
return rv;
|
147
|
+
};
|
148
|
+
|
149
|
+
|
150
|
+
/**
|
151
|
+
* Returns one key from the object map, if any exists.
|
152
|
+
* For map literals the returned key will be the first one in most of the
|
153
|
+
* browsers (a know exception is Konqueror).
|
154
|
+
*
|
155
|
+
* @param {Object} obj The object to pick a key from.
|
156
|
+
* @return {string|undefined} The key or undefined if the object is empty.
|
157
|
+
*/
|
158
|
+
goog.object.getAnyKey = function(obj) {
|
159
|
+
for (var key in obj) {
|
160
|
+
return key;
|
161
|
+
}
|
162
|
+
};
|
163
|
+
|
164
|
+
|
165
|
+
/**
|
166
|
+
* Returns one value from the object map, if any exists.
|
167
|
+
* For map literals the returned value will be the first one in most of the
|
168
|
+
* browsers (a know exception is Konqueror).
|
169
|
+
*
|
170
|
+
* @param {Object} obj The object to pick a value from.
|
171
|
+
* @return {*} The value or undefined if the object is empty.
|
172
|
+
*/
|
173
|
+
goog.object.getAnyValue = function(obj) {
|
174
|
+
for (var key in obj) {
|
175
|
+
return obj[key];
|
176
|
+
}
|
177
|
+
};
|
178
|
+
|
179
|
+
|
180
|
+
/**
|
181
|
+
* Whether the object/hash/map contains the given object as a value.
|
182
|
+
* An alias for goog.object.containsValue(obj, val).
|
183
|
+
*
|
184
|
+
* @param {Object} obj The object in which to look for val.
|
185
|
+
* @param {*} val The object for which to check.
|
186
|
+
* @return {boolean} true if val is present.
|
187
|
+
*/
|
188
|
+
goog.object.contains = function(obj, val) {
|
189
|
+
return goog.object.containsValue(obj, val);
|
190
|
+
};
|
191
|
+
|
192
|
+
|
193
|
+
/**
|
194
|
+
* Returns the values of the object/map/hash.
|
195
|
+
*
|
196
|
+
* @param {Object} obj The object from which to get the values.
|
197
|
+
* @return {!Array} The values in the object/map/hash.
|
198
|
+
*/
|
199
|
+
goog.object.getValues = function(obj) {
|
200
|
+
var res = [];
|
201
|
+
var i = 0;
|
202
|
+
for (var key in obj) {
|
203
|
+
res[i++] = obj[key];
|
204
|
+
}
|
205
|
+
return res;
|
206
|
+
};
|
207
|
+
|
208
|
+
|
209
|
+
/**
|
210
|
+
* Returns the keys of the object/map/hash.
|
211
|
+
*
|
212
|
+
* @param {Object} obj The object from which to get the keys.
|
213
|
+
* @return {!Array.<string>} Array of property keys.
|
214
|
+
*/
|
215
|
+
goog.object.getKeys = function(obj) {
|
216
|
+
var res = [];
|
217
|
+
var i = 0;
|
218
|
+
for (var key in obj) {
|
219
|
+
res[i++] = key;
|
220
|
+
}
|
221
|
+
return res;
|
222
|
+
};
|
223
|
+
|
224
|
+
|
225
|
+
/**
|
226
|
+
* Get a value from an object multiple levels deep. This is useful for
|
227
|
+
* pulling values from deeply nested objects, such as JSON responses.
|
228
|
+
* Example usage: getValueByKeys(jsonObj, 'foo', 'entries', 3)
|
229
|
+
*
|
230
|
+
* @param {!Object} obj An object to get the value from. Can be array-like.
|
231
|
+
* @param {...(string|number|!Array.<number|string>)} var_args A number of keys
|
232
|
+
* (as strings, or nubmers, for array-like objects). Can also be
|
233
|
+
* specified as a single array of keys.
|
234
|
+
* @return {*} The resulting value. If, at any point, the value for a key
|
235
|
+
* is undefined, returns undefined.
|
236
|
+
*/
|
237
|
+
goog.object.getValueByKeys = function(obj, var_args) {
|
238
|
+
var isArrayLike = goog.isArrayLike(var_args);
|
239
|
+
var keys = isArrayLike ? var_args : arguments;
|
240
|
+
|
241
|
+
// Start with the 2nd parameter for the variable parameters syntax.
|
242
|
+
for (var i = isArrayLike ? 0 : 1; i < keys.length; i++) {
|
243
|
+
obj = obj[keys[i]];
|
244
|
+
if (!goog.isDef(obj)) {
|
245
|
+
break;
|
246
|
+
}
|
247
|
+
}
|
248
|
+
|
249
|
+
return obj;
|
250
|
+
};
|
251
|
+
|
252
|
+
|
253
|
+
/**
|
254
|
+
* Whether the object/map/hash contains the given key.
|
255
|
+
*
|
256
|
+
* @param {Object} obj The object in which to look for key.
|
257
|
+
* @param {*} key The key for which to check.
|
258
|
+
* @return {boolean} true If the map contains the key.
|
259
|
+
*/
|
260
|
+
goog.object.containsKey = function(obj, key) {
|
261
|
+
return key in obj;
|
262
|
+
};
|
263
|
+
|
264
|
+
|
265
|
+
/**
|
266
|
+
* Whether the object/map/hash contains the given value. This is O(n).
|
267
|
+
*
|
268
|
+
* @param {Object} obj The object in which to look for val.
|
269
|
+
* @param {*} val The value for which to check.
|
270
|
+
* @return {boolean} true If the map contains the value.
|
271
|
+
*/
|
272
|
+
goog.object.containsValue = function(obj, val) {
|
273
|
+
for (var key in obj) {
|
274
|
+
if (obj[key] == val) {
|
275
|
+
return true;
|
276
|
+
}
|
277
|
+
}
|
278
|
+
return false;
|
279
|
+
};
|
280
|
+
|
281
|
+
|
282
|
+
/**
|
283
|
+
* Searches an object for an element that satisfies the given condition and
|
284
|
+
* returns its key.
|
285
|
+
* @param {Object} obj The object to search in.
|
286
|
+
* @param {function(*, string, Object): boolean} f The function to call for
|
287
|
+
* every element. Takes 3 arguments (the value, the key and the object) and
|
288
|
+
* should return a boolean.
|
289
|
+
* @param {Object=} opt_this An optional "this" context for the function.
|
290
|
+
* @return {string|undefined} The key of an element for which the function
|
291
|
+
* returns true or undefined if no such element is found.
|
292
|
+
*/
|
293
|
+
goog.object.findKey = function(obj, f, opt_this) {
|
294
|
+
for (var key in obj) {
|
295
|
+
if (f.call(opt_this, obj[key], key, obj)) {
|
296
|
+
return key;
|
297
|
+
}
|
298
|
+
}
|
299
|
+
return undefined;
|
300
|
+
};
|
301
|
+
|
302
|
+
|
303
|
+
/**
|
304
|
+
* Searches an object for an element that satisfies the given condition and
|
305
|
+
* returns its value.
|
306
|
+
* @param {Object} obj The object to search in.
|
307
|
+
* @param {function(*, string, Object): boolean} f The function to call for
|
308
|
+
* every element. Takes 3 arguments (the value, the key and the object) and
|
309
|
+
* should return a boolean.
|
310
|
+
* @param {Object=} opt_this An optional "this" context for the function.
|
311
|
+
* @return {*} The value of an element for which the function returns true or
|
312
|
+
* undefined if no such element is found.
|
313
|
+
*/
|
314
|
+
goog.object.findValue = function(obj, f, opt_this) {
|
315
|
+
var key = goog.object.findKey(obj, f, opt_this);
|
316
|
+
return key && obj[key];
|
317
|
+
};
|
318
|
+
|
319
|
+
|
320
|
+
/**
|
321
|
+
* Whether the object/map/hash is empty.
|
322
|
+
*
|
323
|
+
* @param {Object} obj The object to test.
|
324
|
+
* @return {boolean} true if obj is empty.
|
325
|
+
*/
|
326
|
+
goog.object.isEmpty = function(obj) {
|
327
|
+
for (var key in obj) {
|
328
|
+
return false;
|
329
|
+
}
|
330
|
+
return true;
|
331
|
+
};
|
332
|
+
|
333
|
+
|
334
|
+
/**
|
335
|
+
* Removes all key value pairs from the object/map/hash.
|
336
|
+
*
|
337
|
+
* @param {Object} obj The object to clear.
|
338
|
+
*/
|
339
|
+
goog.object.clear = function(obj) {
|
340
|
+
for (var i in obj) {
|
341
|
+
delete obj[i];
|
342
|
+
}
|
343
|
+
};
|
344
|
+
|
345
|
+
|
346
|
+
/**
|
347
|
+
* Removes a key-value pair based on the key.
|
348
|
+
*
|
349
|
+
* @param {Object} obj The object from which to remove the key.
|
350
|
+
* @param {*} key The key to remove.
|
351
|
+
* @return {boolean} Whether an element was removed.
|
352
|
+
*/
|
353
|
+
goog.object.remove = function(obj, key) {
|
354
|
+
var rv;
|
355
|
+
if ((rv = key in obj)) {
|
356
|
+
delete obj[key];
|
357
|
+
}
|
358
|
+
return rv;
|
359
|
+
};
|
360
|
+
|
361
|
+
|
362
|
+
/**
|
363
|
+
* Adds a key-value pair to the object. Throws an exception if the key is
|
364
|
+
* already in use. Use set if you want to change an existing pair.
|
365
|
+
*
|
366
|
+
* @param {Object} obj The object to which to add the key-value pair.
|
367
|
+
* @param {string} key The key to add.
|
368
|
+
* @param {*} val The value to add.
|
369
|
+
*/
|
370
|
+
goog.object.add = function(obj, key, val) {
|
371
|
+
if (key in obj) {
|
372
|
+
throw Error('The object already contains the key "' + key + '"');
|
373
|
+
}
|
374
|
+
goog.object.set(obj, key, val);
|
375
|
+
};
|
376
|
+
|
377
|
+
|
378
|
+
/**
|
379
|
+
* Returns the value for the given key.
|
380
|
+
*
|
381
|
+
* @param {Object} obj The object from which to get the value.
|
382
|
+
* @param {string} key The key for which to get the value.
|
383
|
+
* @param {*=} opt_val The value to return if no item is found for the given
|
384
|
+
* key (default is undefined).
|
385
|
+
* @return {*} The value for the given key.
|
386
|
+
*/
|
387
|
+
goog.object.get = function(obj, key, opt_val) {
|
388
|
+
if (key in obj) {
|
389
|
+
return obj[key];
|
390
|
+
}
|
391
|
+
return opt_val;
|
392
|
+
};
|
393
|
+
|
394
|
+
|
395
|
+
/**
|
396
|
+
* Adds a key-value pair to the object/map/hash.
|
397
|
+
*
|
398
|
+
* @param {Object} obj The object to which to add the key-value pair.
|
399
|
+
* @param {string} key The key to add.
|
400
|
+
* @param {*} value The value to add.
|
401
|
+
*/
|
402
|
+
goog.object.set = function(obj, key, value) {
|
403
|
+
obj[key] = value;
|
404
|
+
};
|
405
|
+
|
406
|
+
|
407
|
+
/**
|
408
|
+
* Adds a key-value pair to the object/map/hash if it doesn't exist yet.
|
409
|
+
*
|
410
|
+
* @param {Object} obj The object to which to add the key-value pair.
|
411
|
+
* @param {string} key The key to add.
|
412
|
+
* @param {*} value The value to add if the key wasn't present.
|
413
|
+
* @return {*} The value of the entry at the end of the function.
|
414
|
+
*/
|
415
|
+
goog.object.setIfUndefined = function(obj, key, value) {
|
416
|
+
return key in obj ? obj[key] : (obj[key] = value);
|
417
|
+
};
|
418
|
+
|
419
|
+
|
420
|
+
/**
|
421
|
+
* Does a flat clone of the object.
|
422
|
+
*
|
423
|
+
* @param {Object} obj Object to clone.
|
424
|
+
* @return {!Object} Clone of the input object.
|
425
|
+
*/
|
426
|
+
goog.object.clone = function(obj) {
|
427
|
+
// We cannot use the prototype trick because a lot of methods depend on where
|
428
|
+
// the actual key is set.
|
429
|
+
|
430
|
+
var res = {};
|
431
|
+
for (var key in obj) {
|
432
|
+
res[key] = obj[key];
|
433
|
+
}
|
434
|
+
return res;
|
435
|
+
// We could also use goog.mixin but I wanted this to be independent from that.
|
436
|
+
};
|
437
|
+
|
438
|
+
|
439
|
+
/**
|
440
|
+
* Clones a value. The input may be an Object, Array, or basic type. Objects and
|
441
|
+
* arrays will be cloned recursively.
|
442
|
+
*
|
443
|
+
* WARNINGS:
|
444
|
+
* <code>goog.object.unsafeClone</code> does not detect reference loops. Objects
|
445
|
+
* that refer to themselves will cause infinite recursion.
|
446
|
+
*
|
447
|
+
* <code>goog.object.unsafeClone</code> is unaware of unique identifiers, and
|
448
|
+
* copies UIDs created by <code>getUid</code> into cloned results.
|
449
|
+
*
|
450
|
+
* @param {*} obj The value to clone.
|
451
|
+
* @return {*} A clone of the input value.
|
452
|
+
*/
|
453
|
+
goog.object.unsafeClone = function(obj) {
|
454
|
+
var type = goog.typeOf(obj);
|
455
|
+
if (type == 'object' || type == 'array') {
|
456
|
+
if (obj.clone) {
|
457
|
+
return obj.clone();
|
458
|
+
}
|
459
|
+
var clone = type == 'array' ? [] : {};
|
460
|
+
for (var key in obj) {
|
461
|
+
clone[key] = goog.object.unsafeClone(obj[key]);
|
462
|
+
}
|
463
|
+
return clone;
|
464
|
+
}
|
465
|
+
|
466
|
+
return obj;
|
467
|
+
};
|
468
|
+
|
469
|
+
|
470
|
+
/**
|
471
|
+
* Returns a new object in which all the keys and values are interchanged
|
472
|
+
* (keys become values and values become keys). If multiple keys map to the
|
473
|
+
* same value, the chosen transposed value is implementation-dependent.
|
474
|
+
*
|
475
|
+
* @param {Object} obj The object to transpose.
|
476
|
+
* @return {!Object} The transposed object.
|
477
|
+
*/
|
478
|
+
goog.object.transpose = function(obj) {
|
479
|
+
var transposed = {};
|
480
|
+
for (var key in obj) {
|
481
|
+
transposed[obj[key]] = key;
|
482
|
+
}
|
483
|
+
return transposed;
|
484
|
+
};
|
485
|
+
|
486
|
+
|
487
|
+
/**
|
488
|
+
* The names of the fields that are defined on Object.prototype.
|
489
|
+
* @type {Array.<string>}
|
490
|
+
* @private
|
491
|
+
*/
|
492
|
+
goog.object.PROTOTYPE_FIELDS_ = [
|
493
|
+
'constructor',
|
494
|
+
'hasOwnProperty',
|
495
|
+
'isPrototypeOf',
|
496
|
+
'propertyIsEnumerable',
|
497
|
+
'toLocaleString',
|
498
|
+
'toString',
|
499
|
+
'valueOf'
|
500
|
+
];
|
501
|
+
|
502
|
+
|
503
|
+
/**
|
504
|
+
* Extends an object with another object.
|
505
|
+
* This operates 'in-place'; it does not create a new Object.
|
506
|
+
*
|
507
|
+
* Example:
|
508
|
+
* var o = {};
|
509
|
+
* goog.object.extend(o, {a: 0, b: 1});
|
510
|
+
* o; // {a: 0, b: 1}
|
511
|
+
* goog.object.extend(o, {c: 2});
|
512
|
+
* o; // {a: 0, b: 1, c: 2}
|
513
|
+
*
|
514
|
+
* @param {Object} target The object to modify.
|
515
|
+
* @param {...Object} var_args The objects from which values will be copied.
|
516
|
+
*/
|
517
|
+
goog.object.extend = function(target, var_args) {
|
518
|
+
var key, source;
|
519
|
+
for (var i = 1; i < arguments.length; i++) {
|
520
|
+
source = arguments[i];
|
521
|
+
for (key in source) {
|
522
|
+
target[key] = source[key];
|
523
|
+
}
|
524
|
+
|
525
|
+
// For IE the for-in-loop does not contain any properties that are not
|
526
|
+
// enumerable on the prototype object (for example isPrototypeOf from
|
527
|
+
// Object.prototype) and it will also not include 'replace' on objects that
|
528
|
+
// extend String and change 'replace' (not that it is common for anyone to
|
529
|
+
// extend anything except Object).
|
530
|
+
|
531
|
+
for (var j = 0; j < goog.object.PROTOTYPE_FIELDS_.length; j++) {
|
532
|
+
key = goog.object.PROTOTYPE_FIELDS_[j];
|
533
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
534
|
+
target[key] = source[key];
|
535
|
+
}
|
536
|
+
}
|
537
|
+
}
|
538
|
+
};
|
539
|
+
|
540
|
+
|
541
|
+
/**
|
542
|
+
* Creates a new object built from the key-value pairs provided as arguments.
|
543
|
+
* @param {...*} var_args If only one argument is provided and it is an array
|
544
|
+
* then this is used as the arguments, otherwise even arguments are used as
|
545
|
+
* the property names and odd arguments are used as the property values.
|
546
|
+
* @return {!Object} The new object.
|
547
|
+
* @throws {Error} If there are uneven number of arguments or there is only one
|
548
|
+
* non array argument.
|
549
|
+
*/
|
550
|
+
goog.object.create = function(var_args) {
|
551
|
+
var argLength = arguments.length;
|
552
|
+
if (argLength == 1 && goog.isArray(arguments[0])) {
|
553
|
+
return goog.object.create.apply(null, arguments[0]);
|
554
|
+
}
|
555
|
+
|
556
|
+
if (argLength % 2) {
|
557
|
+
throw Error('Uneven number of arguments');
|
558
|
+
}
|
559
|
+
|
560
|
+
var rv = {};
|
561
|
+
for (var i = 0; i < argLength; i += 2) {
|
562
|
+
rv[arguments[i]] = arguments[i + 1];
|
563
|
+
}
|
564
|
+
return rv;
|
565
|
+
};
|
566
|
+
|
567
|
+
|
568
|
+
/**
|
569
|
+
* Creates a new object where the property names come from the arguments but
|
570
|
+
* the value is always set to true
|
571
|
+
* @param {...*} var_args If only one argument is provided and it is an array
|
572
|
+
* then this is used as the arguments, otherwise the arguments are used
|
573
|
+
* as the property names.
|
574
|
+
* @return {!Object} The new object.
|
575
|
+
*/
|
576
|
+
goog.object.createSet = function(var_args) {
|
577
|
+
var argLength = arguments.length;
|
578
|
+
if (argLength == 1 && goog.isArray(arguments[0])) {
|
579
|
+
return goog.object.createSet.apply(null, arguments[0]);
|
580
|
+
}
|
581
|
+
|
582
|
+
var rv = {};
|
583
|
+
for (var i = 0; i < argLength; i++) {
|
584
|
+
rv[arguments[i]] = true;
|
585
|
+
}
|
586
|
+
return rv;
|
587
|
+
};
|
588
|
+
;
|
589
|
+
FI"
|
590
|
+
F"%af34e2a3eb5b6b372811cd10c81eeb94
|