--- http_interactions: - request: method: get uri: http://builds.emberjs.com/tags/v1.0.0-beta.1/ember-data.js body: encoding: US-ASCII string: '' headers: Accept-Encoding: - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 Accept: - '*/*' User-Agent: - Ruby Host: - builds.emberjs.com response: status: code: 200 message: OK headers: X-Amz-Id-2: - cKB1NvBMCMXyzmglhVgd1u4e4s13hLCdLXuTzMqnAn1PZxM4EI11VQvuKVKtg5oG X-Amz-Request-Id: - 15EB4E489F8710FA Date: - Mon, 17 Feb 2014 11:45:23 GMT Last-Modified: - Sun, 01 Sep 2013 07:45:26 GMT Etag: - '"5829a6a7e731efc80e1d5677513e2d24"' Content-Type: - text/javascript Content-Length: - '184834' Server: - AmazonS3 body: encoding: ASCII-8BIT string: !binary |- Ly8gVmVyc2lvbjogdjEuMC4wLWJldGEuMQovLyBMYXN0IGNvbW1pdDogY2Fm YWI5ZCAoMjAxMy0wOS0wMSAwMDo0MjozOSAtMDcwMCkKCgooZnVuY3Rpb24o KSB7CnZhciBkZWZpbmUsIHJlcXVpcmVNb2R1bGU7CgooZnVuY3Rpb24oKSB7 CiAgdmFyIHJlZ2lzdHJ5ID0ge30sIHNlZW4gPSB7fTsKCiAgZGVmaW5lID0g ZnVuY3Rpb24obmFtZSwgZGVwcywgY2FsbGJhY2spIHsKICAgIHJlZ2lzdHJ5 W25hbWVdID0geyBkZXBzOiBkZXBzLCBjYWxsYmFjazogY2FsbGJhY2sgfTsK ICB9OwoKICByZXF1aXJlTW9kdWxlID0gZnVuY3Rpb24obmFtZSkgewogICAg aWYgKHNlZW5bbmFtZV0pIHsgcmV0dXJuIHNlZW5bbmFtZV07IH0KICAgIHNl ZW5bbmFtZV0gPSB7fTsKCiAgICB2YXIgbW9kLCBkZXBzLCBjYWxsYmFjaywg cmVpZmllZCAsIGV4cG9ydHM7CgogICAgbW9kID0gcmVnaXN0cnlbbmFtZV07 CgogICAgaWYgKCFtb2QpIHsKICAgICAgdGhyb3cgbmV3IEVycm9y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G1hdHJ8dmVydHxpbmQpKD86 aXh8ZXgpJC9pLCAnJDFpY2VzJ10sCiAgICBbL14obXxsKW91c2UkL2ksICck MWljZSddLAogICAgWy9eKG18bClpY2UkL2ksICckMWljZSddLAogICAgWy9e KG94KSQvaSwgJyQxZW4nXSwKICAgIFsvXihveGVuKSQvaSwgJyQxJ10sCiAg ICBbLyhxdWl6KSQvaSwgJyQxemVzJ10KICBdLAoKICBzaW5ndWxhcjogWwog ICAgWy9zJC9pLCAnJ10sCiAgICBbLyhzcykkL2ksICckMSddLAogICAgWy8o billd3MkL2ksICckMWV3cyddLAogICAgWy8oW3RpXSlhJC9pLCAnJDF1bSdd LAogICAgWy8oKGEpbmFseXwoYilhfChkKWlhZ25vfChwKWFyZW50aGV8KHAp cm9nbm98KHMpeW5vcHwodCloZSkoc2lzfHNlcykkL2ksICckMXNpcyddLAog ICAgWy8oXmFuYWx5KShzaXN8c2VzKSQvaSwgJyQxc2lzJ10sCiAgICBbLyhb XmZdKXZlcyQvaSwgJyQxZmUnXSwKICAgIFsvKGhpdmUpcyQvaSwgJyQxJ10s CiAgICBbLyh0aXZlKXMkL2ksICckMSddLAogICAgWy8oW2xyXSl2ZXMkL2ks ICckMWYnXSwKICAgIFsvKFteYWVpb3V5XXxxdSlpZXMkL2ksICckMXknXSwK ICAgIFsvKHMpZXJpZXMkL2ksICckMWVyaWVzJ10sCiAgICBbLyhtKW92aWVz JC9pLCAnJDFvdmllJ10sCiAgICBbLyh4fGNofHNzfHNoKWVzJC9pLCAnJDEn XSwKICAgIFsvXihtfGwpaWNlJC9pLCAnJDFvdXNlJ10sCiAgICBbLyhidXMp KGVzKT8kL2ksICckMSddLAogICAgWy8obyllcyQvaSwgJyQxJ10sCiAgICBb LyhzaG9lKXMkL2ksICckMSddLAogICAgWy8oY3Jpc3x0ZXN0KShpc3xlcykk L2ksICckMWlzJ10sCiAgICBbL14oYSl4W2llXXMkL2ksICckMXhpcyddLAog ICAgWy8ob2N0b3B8dmlyKSh1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ogewogICAgZGVzZXJp YWxpemU6IGZ1bmN0aW9uKHNlcmlhbGl6ZWQpIHsKICAgICAgdmFyIHR5cGUg PSB0eXBlb2Ygc2VyaWFsaXplZDsKCiAgICAgIGlmICh0eXBlID09PSAiYm9v bGVhbiIpIHsKICAgICAgICByZXR1cm4gc2VyaWFsaXplZDsKICAgICAgfSBl bHNlIGlmICh0eXBlID09PSAic3RyaW5nIikgewogICAgICAgIHJldHVybiBz ZXJpYWxpemVkLm1hdGNoKC9edHJ1ZSR8XnQkfF4xJC9pKSAhPT0gbnVsbDsK ICAgICAgfSBlbHNlIGlmICh0eXBlID09PSAibnVtYmVyIikgewogICAgICAg IHJldHVybiBzZXJpYWxpemVkID09PSAxOwogICAgICB9IGVsc2UgewogICAg ICAgIHJldHVybiBmYWxzZTsKICAgICAgfQogICAgfSwKCiAgICBzZXJpYWxp emU6IGZ1bmN0aW9uKGRlc2VyaWFsaXplZCkgewogICAgICByZXR1cm4gQm9v bGVhbihkZXNlcmlhbGl6ZWQpOwogICAgfQogIH0sCgogIGRhdGU6IHsKICAg IGRlc2VyaWFsaXplOiBmdW5jdGlvbihzZXJpYWxpemVkKSB7CiAgICAgIHZh ciB0eXBlID0gdHlwZW9mIHNlcmlhbGl6ZWQ7CgogICAgICBpZiAodHlwZSA9 PT0gInN0cmluZyIpIHsKICAgICAgICByZXR1cm4gbmV3IERhdGUoRW1iZXIu RGF0ZS5wYXJzZShzZXJpYWxpemVkKSk7CiAgICAgIH0gZWxzZSBpZiAodHlw ZSA9PT0gIm51bWJlciIpIHsKICAgICAgICByZXR1cm4gbmV3IERhdGUoc2Vy aWFsaXplZCk7CiAgICAgIH0gZWxzZSBpZiAoc2VyaWFsaXplZCA9PT0gbnVs bCB8fCBzZXJpYWxpemVkID09PSB1bmRlZmluZWQpIHsKICAgICAgICAvLyBp ZiB0aGUgdmFsdWUgaXMgbm90IHByZXNlbnQgaW4gdGhlIGRhdGEsCiAgICAg ICAgLy8gcmV0dXJuIHVuZGVmaW5lZCwgbm90IG51bGwuCiAgICAgICAgcmV0 dXJuIHNlcmlhbGl6ZWQ7CiAgICAgIH0gZWxzZSB7CiAgICAgICAgcmV0dXJu IG51bGw7CiAgICAgIH0KICAgIH0sCgogICAgc2VyaWFsaXplOiBmdW5jdGlv bihkYXRlKSB7CiAgICAgIGlmIChkYXRlIGluc3RhbmNlb2YgRGF0ZSkgewog ICAgICAgIHZhciBkYXlzID0gWyJTdW4iLCAiTW9uIiwgIlR1ZSIsICJXZWQi LCAiVGh1IiwgIkZyaSIsICJTYXQiXTsKICAgICAgICB2YXIgbW9udGhzID0g WyJKYW4iLCAiRmViIiwgIk1hciIsICJBcHIiLCAiTWF5IiwgIkp1biIsICJK dWwiLCAiQXVnIiwgIlNlcCIsICJPY3QiLCAiTm92IiwgIkRlYyJdOwoKICAg ICAgICB2YXIgcGFkID0gZnVuY3Rpb24obnVtKSB7CiAgICAgICAgICByZXR1 cm4gbnVtIDwgMTAgPyAiMCIrbnVtIDogIiIrbnVtOwogICAgICAgIH07Cgog ICAgICAgIHZhciB1dGNZZWFyID0gZGF0ZS5nZXRVVENGdWxsWWVhcigpLAog ICAgICAgICAgICB1dGNNb250aCA9IGRhdGUuZ2V0VVRDTW9udGgoKSwKICAg ICAgICAgICAgdXRjRGF5T2ZNb250aCA9IGRhdGUuZ2V0VVRDRGF0ZSgpLAog ICAgICAgICAgICB1dGNEYXkgPSBkYXRlLmdldFVUQ0RheSgpLAogICAgICAg ICAgICB1dGNIb3VycyA9IGRhdGUuZ2V0VVRDSG91cnMoKSwKICAgICAgICAg ICAgdXRjTWludXRlcyA9IGRhdGUuZ2V0VVRDTWludXRlcygpLAogICAgICAg ICAgICB1dGNTZWNvbmRzID0gZGF0ZS5nZXRVVENTZWNvbmRzKCk7CgoKICAg ICAgICB2YXIgZGF5T2ZXZWVrID0gZGF5c1t1dGNEYXldOwogICAgICAgIHZh ciBkYXlPZk1vbnRoID0gcGFkKHV0Y0RheU9mTW9udGgpOwogICAgICAg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XkpIHsK ICAgICAgaWYgKGNvdW50KysgPiBzZWxmLmF0dHJpYnV0ZUxpbWl0KSB7CiAg ICAgICAgcmV0dXJuIGZhbHNlOwogICAgICB9CiAgICAgIHZhciB2YWx1ZSA9 IGdldChyZWNvcmQsIGtleSk7CiAgICAgIGNvbHVtblZhbHVlc1trZXldID0g dmFsdWU7CiAgICB9KTsKICAgIHJldHVybiBjb2x1bW5WYWx1ZXM7CiAgfSwK CiAgZ2V0UmVjb3JkS2V5d29yZHM6IGZ1bmN0aW9uKHJlY29yZCkgewogICAg dmFyIGtleXdvcmRzID0gW10sIGtleXMgPSBFbWJlci5BKFsnaWQnXSk7CiAg ICByZWNvcmQuZWFjaEF0dHJpYnV0ZShmdW5jdGlvbihrZXkpIHsKICAgICAg a2V5cy5wdXNoKGtleSk7CiAgICB9KTsKICAgIGtleXMuZm9yRWFjaChmdW5j dGlvbihrZXkpIHsKICAgICAga2V5d29yZHMucHVzaChnZXQocmVjb3JkLCBr ZXkpKTsKICAgIH0pOwogICAgcmV0dXJuIGtleXdvcmRzOwogIH0sCgogIGdl dFJlY29yZEZpbHRlclZhbHVlczogZnVuY3Rpb24ocmVjb3JkKSB7CiAgICBy ZXR1cm4gewogICAgICBpc05ldzogcmVjb3JkLmdldCgnaXNOZXcnKSwKICAg ICAgaXNNb2RpZmllZDogcmVjb3JkLmdldCgnaXNEaXJ0eScpICYmICFyZWNv cmQuZ2V0KCdpc05ldycpLAogICAgICBpc0NsZWFuOiAhcmVjb3JkLmdldCgn aXNEaXJ0eScpCiAgICB9OwogIH0sCgogIGdldFJlY29yZENvbG9yOiBmdW5j dGlvbihyZWNvcmQpIHsKICAgIHZhciBjb2xvciA9ICdibGFjayc7CiAgICBp ZiAocmVjb3JkLmdldCgnaXNOZXcnKSkgewogICAgICBjb2xvciA9ICdncmVl bic7CiAgICB9IGVsc2UgaWYgKHJlY29yZC5nZXQoJ2lzRGlydHknKSkgewog ICAgICBjb2xvciA9ICdibHVlJzsKICAgIH0K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gIGZvciAodmFyIGk9aW5kZXg7IGk8aW5kZXgrcmVtb3ZlZDsgaSsr KSB7CiAgICAgICAgdmFyIHJlY29yZCA9IGdldCh0aGlzLCAnY29udGVudCcp Lm9iamVjdEF0KGkpOwoKICAgICAgICB2YXIgY2hhbmdlID0gRFMuUmVsYXRp b25zaGlwQ2hhbmdlLmNyZWF0ZUNoYW5nZShvd25lciwgcmVjb3JkLCBnZXQo dGhpcywgJ3N0b3JlJyksIHsKICAgICAgICAgIHBhcmVudFR5cGU6IG93bmVy LmNvbnN0cnVjdG9yLAogICAgICAgICAgY2hhbmdlVHlwZTogInJlbW92ZSIs CiAgICAgICAgICBraW5kOiAiaGFzTWFueSIsCiAgICAgICAgICBrZXk6IG5h bWUKICAgICAgICB9KTsKCiAgICAgICAgdGhpcy5fY2hhbmdlc1RvU3luYy5h ZGQoY2hhbmdlKTsKICAgICAgfQogICAgfQoKICAgIHJldHVybiB0aGlzLl9z dXBlci5hcHBseSh0aGlzLCBhcmd1bWVudHMpOwogIH0sCgogIGFycmF5Q29u dGVudERpZENoYW5nZTogZnVuY3Rpb24oaW5kZXgsIHJlbW92ZWQsIGFkZGVk KSB7CiAgICB0aGlzLl9zdXBlci5hcHBseSh0aGlzLCBhcmd1bWVudHMpOwoK ICAgIHZhciBvd25lciA9IGdldCh0aGlzLCAnb3duZXInKSwKICAgICAgICBu YW1lID0gZ2V0KHRoaXMsICduYW1lJyksCiAgICAgICAgc3RvcmUgPSBnZXQo dGhpcywgJ3N0b3JlJyk7CgogICAgaWYgKCFvd25lci5fc3VzcGVuZGVkUmVs YXRpb25zaGlwcykgewogICAgICAvLyBUaGlzIGNvZGUgaXMgdGhlIHNlY29u ZCBoYWxmIG9mIGNvZGUgdGhhdCBzdGFydGVkIGluCiAgICAgIC8vIGBhcnJh eUNvbnRlbnRXaWxsQ2hhbmdlYC4gSXQgZ2V0cyBvciBjcmVhdGVzIGEgY2hh bmdlCiAgICAgIC8vIGZyb20gdGhlIGNoaWxkIG9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JuOyB9CgogICAgLy9UT0RP KElnb3IpIFdoYXQgYWJvdXQgdGhlIG90aGVyIHNpZGUKICAgIHZhciBjaGFu Z2VzT2JqZWN0ID0gdGhpcy5fcmVsYXRpb25zaGlwQ2hhbmdlc1tyZWNvcmQu Y2xpZW50SWRdOwogICAgZm9yICh2YXIgb2JqS2V5IGluIGNoYW5nZXNPYmpl Y3QpewogICAgICBpZihjaGFuZ2VzT2JqZWN0Lmhhc093blByb3BlcnR5KG9i aktleSkpewogICAgICAgIGZvciAodmFyIGNoYW5nZUtleSBpbiBjaGFuZ2Vz T2JqZWN0W29iaktleV0pewogICAgICAgICAgaWYoY2hhbmdlc09iamVjdFtv YmpLZXldLmhhc093blByb3BlcnR5KGNoYW5nZUtleSkpewogICAgICAgICAg ICB0b1JldHVybi5wdXNoKGNoYW5nZXNPYmplY3Rbb2JqS2V5XVtjaGFuZ2VL ZXldKTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgIH0KICAgIH0KICAg IHJldHVybiB0b1JldHVybjsKICB9LAoKICAvLyAuLi4uLi4uLi4uLi4uLi4u Li4uLi4uCiAgLy8gLiBQRVItVFlQRSBBREFQVEVSUwogIC8vIC4uLi4uLi4u Li4uLi4uLi4uLi4uLi4KCiAgLyoqCiAgICBSZXR1cm5zIHRoZSBhZGFwdGVy IGZvciBhIGdpdmVuIHR5cGUuCgogICAgQG1ldGhvZCBhZGFwdGVyRm9yVHlw ZQogICAgQHByaXZhdGUKICAgIEBwYXJhbSB7c3ViY2xhc3Mgb2YgRFMuTW9k ZWx9IHR5cGUKICAgIEByZXR1cm5zIERTLkFkYXB0ZXIKICAqLwogIGFkYXB0 ZXJGb3JUeXBlOiBmdW5jdGlvbih0eXBlKSB7CiAgICB2YXIgY29udGFpbmVy ID0gdGhpcy5jb250YWluZXIsIGFkYXB0ZXI7CgogICAgaWYgKGNvbnRhaW5l cikgewogICAgICBhZGFwdGVyID0gY29udGFpbmVyLmxvb2t1cCgnYWRhcHRl cjonICsgd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yIHNlcmlhbGl6ZXIgPSBhZGFwdGVyLnNlcmlh bGl6ZXIsCiAgICAgIGRlZmF1bHRTZXJpYWxpemVyID0gYWRhcHRlci5kZWZh dWx0U2VyaWFsaXplciwKICAgICAgY29udGFpbmVyID0gYWRhcHRlci5jb250 YWluZXI7CgogIGlmIChjb250YWluZXIgJiYgc2VyaWFsaXplciA9PT0gdW5k ZWZpbmVkKSB7CiAgICBzZXJpYWxpemVyID0gY29udGFpbmVyLmxvb2t1cCgn c2VyaWFsaXplcjonK3R5cGUudHlwZUtleSkgfHwKICAgICAgICAgICAgICAg ICBjb250YWluZXIubG9va3VwKCdzZXJpYWxpemVyOmFwcGxpY2F0aW9uJykg fHwKICAgICAgICAgICAgICAgICBjb250YWluZXIubG9va3VwKCdzZXJpYWxp emVyOicgKyBkZWZhdWx0U2VyaWFsaXplciB8fCAnc2VyaWFsaXplcjpfZGVm YXVsdCcpOwogIH0KCiAgaWYgKHNlcmlhbGl6ZXIgPT09IG51bGwgfHwgc2Vy aWFsaXplciA9PT0gdW5kZWZpbmVkKSB7CiAgICBzZXJpYWxpemVyID0gewog ICAgICBleHRyYWN0OiBmdW5jdGlvbihzdG9yZSwgdHlwZSwgcGF5bG9hZCkg eyByZXR1cm4gcGF5bG9hZDsgfQogICAgfTsKICB9CgogIHJldHVybiBzZXJp YWxpemVyOwp9CgpmdW5jdGlvbiBfZmluZChhZGFwdGVyLCBzdG9yZSwgdHlw ZSwgaWQsIHJlc29sdmVyKSB7CiAgdmFyIHByb21pc2UgPSBhZGFwdGVyLmZp bmQoc3RvcmUsIHR5cGUsIGlkKSwKICAgICAgc2VyaWFsaXplciA9IHNlcmlh bGl6ZXJGb3IoYWRhcHRlciwgdHlwZSk7CgogIHJldHVybiByZXNvbHZlKHBy b21pc2UpLnRoZW4oZnVuY3Rpb24ocGF5bG9hZCkgewogICAgRW1iZXIuYXNz ZXJ0KCJZb3UgbWFkZSBhIHJlcXVlc3QgZm9yIGEgIiArIHR5cGUudHlwZ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AgICAgIH0KICAgICAgICB9 CgogICAgICAgIGlmIChpc0RpcnR5KSB7CiAgICAgICAgICByZWNvcmQuYWRh cHRlckRpZERpcnR5KCk7CiAgICAgICAgfQogICAgICB9LAoKICAgICAgLy8g RVZFTlRTCiAgICAgIGRpZFNldFByb3BlcnR5OiBkaWRTZXRQcm9wZXJ0eSwK CiAgICAgIHB1c2hlZERhdGE6IEVtYmVyLkssCgogICAgICBiZWNvbWVEaXJ0 eTogZnVuY3Rpb24ocmVjb3JkKSB7CiAgICAgICAgcmVjb3JkLnRyYW5zaXRp b25UbygndXBkYXRlZC51bmNvbW1pdHRlZCcpOwogICAgICB9LAoKICAgICAg d2lsbENvbW1pdDogZnVuY3Rpb24ocmVjb3JkKSB7CiAgICAgICAgcmVjb3Jk LnRyYW5zaXRpb25UbygndXBkYXRlZC5pbkZsaWdodCcpOwogICAgICB9LAoK ICAgICAgcmVsb2FkUmVjb3JkOiBmdW5jdGlvbihyZWNvcmQsIHJlc29sdmVy KSB7CiAgICAgICAgZ2V0KHJlY29yZCwgJ3N0b3JlJykucmVsb2FkUmVjb3Jk KHJlY29yZCwgcmVzb2x2ZXIpOwogICAgICB9LAoKICAgICAgZGVsZXRlUmVj b3JkOiBmdW5jdGlvbihyZWNvcmQpIHsKICAgICAgICByZWNvcmQudHJhbnNp dGlvblRvKCdkZWxldGVkLnVuY29tbWl0dGVkJyk7CiAgICAgICAgcmVjb3Jk LmNsZWFyUmVsYXRpb25zaGlwcygpOwogICAgICB9LAoKICAgICAgdW5sb2Fk UmVjb3JkOiBmdW5jdGlvbihyZWNvcmQpIHsKICAgICAgICAvLyBjbGVhciBy ZWxhdGlvbnNoaXBzIGJlZm9yZSBtb3ZpbmcgdG8gZGVsZXRlZCBzdGF0ZQog ICAgICAgIC8vIG90aGVyd2lzZSBpdCBmYWlscwogICAgICAgIHJlY29yZC5j bGVhclJlbGF0aW9uc2hpcHMoKTsKICAgICAgICByZWNvcmQudHJhbnNpdGlv blRvKCdkZWxldG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ICAgIGlmIChtZXRhLmlzUmVsYXRpb25zaGlwKSB7CiAgICAgICAg aWYgKHR5cGVvZiBtZXRhLnR5cGUgPT09ICdzdHJpbmcnKSB7CiAgICAgICAg ICBtZXRhLnR5cGUgPSBFbWJlci5nZXQoRW1iZXIubG9va3VwLCBtZXRhLnR5 cGUpOwogICAgICAgIH0KCiAgICAgICAgdmFyIHJlbGF0aW9uc2hpcHNGb3JU eXBlID0gbWFwLmdldChtZXRhLnR5cGUpOwoKICAgICAgICByZWxhdGlvbnNo aXBzRm9yVHlwZS5wdXNoKHsgbmFtZTogbmFtZSwga2luZDogbWV0YS5raW5k IH0pOwogICAgICB9CiAgICB9KTsKCiAgICByZXR1cm4gbWFwOwogIH0pLAoK ICAvKioKICAgIEEgaGFzaCBjb250YWluaW5nIGxpc3RzIG9mIHRoZSBtb2Rl bCdzIHJlbGF0aW9uc2hpcHMsIGdyb3VwZWQKICAgIGJ5IHRoZSByZWxhdGlv bnNoaXAga2luZC4gRm9yIGV4YW1wbGUsIGdpdmVuIGEgbW9kZWwgd2l0aCB0 aGlzCiAgICBkZWZpbml0aW9uOgoKICAgICAgICBBcHAuQmxvZyA9IERTLk1v ZGVsLmV4dGVuZCh7CiAgICAgICAgICB1c2VyczogRFMuaGFzTWFueShBcHAu VXNlciksCiAgICAgICAgICBvd25lcjogRFMuYmVsb25nc1RvKEFwcC5Vc2Vy KSwKCiAgICAgICAgICBwb3N0czogRFMuaGFzTWFueShBcHAuUG9zdCkKICAg ICAgICB9KTsKCiAgICBUaGlzIHByb3BlcnR5IHdvdWxkIGNvbnRhaW4gdGhl IGZvbGxvd2luZzoKCiAgICAgICB2YXIgcmVsYXRpb25zaGlwTmFtZXMgPSBF bWJlci5nZXQoQXBwLkJsb2csICdyZWxhdGlvbnNoaXBOYW1lcycpOwogICAg ICAgcmVsYXRpb25zaGlwTmFtZXMuaGFzTWFueTsKICAgICAgIC8vPT4gWyd1 c2VycycsICdwb3N0cyddCiAgICAgICByZWxhdGlvb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uVXNlciksCiAgICAgICAgICBv d25lcjogRFMuYmVsb25nc1RvKEFwcC5Vc2VyKSwKCiAgICAgICAgICBwb3N0 czogRFMuaGFzTWFueShBcHAuUG9zdCksCgogICAgICAgICAgdGl0bGU6IERT LmF0dHIoJ3N0cmluZycpCiAgICAgICAgfSk7CgogICAgICAgIHZhciBmaWVs ZHMgPSBFbWJlci5nZXQoQXBwLkJsb2csICdmaWVsZHMnKTsKICAgICAgICBm aWVsZHMuZm9yRWFjaChmdW5jdGlvbihmaWVsZCwga2luZCkgewogICAgICAg ICAgY29uc29sZS5sb2coZmllbGQsIGtpbmQpOwogICAgICAgIH0pOwoKICAg ICAgICAvLyBwcmludHM6CiAgICAgICAgLy8gdXNlcnMsIGhhc01hbnkKICAg ICAgICAvLyBvd25lciwgYmVsb25nc1RvCiAgICAgICAgLy8gcG9zdHMsIGhh c01hbnkKICAgICAgICAvLyB0aXRsZSwgYXR0cmlidXRlCgogICAgQHByb3Bl cnR5IGZpZWxkcwogICAgQHN0YXRpYwogICAgQHR5cGUgRW1iZXIuTWFwCiAg ICBAcmVhZE9ubHkKICAqLwogIGZpZWxkczogRW1iZXIuY29tcHV0ZWQoZnVu Y3Rpb24oKSB7CiAgICB2YXIgbWFwID0gRW1iZXIuTWFwLmNyZWF0ZSgpOwoK ICAgIHRoaXMuZWFjaENvbXB1dGVkUHJvcGVydHkoZnVuY3Rpb24obmFtZSwg bWV0YSkgewogICAgICBpZiAobWV0YS5pc1JlbGF0aW9uc2hpcCkgewogICAg ICAgIG1hcC5zZXQobmFtZSwgbWV0YS5raW5kKTsKICAgICAgfSBlbHNlIGlm IChtZXRhLmlzQXR0cmlidXRlKSB7CiAgICAgICAgbWFwLnNldChuYW1lLCAn YXR0cmlidXRlJyk7CiAgICAgIH0KICAgIH0pOwoKICAgIHJldHVybiBtYXA7 CiAgfSksCgogIC8qKgogICAgR2l2ZW4gYSBjYWxsYmFjaywgaXRlcmF0ZXMg b3ZlciBlYWNoIG9mIHRoZSBy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ICAgInRpdGxlIjogIlRoZSBQYXJsZXkgTGV0dGVyIgogICAg ICAgIH1dLAogICAgICAgICJjb21tZW50IjogW3sKICAgICAgICAgICJfaWQi OiAxLAogICAgICAgICAgImNvbW1lbnRfdGl0bGUiOiAiUmFpbHMgaXMgdW5h Z2kiCiAgICAgICAgICAicG9zdF9pZCI6IDEKICAgICAgICB9LCB7CiAgICAg ICAgICAiX2lkIjogMiwKICAgICAgICAgICJjb21tZW50X3RpdGxlIjogIkRv bid0IHRyZWFkIG9uIG1lIiwKICAgICAgICAgICJwb3N0X2lkIjogMgogICAg ICAgIH1dCiAgICAgIH0KICAgIH0KICAgIGBgYAoKICAgIFlvdSBjb3VsZCBp bXBsZW1lbnQgYSBzZXJpYWxpemVyIHRoYXQgbG9va3MgbGlrZSB0aGlzIHRv IGdldCB5b3VyIHBheWxvYWQKICAgIGludG8gc2hhcGU6CgogICAgYGBganMK ICAgIEFwcC5Qb3N0U2VyaWFsaXplciA9IERTLlJFU1RTZXJpYWxpemVyLmV4 dGVuZCh7CiAgICAgIC8vIEZpcnN0LCByZXN0cnVjdHVyZSB0aGUgdG9wLWxl dmVsIHNvIGl0J3Mgb3JnYW5pemVkIGJ5IHR5cGUKICAgICAgLy8gYW5kIHRo ZSBjb21tZW50cyBhcmUgbGlzdGVkIHVuZGVyIGEgcG9zdCdzIGBjb21tZW50 c2Aga2V5LgogICAgICBleHRyYWN0QXJyYXk6IGZ1bmN0aW9uKHN0b3JlLCB0 eXBlLCBwYXlsb2FkLCBpZCwgcmVxdWVzdFR5cGUpIHsKICAgICAgICB2YXIg cG9zdHMgPSBwYXlsb2FkLl9lbWJlZGRlZC5wb3N0OwogICAgICAgIHZhciBj b21tZW50cyA9IFtdOwogICAgICAgIHZhciBwb3N0Q2FjaGUgPSB7fTsKCiAg ICAgICAgcG9zdHMuZm9yRWFjaChmdW5jdGlvbihwb3N0KSB7CiAgICAgICAg ICBwb3N0LmNvbW1lbnRzID0gW107CiAgICAgICAgICBwb3N0Q2FjaGVbcG9z dC5pZF0gPSBwb3N0OwogICAgICAgIH0pOwoKICAgICAgICBwYXlsb2FkLl9l bWJlZGRlZC5jb21tZW50LmZvckVhY2goZnVuY3Rpb24oY29tbWVudCkgewog ICAgICAgICAgY29tbWVudHMucHVzaChjb21tZW50KTsKICAgICAgICAgIHBv c3RDYWNoZVtjb21tZW50LnBvc3RfaWRdLmNvbW1lbnRzLnB1c2goY29tbWVu dCk7CiAgICAgICAgICBkZWxldGUgY29tbWVudC5wb3N0X2lkOwogICAgICAg IH0KCiAgICAgICAgcGF5bG9hZCA9IHsgY29tbWVudHM6IGNvbW1lbnRzLCBw b3N0czogcGF5bG9hZCB9OwoKICAgICAgICByZXR1cm4gdGhpcy5fc3VwZXIo c3RvcmUsIHR5cGUsIHBheWxvYWQsIGlkLCByZXF1ZXN0VHlwZSk7CiAgICAg IH0sCgogICAgICBub3JtYWxpemVIYXNoOiB7CiAgICAgICAgLy8gTmV4dCwg bm9ybWFsaXplIGluZGl2aWR1YWwgY29tbWVudHMsIHdoaWNoIChhZnRlciBg ZXh0cmFjdGApCiAgICAgICAgLy8gYXJlIG5vdyBsb2NhdGVkIHVuZGVyIGBj b21tZW50c2AKICAgICAgICBjb21tZW50czogZnVuY3Rpb24oaGFzaCkgewog ICAgICAgICAgaGFzaC5pZCA9IGhhc2guX2lkOwogICAgICAgICAgaGFzaC50 aXRsZSA9IGhhc2guY29tbWVudF90aXRsZTsKICAgICAgICAgIGRlbGV0ZSBo YXNoLl9pZDsKICAgICAgICAgIGRlbGV0ZSBoYXNoLmNvbW1lbnRfdGl0bGU7 CiAgICAgICAgICByZXR1cm4gaGFzaDsKICAgICAgICB9CiAgICAgIH0KICAg IH0pCiAgICBgYGAKCiAgICBXaGVuIHlvdSBjYWxsIHN1cGVyIGZyb20geW91 ciBvd24gaW1wbGVtZW50YXRpb24gb2YgYGV4dHJhY3RBcnJheWAsIHRoZQog ICAgYnVpbHQtaW4gaW1wbGVtZW50YXRpb24gd2lsb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NUX0NNUzogcG9z dC5nZXQoJ2NvbW1lbnRzJykubWFwUHJvcGVydHkoJ2lkJykKICAgICAgICB9 CgogICAgICAgIGlmIChvcHRpb25zLmluY2x1ZGVJZCkgewogICAgICAgICAg anNvbi5QT1NUX0lEXyA9IHBvc3QuZ2V0KCdpZCcpOwogICAgICAgIH0KCiAg ICAgICAgcmV0dXJuIGpzb247CiAgICAgIH0KICAgIH0pOwogICAgYGBgCgog ICAgIyMgQ3VzdG9taXppbmcgYW4gQXBwLVdpZGUgU2VyaWFsaXplcgoKICAg IElmIHlvdSB3YW50IHRvIGRlZmluZSBhIHNlcmlhbGl6ZXIgZm9yIHlvdXIg ZW50aXJlCiAgICBhcHBsaWNhdGlvbiwgeW91J2xsIHByb2JhYmx5IHdhbnQg dG8gdXNlIGBlYWNoQXR0cmlidXRlYAogICAgYW5kIGBlYWNoUmVsYXRpb25z aGlwYCBvbiB0aGUgcmVjb3JkLgoKICAgIGBgYGpzCiAgICBBcHAuQXBwbGlj YXRpb25TZXJpYWxpemVyID0gRFMuUkVTVFNlcmlhbGl6ZXIuZXh0ZW5kKHsK ICAgICAgc2VyaWFsaXplOiBmdW5jdGlvbihyZWNvcmQsIG9wdGlvbnMpIHsK ICAgICAgICB2YXIganNvbiA9IHt9OwoKICAgICAgICByZWNvcmQuZWFjaEF0 dHJpYnV0ZShmdW5jdGlvbihuYW1lKSB7CiAgICAgICAgICBqc29uW3NlcnZl ckF0dHJpYnV0ZU5hbWUobmFtZSldID0gcmVjb3JkLmdldChuYW1lKTsKICAg ICAgICB9KQoKICAgICAgICByZWNvcmQuZWFjaFJlbGF0aW9uc2hpcChmdW5j dGlvbihuYW1lLCByZWxhdGlvbnNoaXApIHsKICAgICAgICAgIGlmIChyZWxh dGlvbnNoaXAua2luZCA9PT0gJ2hhc01hbnknKSB7CiAgICAgICAgICAgIGpz b25bc2VydmVySGFzTWFueU5hbWUobmFtZSldID0gcmVjb3JkLmdldChuYW1l KS5tYXBCeSgnaWQnKTs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HR5cGU7CiAgICAgIGhh c2guZGF0YVR5cGUgPSAnanNvbic7CiAgICAgIGhhc2guY29udGV4dCA9IGFk YXB0ZXI7CgogICAgICBpZiAoaGFzaC5kYXRhICYmIHR5cGUgIT09ICdHRVQn KSB7CiAgICAgICAgaGFzaC5jb250ZW50VHlwZSA9ICdhcHBsaWNhdGlvbi9q c29uOyBjaGFyc2V0PXV0Zi04JzsKICAgICAgICBoYXNoLmRhdGEgPSBKU09O LnN0cmluZ2lmeShoYXNoLmRhdGEpOwogICAgICB9CgogICAgICBpZiAoYWRh cHRlci5oZWFkZXJzICE9PSB1bmRlZmluZWQpIHsKICAgICAgICB2YXIgaGVh ZGVycyA9IGFkYXB0ZXIuaGVhZGVyczsKICAgICAgICBoYXNoLmJlZm9yZVNl bmQgPSBmdW5jdGlvbiAoeGhyKSB7CiAgICAgICAgICBFbWJlci5rZXlzKGhl YWRlcnMpLmZvckVhY2goZnVuY3Rpb24oa2V5KSB7CiAgICAgICAgICAgIHho ci5zZXRSZXF1ZXN0SGVhZGVyKGtleSwgaGVhZGVyc1trZXldKTsKICAgICAg ICAgIH0pOwogICAgICAgIH07CiAgICAgIH0KCiAgICAgIGhhc2guc3VjY2Vz cyA9IGZ1bmN0aW9uKGpzb24pIHsKICAgICAgICBFbWJlci5ydW4obnVsbCwg cmVzb2x2ZSwganNvbik7CiAgICAgIH07CgogICAgICBoYXNoLmVycm9yID0g ZnVuY3Rpb24oanFYSFIsIHRleHRTdGF0dXMsIGVycm9yVGhyb3duKSB7CiAg ICAgICAgaWYgKGpxWEhSKSB7CiAgICAgICAgICBqcVhIUi50aGVuID0gbnVs bDsKICAgICAgICB9CgogICAgICAgIEVtYmVyLnJ1bihudWxsLCByZWplY3Qs IGpxWEhSKTsKICAgICAgfTsKCiAgICAgIEVtYmVyLiQuYWpheChoYXNoKTsK ICAgIH0pOwogIH0KCn0pOwoKfSkoKTsKCgoKKGZ1bmN0aW9uKCkgewovKioK ICBAbW9kdWxlIGVtYmVyL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9GIEFOWSBLSU5ELCBFWFBSRVNTIE9S Ci8vSU1QTElFRCwgSU5DTFVESU5HIEJVVCBOT1QgTElNSVRFRCBUTyBUSEUg V0FSUkFOVElFUyBPRiBNRVJDSEFOVEFCSUxJVFksCi8vRklUTkVTUyBGT1Ig QSBQQVJUSUNVTEFSIFBVUlBPU0UgQU5EIE5PTklORlJJTkdFTUVOVC4gSU4g Tk8gRVZFTlQgU0hBTEwgVEhFCi8vQVVUSE9SUyBPUiBDT1BZUklHSFQgSE9M REVSUyBCRSBMSUFCTEUgRk9SIEFOWSBDTEFJTSwgREFNQUdFUyBPUiBPVEhF UgovL0xJQUJJTElUWSwgV0hFVEhFUiBJTiBBTiBBQ1RJT04gT0YgQ09OVFJB Q1QsIFRPUlQgT1IgT1RIRVJXSVNFLCBBUklTSU5HIEZST00sCi8vT1VUIE9G IE9SIElOIENPTk5FQ1RJT04gV0lUSCBUSEUgU09GVFdBUkUgT1IgVEhFIFVT RSBPUiBPVEhFUiBERUFMSU5HUyBJTiBUSEUKLy9TT0ZUV0FSRS4KCi8qKgog IEVtYmVyIERhdGEKCiAgQG1vZHVsZSBlbWJlci1kYXRhCiAgQG1haW4gZW1i ZXItZGF0YQoqLwoKfSkoKTsKCg== http_version: recorded_at: Mon, 17 Feb 2014 11:45:23 GMT - request: method: get uri: http://builds.emberjs.com/tags/v1.0.0-beta.1/ember-data.min.js body: encoding: US-ASCII string: '' headers: Accept-Encoding: - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 Accept: - '*/*' User-Agent: - Ruby Host: - builds.emberjs.com response: status: code: 200 message: OK headers: X-Amz-Id-2: - dhcnXvFIaQzLDo1KXXC8kCGb0g8og6oYgO2pDcEXbFsVndVrIG/qtA9qu9PbSbEe X-Amz-Request-Id: - DE1DE9B79D7D5B2D Date: - Mon, 17 Feb 2014 11:45:25 GMT Last-Modified: - Sun, 01 Sep 2013 07:45:27 GMT Etag: - '"7066a174c8ef121fbcc734c19087d271"' Content-Type: - text/javascript Content-Length: - '4008' Server: - AmazonS3 body: encoding: ASCII-8BIT string: !binary |- Ly8gPT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09 PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT0KLy8gUHJvamVjdDog ICBFbWJlciBEYXRhCi8vIENvcHlyaWdodDogwqkyMDExLTIwMTIgVGlsZGUg SW5jLiBhbmQgY29udHJpYnV0b3JzLgovLyAgICAgICAgICAgIFBvcnRpb25z IMKpMjAxMSBMaXZpbmcgU29jaWFsIEluYy4gYW5kIGNvbnRyaWJ1dG9ycy4K Ly8gTGljZW5zZTogICBMaWNlbnNlZCB1bmRlciBNSVQgbGljZW5zZSAoc2Vl IGxpY2Vuc2UuanMpCi8vID09PT09PT09PT09PT09PT09PT09PT09PT09PT09 PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09 CgoKCi8vIFZlcnNpb246IHYxLjAuMC1iZXRhLjEKLy8gTGFzdCBjb21taXQ6 IGNhZmFiOWQgKDIwMTMtMDktMDEgMDA6NDI6MzkgLTA3MDApCgoKIWZ1bmN0 aW9uKCl7dmFyIGUsaTshZnVuY3Rpb24oKXt2YXIgcj17fSxzPXt9O2U9ZnVu Y3Rpb24oZSxpLHMpe3JbZV09e2RlcHM6aSxjYWxsYmFjazpzfX0saT1mdW5j dGlvbihlKXtpZihzW2VdKXJldHVybiBzW2VdO3NbZV09e307dmFyIG4sdCx1 LG8sYTtpZihuPXJbZV0sIW4pdGhyb3cgbmV3IEVycm9yKCJNb2R1bGUgJyIr ZSsiJyBub3QgZm91bmQuIik7dD1uLmRlcHMsdT1uLmNhbGxiYWNrLG89W107 Zm9yKHZhciBsPTAsJD10Lmxlbmd0aDskPmw7bCsrKSJleHBvcnRzIj09PXRb bF0/by5wdXNoKGE9e30pOm8ucHVzaChpKHRbbF0pKTt2YXIgYz11LmFwcGx5 KHRoaXMsbyk7cmV0dXJuIHNbZV09YXx8Y319KCksZnVuY3Rpb24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