ende 0.2.9 → 0.2.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/assets/javascripts/aura/extensions/devise.js.coffee +2 -2
- data/lib/assets/javascripts/widgets/viewer/main.js.coffee +1 -1
- data/lib/ende/version.rb +1 -1
- data/vendor/assets/components/build.js +638 -133
- data/vendor/components/indefinido-indemma/.gitignore +14 -0
- data/vendor/components/indefinido-indemma/.gitignore~ +2 -0
- data/vendor/components/indefinido-indemma/.ruby-gemset +1 -0
- data/vendor/components/indefinido-indemma/.ruby-version +1 -0
- data/vendor/components/indefinido-indemma/Gemfile +13 -0
- data/vendor/components/indefinido-indemma/Guardfile +39 -0
- data/vendor/components/indefinido-indemma/History.md +0 -0
- data/vendor/components/indefinido-indemma/Readme.md +447 -0
- data/vendor/components/indefinido-indemma/build/development.js +340 -0
- data/vendor/components/indefinido-indemma/build/release.js +22039 -0
- data/vendor/components/indefinido-indemma/build/test.js +22039 -0
- data/vendor/components/indefinido-indemma/component.json +7 -3
- data/vendor/components/indefinido-indemma/components/chaijs-assertion-error/component.json +18 -0
- data/vendor/components/indefinido-indemma/components/chaijs-assertion-error/index.js +110 -0
- data/vendor/components/indefinido-indemma/components/chaijs-chai/component.json +47 -0
- data/vendor/components/indefinido-indemma/components/chaijs-chai/index.js +1 -0
- data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/assertion.js +130 -0
- data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/core/assertions.js +1270 -0
- data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/interface/assert.js +1080 -0
- data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/interface/expect.js +12 -0
- data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/interface/should.js +76 -0
- data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/addChainableMethod.js +94 -0
- data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/addMethod.js +37 -0
- data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/addProperty.js +40 -0
- data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/eql.js +129 -0
- data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/flag.js +32 -0
- data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/getActual.js +19 -0
- data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/getEnumerableProperties.js +25 -0
- data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/getMessage.js +49 -0
- data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/getName.js +20 -0
- data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/getPathValue.js +102 -0
- data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/getProperties.js +35 -0
- data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/index.js +108 -0
- data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/inspect.js +320 -0
- data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/objDisplay.js +48 -0
- data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/overwriteMethod.js +51 -0
- data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/overwriteProperty.js +54 -0
- data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/test.js +26 -0
- data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/transferFlags.js +44 -0
- data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/type.js +45 -0
- data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai.js +80 -0
- data/vendor/components/indefinido-indemma/components/component-bind/component.json +14 -0
- data/vendor/components/indefinido-indemma/components/component-bind/index.js +24 -0
- data/vendor/components/indefinido-indemma/components/component-jquery/component.json +14 -0
- data/vendor/components/indefinido-indemma/components/component-jquery/index.js +9601 -0
- data/vendor/components/indefinido-indemma/components/component-type/component.json +18 -0
- data/vendor/components/indefinido-indemma/components/component-type/index.js +32 -0
- data/vendor/components/indefinido-indemma/components/indefinido-advisable/component.json +21 -0
- data/vendor/components/indefinido-indemma/components/indefinido-advisable/index.js +1 -0
- data/vendor/components/indefinido-indemma/components/indefinido-advisable/lib/advisable.js +60 -0
- data/vendor/components/indefinido-indemma/components/indefinido-observable/component.json +25 -0
- data/vendor/components/indefinido-indemma/components/indefinido-observable/components/cjohansen-sinon/sinon.js +4290 -0
- data/vendor/components/indefinido-indemma/components/indefinido-observable/index.js +1 -0
- data/vendor/components/indefinido-indemma/components/indefinido-observable/lib/adapters/rivets.js +26 -0
- data/vendor/components/indefinido-indemma/components/indefinido-observable/lib/observable.js +323 -0
- data/vendor/components/indefinido-indemma/components/indefinido-observable/vendor/shims/accessors-legacy.js +92 -0
- data/vendor/components/indefinido-indemma/components/indefinido-observable/vendor/shims/accessors.js +173 -0
- data/vendor/components/indefinido-indemma/components/indefinido-observable/vendor/shims/array.indexOf.js +8 -0
- data/vendor/components/indefinido-indemma/components/indefinido-observable/vendor/shims/object.create.js +77 -0
- data/vendor/components/indefinido-indemma/components/kapit-observe-utils/component.json +13 -0
- data/vendor/components/indefinido-indemma/components/paulmillr-es6-shim/component.json +17 -0
- data/vendor/components/indefinido-indemma/components/paulmillr-es6-shim/es6-shim.js +996 -0
- data/vendor/components/indefinido-indemma/components/pluma-assimilate/component.json +25 -0
- data/vendor/components/indefinido-indemma/components/pluma-assimilate/dist/assimilate.js +127 -0
- data/vendor/components/indefinido-indemma/karma.conf.js +86 -0
- data/vendor/components/indefinido-indemma/lib/record/associable.js +229 -82
- data/vendor/components/indefinido-indemma/lib/record/errors.js +1 -0
- data/vendor/components/indefinido-indemma/lib/record/persistable.js +32 -0
- data/vendor/components/indefinido-indemma/lib/record/queryable.js +32 -0
- data/vendor/components/indefinido-indemma/lib/record/resource.js +12 -4
- data/vendor/components/indefinido-indemma/lib/record/rest.js +1 -1
- data/vendor/components/indefinido-indemma/lib/record/restfulable.js +38 -27
- data/vendor/components/indefinido-indemma/lib/record/scopable.js +15 -2
- data/vendor/components/indefinido-indemma/lib/record/storable.js +48 -0
- data/vendor/components/indefinido-indemma/lib/record/validatable.js +10 -5
- data/vendor/components/indefinido-indemma/lib/record/validations/cpf.js +1 -1
- data/vendor/components/indefinido-indemma/lib/record.js +15 -12
- data/vendor/components/indefinido-indemma/spec/record/associable_spec.js +137 -0
- data/vendor/components/indefinido-indemma/spec/record/persistable_spec.js +36 -0
- data/vendor/components/indefinido-indemma/spec/record/queryable_spec.js +33 -0
- data/vendor/components/indefinido-indemma/spec/record/resource_spec.js +93 -0
- data/vendor/components/indefinido-indemma/spec/record/rest_spec.js +32 -0
- data/vendor/components/indefinido-indemma/spec/record/restfulable_spec.js +288 -0
- data/vendor/components/indefinido-indemma/spec/record/scopable_spec.js +212 -0
- data/vendor/components/indefinido-indemma/spec/record/storable_spec.js +53 -0
- data/vendor/components/indefinido-indemma/spec/record/translationable.js +28 -0
- data/vendor/components/indefinido-indemma/spec/record/validatable_spec.js +111 -0
- data/vendor/components/indefinido-indemma/spec/record/validations/associated_spec.js +43 -0
- data/vendor/components/indefinido-indemma/spec/record/validations/confirmation_spec.js +36 -0
- data/vendor/components/indefinido-indemma/spec/record/validations/cpf_spec.js +35 -0
- data/vendor/components/indefinido-indemma/spec/record/validations/presence_spec.js +28 -0
- data/vendor/components/indefinido-indemma/spec/record/validations/remote_spec.js +87 -0
- data/vendor/components/indefinido-indemma/spec/record/validations/type_spec.js +48 -0
- data/vendor/components/indefinido-indemma/spec/record_spec.js +37 -0
- data/vendor/components/indefinido-indemma/spec/spec_helper.js +11 -0
- data/vendor/components/indefinido-indemma/spec/support/value_objects/phone.js +45 -0
- data/vendor/components/indefinido-indemma/src/lib/extensions/rivets.coffee +17 -0
- data/vendor/components/indefinido-indemma/src/lib/record/associable.coffee +342 -0
- data/vendor/components/indefinido-indemma/src/lib/record/errors.coffee +20 -0
- data/vendor/components/indefinido-indemma/src/lib/record/maid.coffee +16 -0
- data/vendor/components/indefinido-indemma/src/lib/record/persistable.coffee +27 -0
- data/vendor/components/indefinido-indemma/src/lib/record/queryable.coffee +29 -0
- data/vendor/components/indefinido-indemma/src/lib/record/resource.coffee +106 -0
- data/vendor/components/indefinido-indemma/src/lib/record/rest.coffee +28 -0
- data/vendor/components/indefinido-indemma/src/lib/record/restfulable.coffee +348 -0
- data/vendor/components/indefinido-indemma/src/lib/record/scopable.coffee +275 -0
- data/vendor/components/indefinido-indemma/src/lib/record/storable.coffee +46 -0
- data/vendor/components/indefinido-indemma/src/lib/record/translationable.coffee +18 -0
- data/vendor/components/indefinido-indemma/src/lib/record/validatable.coffee +217 -0
- data/vendor/components/indefinido-indemma/src/lib/record/validations/associated.coffee +32 -0
- data/vendor/components/indefinido-indemma/src/lib/record/validations/confirmation.coffee +19 -0
- data/vendor/components/indefinido-indemma/src/lib/record/validations/cpf.coffee +58 -0
- data/vendor/components/indefinido-indemma/src/lib/record/validations/presence.coffee +19 -0
- data/vendor/components/indefinido-indemma/src/lib/record/validations/remote.coffee +65 -0
- data/vendor/components/indefinido-indemma/src/lib/record/validations/type.coffee +32 -0
- data/vendor/components/indefinido-indemma/src/lib/record.coffee +136 -0
- data/vendor/components/indefinido-indemma/src/spec/record/associable_spec.coffee +130 -0
- data/vendor/components/indefinido-indemma/src/spec/record/persistable_spec.coffee +30 -0
- data/vendor/components/indefinido-indemma/src/spec/record/queryable_spec.coffee +27 -0
- data/vendor/components/indefinido-indemma/src/spec/record/resource_spec.coffee +69 -0
- data/vendor/components/indefinido-indemma/src/spec/record/rest_spec.coffee +22 -0
- data/vendor/components/indefinido-indemma/src/spec/record/restfulable_spec.coffee +207 -0
- data/vendor/components/indefinido-indemma/src/spec/record/scopable_spec.coffee +191 -0
- data/vendor/components/indefinido-indemma/src/spec/record/storable_spec.coffee +40 -0
- data/vendor/components/indefinido-indemma/src/spec/record/translationable.coffee +19 -0
- data/vendor/components/indefinido-indemma/src/spec/record/validatable_spec.coffee +100 -0
- data/vendor/components/indefinido-indemma/src/spec/record/validations/associated_spec.coffee +35 -0
- data/vendor/components/indefinido-indemma/src/spec/record/validations/confirmation_spec.coffee +25 -0
- data/vendor/components/indefinido-indemma/src/spec/record/validations/cpf_spec.coffee +28 -0
- data/vendor/components/indefinido-indemma/src/spec/record/validations/presence_spec.coffee +24 -0
- data/vendor/components/indefinido-indemma/src/spec/record/validations/remote_spec.coffee +74 -0
- data/vendor/components/indefinido-indemma/src/spec/record/validations/type_spec.coffee +33 -0
- data/vendor/components/indefinido-indemma/src/spec/record_spec.coffee +23 -0
- data/vendor/components/indefinido-indemma/src/spec/spec_helper.coffee +9 -0
- data/vendor/components/indefinido-indemma/src/spec/support/value_objects/phone.coffee +30 -0
- data/vendor/components/indefinido-indemma/vendor/object/mixin.js +196 -0
- data/vendor/components/indefinido-indemma/vendor/owl/pluralize.js +190 -0
- metadata +130 -2
@@ -0,0 +1,25 @@
|
|
1
|
+
{
|
2
|
+
"name": "assimilate",
|
3
|
+
"version": "0.3.0",
|
4
|
+
"license": "MIT",
|
5
|
+
"repo": "pluma/assimilate",
|
6
|
+
"description": "Extends objects.",
|
7
|
+
"keywords": [
|
8
|
+
"extend",
|
9
|
+
"inherit",
|
10
|
+
"mixin"
|
11
|
+
],
|
12
|
+
"main": "./dist/assimilate.js",
|
13
|
+
"dependencies": {},
|
14
|
+
"development": {},
|
15
|
+
"scripts": [
|
16
|
+
"dist/assimilate.js"
|
17
|
+
],
|
18
|
+
"styles": [],
|
19
|
+
"ignore": [
|
20
|
+
"**/.*",
|
21
|
+
"build",
|
22
|
+
"components",
|
23
|
+
"node_modules"
|
24
|
+
]
|
25
|
+
}
|
@@ -0,0 +1,127 @@
|
|
1
|
+
/*! assimilate 0.3.0 Copyright (c) 2013 Alan Plum. MIT licensed. */
|
2
|
+
var slice = Array.prototype.slice;
|
3
|
+
|
4
|
+
function bind(fn, self) {
|
5
|
+
var args = slice.call(arguments, 2);
|
6
|
+
if (typeof Function.prototype.bind === 'function') {
|
7
|
+
return Function.prototype.bind.apply(fn, [self].concat(args));
|
8
|
+
}
|
9
|
+
return function() {
|
10
|
+
return fn.apply(self, args.concat(slice.call(arguments, 0)));
|
11
|
+
};
|
12
|
+
}
|
13
|
+
|
14
|
+
function simpleCopy(target, name, source) {
|
15
|
+
target[name] = source[name];
|
16
|
+
}
|
17
|
+
|
18
|
+
function properCopy(target, name, source) {
|
19
|
+
var descriptor = Object.getOwnPropertyDescriptor(source, name);
|
20
|
+
Object.defineProperty(target, name, descriptor);
|
21
|
+
}
|
22
|
+
|
23
|
+
function ownProperties(obj) {
|
24
|
+
return Object.getOwnPropertyNames(obj);
|
25
|
+
}
|
26
|
+
|
27
|
+
function allKeys(obj) {
|
28
|
+
var keys = [];
|
29
|
+
for (var name in obj) {
|
30
|
+
keys.push(name);
|
31
|
+
}
|
32
|
+
return keys;
|
33
|
+
}
|
34
|
+
|
35
|
+
function ownKeys(obj) {
|
36
|
+
var keys = [];
|
37
|
+
for (var name in obj) {
|
38
|
+
if (obj.hasOwnProperty(name)) {
|
39
|
+
keys.push(name);
|
40
|
+
}
|
41
|
+
}
|
42
|
+
return keys;
|
43
|
+
}
|
44
|
+
|
45
|
+
function assimilateWithStrategy(target) {
|
46
|
+
var strategy = this,
|
47
|
+
sources = slice.call(arguments, 1),
|
48
|
+
i, source, names, j, name;
|
49
|
+
|
50
|
+
if (target === undefined || target === null) {
|
51
|
+
target = {};
|
52
|
+
}
|
53
|
+
|
54
|
+
for (i = 0; i < sources.length; i++) {
|
55
|
+
source = sources[i];
|
56
|
+
names = strategy.keysFn(source);
|
57
|
+
for (j = 0; j < names.length; j++) {
|
58
|
+
name = names[j];
|
59
|
+
strategy.copyFn(target, name, source);
|
60
|
+
}
|
61
|
+
}
|
62
|
+
|
63
|
+
return target;
|
64
|
+
}
|
65
|
+
|
66
|
+
var strategies = {
|
67
|
+
DEFAULT: {
|
68
|
+
keysFn: ownKeys,
|
69
|
+
copyFn: simpleCopy
|
70
|
+
},
|
71
|
+
PROPER: {
|
72
|
+
keysFn: ownProperties,
|
73
|
+
copyFn: properCopy
|
74
|
+
},
|
75
|
+
INHERITED: {
|
76
|
+
keysFn: allKeys,
|
77
|
+
copyFn: simpleCopy
|
78
|
+
},
|
79
|
+
DEEP: {
|
80
|
+
keysFn: ownKeys,
|
81
|
+
copyFn: function recursiveCopy(target, name, source) {
|
82
|
+
var val = source[name];
|
83
|
+
var old = target[name];
|
84
|
+
if (typeof val === 'object' && typeof old === 'object') {
|
85
|
+
assimilateWithStrategy.call(strategies.DEEP, old, val);
|
86
|
+
} else {
|
87
|
+
simpleCopy(target, name, source);
|
88
|
+
}
|
89
|
+
}
|
90
|
+
},
|
91
|
+
STRICT: {
|
92
|
+
keysFn: ownKeys,
|
93
|
+
copyFn: function strictCopy(target, name, source) {
|
94
|
+
if (source[name] !== undefined) {
|
95
|
+
simpleCopy(target, name, source);
|
96
|
+
}
|
97
|
+
}
|
98
|
+
},
|
99
|
+
FALLBACK: {
|
100
|
+
keysFn: function fallbackCopy(target, name, source) {
|
101
|
+
if (target[name] === undefined) {
|
102
|
+
simpleCopy(target, name, source);
|
103
|
+
}
|
104
|
+
},
|
105
|
+
copyFn: simpleCopy
|
106
|
+
}
|
107
|
+
};
|
108
|
+
|
109
|
+
var assimilate = bind(assimilateWithStrategy, strategies.DEFAULT);
|
110
|
+
assimilate.strategies = strategies;
|
111
|
+
assimilate.withStrategy = function withStrategy(strategy) {
|
112
|
+
if (typeof strategy === 'string') {
|
113
|
+
strategy = strategies[strategy.toUpperCase()];
|
114
|
+
}
|
115
|
+
if (!strategy) {
|
116
|
+
throw new Error('Unknwon or invalid strategy:' + strategy);
|
117
|
+
}
|
118
|
+
if (typeof strategy.copyFn !== 'function') {
|
119
|
+
throw new Error('Strategy missing copy function:' + strategy);
|
120
|
+
}
|
121
|
+
if (typeof strategy.keysFn !== 'function') {
|
122
|
+
throw new Error('Strategy missing keys function:' + strategy);
|
123
|
+
}
|
124
|
+
return bind(assimilateWithStrategy, strategy);
|
125
|
+
};
|
126
|
+
|
127
|
+
module.exports = assimilate;
|
@@ -0,0 +1,86 @@
|
|
1
|
+
// Karma configuration
|
2
|
+
// Generated on Mon May 27 2013 16:00:28 GMT-0300 (BRT)
|
3
|
+
|
4
|
+
|
5
|
+
// base path, that will be used to resolve files and exclude
|
6
|
+
basePath = '';
|
7
|
+
|
8
|
+
// list of files / patterns to load in the browser
|
9
|
+
files = [
|
10
|
+
|
11
|
+
// Test environment
|
12
|
+
MOCHA,
|
13
|
+
MOCHA_ADAPTER,
|
14
|
+
'vendor/sinon.js',
|
15
|
+
|
16
|
+
// Test dependencies
|
17
|
+
'build/test.js',
|
18
|
+
'spec/support/**/*.js',
|
19
|
+
|
20
|
+
// Test Source files
|
21
|
+
'spec/spec_helper.js',
|
22
|
+
'spec/**/*.js'
|
23
|
+
];
|
24
|
+
|
25
|
+
|
26
|
+
// list of files to exclude
|
27
|
+
exclude = [
|
28
|
+
'spec/coverage'
|
29
|
+
];
|
30
|
+
|
31
|
+
|
32
|
+
// test results reporter to use
|
33
|
+
// possible values: 'dots', 'progress', 'junit'
|
34
|
+
reporters = ['progress', 'coverage'];
|
35
|
+
|
36
|
+
|
37
|
+
// web server port
|
38
|
+
port = 9876;
|
39
|
+
|
40
|
+
|
41
|
+
// cli runner port
|
42
|
+
runnerPort = 9100;
|
43
|
+
|
44
|
+
|
45
|
+
// enable / disable colors in the output (reporters and logs)
|
46
|
+
colors = true;
|
47
|
+
|
48
|
+
|
49
|
+
// level of logging
|
50
|
+
// possible values: LOG_DISABLE || LOG_ERROR || LOG_WARN || LOG_INFO || LOG_DEBUG
|
51
|
+
logLevel = LOG_INFO;
|
52
|
+
|
53
|
+
|
54
|
+
// enable / disable watching file and executing tests whenever any file changes
|
55
|
+
autoWatch = true;
|
56
|
+
|
57
|
+
|
58
|
+
// Start these browsers, currently available:
|
59
|
+
// - Chrome
|
60
|
+
// - ChromeCanary
|
61
|
+
// - Firefox
|
62
|
+
// - Opera
|
63
|
+
// - Safari (only Mac)
|
64
|
+
// - PhantomJS
|
65
|
+
// - IE (only Windows)
|
66
|
+
browsers = ['Chrome'];
|
67
|
+
|
68
|
+
|
69
|
+
// If browser does not capture in given timeout [ms], kill it
|
70
|
+
captureTimeout = 600000;
|
71
|
+
|
72
|
+
|
73
|
+
// Continuous Integration mode
|
74
|
+
// if true, it capture browsers, run tests and exit
|
75
|
+
singleRun = false;
|
76
|
+
|
77
|
+
// Coverage preprocessors
|
78
|
+
preprocessors = {
|
79
|
+
'**/lib/*.js': 'coverage'
|
80
|
+
};
|
81
|
+
|
82
|
+
// Converage configuration
|
83
|
+
coverageReporter = {
|
84
|
+
type : 'html',
|
85
|
+
dir : 'spec/coverage'
|
86
|
+
}
|
@@ -1,10 +1,12 @@
|
|
1
|
-
var $, associable, model, plural, root, singular,
|
1
|
+
var $, associable, callbacks, extend, model, modifiers, plural, root, singular, subscribers,
|
2
2
|
__slice = [].slice;
|
3
3
|
|
4
4
|
root = window;
|
5
5
|
|
6
6
|
$ = require('jquery');
|
7
7
|
|
8
|
+
extend = require('assimilate');
|
9
|
+
|
8
10
|
require('./resource');
|
9
11
|
|
10
12
|
plural = {
|
@@ -48,7 +50,10 @@ plural = {
|
|
48
50
|
data[_name = this.parent_resource] || (data[_name] = this.parent);
|
49
51
|
return model[model.singularize(this.resource)](data);
|
50
52
|
},
|
51
|
-
push:
|
53
|
+
push: function() {
|
54
|
+
console.warn("" + this.resource + ".push is deprecated and will be removed, please use add instead");
|
55
|
+
return Array.prototype.push.apply(this, arguments);
|
56
|
+
},
|
52
57
|
length: 0,
|
53
58
|
json: function(methods, omissions) {
|
54
59
|
var record, _i, _len, _results;
|
@@ -64,92 +69,192 @@ plural = {
|
|
64
69
|
|
65
70
|
singular = {
|
66
71
|
create: function(data) {
|
67
|
-
return model[this.resource].create(
|
72
|
+
return model[this.resource].create(extend({}, this, data));
|
68
73
|
},
|
69
74
|
build: function(data) {
|
70
|
-
return this
|
75
|
+
return this.owner[this.resource.toString()] = model[this.resource.toString()](extend({}, this, data));
|
71
76
|
}
|
72
77
|
};
|
73
78
|
|
74
|
-
|
75
|
-
|
76
|
-
|
79
|
+
subscribers = {
|
80
|
+
belongs_to: {
|
81
|
+
foreign_key: function(resource_id) {
|
82
|
+
var associated, association_name, current_resource_id, resource, _ref;
|
77
83
|
|
78
|
-
|
79
|
-
|
84
|
+
association_name = this.resource.toString();
|
85
|
+
if (resource_id === null || resource_id === void 0) {
|
86
|
+
this.dirty = true;
|
87
|
+
this.owner[association_name] = resource_id;
|
88
|
+
return resource_id;
|
89
|
+
}
|
90
|
+
current_resource_id = (_ref = this.owner[association_name]) != null ? _ref._id : void 0;
|
91
|
+
if (resource_id !== current_resource_id) {
|
92
|
+
resource = model[association_name];
|
93
|
+
if (!resource) {
|
94
|
+
console.warn("subscribers.belongs_to.foreign_key: associated factory not found for model: " + association_name);
|
95
|
+
return resource_id;
|
96
|
+
}
|
97
|
+
associated = resource.find(resource_id);
|
98
|
+
associated || (associated = resource({
|
99
|
+
_id: resource_id
|
100
|
+
}));
|
101
|
+
this.owner.observed[association_name] = associated;
|
102
|
+
}
|
103
|
+
return resource_id;
|
104
|
+
},
|
105
|
+
associated_changed: function(associated) {
|
106
|
+
return this.owner.observed["" + (this.resource.toString()) + "_id"] = associated ? associated._id : null;
|
80
107
|
}
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
}
|
106
|
-
return _results;
|
108
|
+
}
|
109
|
+
};
|
110
|
+
|
111
|
+
modifiers = {
|
112
|
+
belongs_to: {
|
113
|
+
associated_loader: function() {
|
114
|
+
var association_name,
|
115
|
+
_this = this;
|
116
|
+
|
117
|
+
association_name = this.resource.toString();
|
118
|
+
return Object.defineProperty(this.owner, association_name, {
|
119
|
+
set: function(associated) {
|
120
|
+
return this.observed[association_name] = associated;
|
121
|
+
},
|
122
|
+
get: function() {
|
123
|
+
var associated, associated_id, resource;
|
124
|
+
|
125
|
+
associated = _this.owner.observed[association_name];
|
126
|
+
associated_id = _this.owner.observed[association_name + '_id'];
|
127
|
+
if (!(((associated != null ? associated._id : void 0) != null) || associated_id)) {
|
128
|
+
return associated;
|
129
|
+
}
|
130
|
+
if (associated != null ? associated.sustained : void 0) {
|
131
|
+
return associated;
|
107
132
|
}
|
133
|
+
resource = model[association_name];
|
134
|
+
if (!resource) {
|
135
|
+
console.warn("subscribers.belongs_to.foreign_key: associated factory not found for model: " + association_name);
|
136
|
+
return associated;
|
137
|
+
}
|
138
|
+
associated = resource.find(associated_id || associated._id);
|
139
|
+
associated || (associated = resource({
|
140
|
+
_id: associated_id
|
141
|
+
}));
|
142
|
+
resource.storage.store(associated._id, associated);
|
143
|
+
associated.reload();
|
144
|
+
return _this.owner.observed[association_name] = associated;
|
108
145
|
},
|
109
|
-
|
110
|
-
|
146
|
+
configurable: true,
|
147
|
+
enumerable: true
|
148
|
+
});
|
149
|
+
}
|
150
|
+
}
|
151
|
+
};
|
111
152
|
|
112
|
-
|
113
|
-
|
114
|
-
|
153
|
+
callbacks = {
|
154
|
+
has_many: {
|
155
|
+
nest_attributes: function() {
|
156
|
+
var association, association_name, association_names, associations_attributes, message, _i, _len, _results;
|
157
|
+
|
158
|
+
association_names = model[this.resource].has_many;
|
159
|
+
if (association_names) {
|
160
|
+
_results = [];
|
161
|
+
for (_i = 0, _len = association_names.length; _i < _len; _i++) {
|
162
|
+
association_name = association_names[_i];
|
163
|
+
associations_attributes = this["" + association_name + "_attributes"];
|
164
|
+
if (associations_attributes && associations_attributes.length) {
|
165
|
+
association = this[model.pluralize(association_name)];
|
166
|
+
if (!association) {
|
167
|
+
message = "has_many.nest_attributes: Association not found for " + association_name + ". \n";
|
168
|
+
message += "did you set it on model declaration? \n has_many: " + association_name + " ";
|
169
|
+
throw message;
|
170
|
+
}
|
171
|
+
association.resource = model.singularize(association.resource);
|
172
|
+
association.add.apply(association, associations_attributes);
|
173
|
+
_results.push(association.resource = model.pluralize(association.resource));
|
174
|
+
} else {
|
175
|
+
_results.push(void 0);
|
115
176
|
}
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
177
|
+
}
|
178
|
+
return _results;
|
179
|
+
}
|
180
|
+
},
|
181
|
+
update_association: function(data) {
|
182
|
+
var associated, association, association_name, id, pluralized_association, _i, _j, _len, _len1, _ref;
|
183
|
+
|
184
|
+
id = this._id || data && (data._id || data.id);
|
185
|
+
if (!id) {
|
186
|
+
return;
|
187
|
+
}
|
188
|
+
_ref = model[this.resource.toString()].has_many;
|
189
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
190
|
+
association_name = _ref[_i];
|
191
|
+
pluralized_association = model.pluralize(association_name);
|
192
|
+
association = this[pluralized_association];
|
193
|
+
if (!association.route) {
|
194
|
+
association.route = "/" + (model.pluralize(this.resource.toString())) + "/" + id + "/" + (model.pluralize(association.resource));
|
195
|
+
for (_j = 0, _len1 = association.length; _j < _len1; _j++) {
|
196
|
+
associated = association[_j];
|
197
|
+
if (!associated.route && (associated.parent != null)) {
|
198
|
+
associated.route = "/" + (model.pluralize(this.resource.toString())) + "/" + id + "/" + (model.pluralize(association.resource));
|
129
199
|
}
|
130
200
|
}
|
131
|
-
return true;
|
132
|
-
},
|
133
|
-
autosave: function() {
|
134
|
-
return this.save();
|
135
201
|
}
|
136
202
|
}
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
if (this.has_one && $.type(this.has_one) !== 'array') {
|
142
|
-
this.has_one = [this.has_one];
|
203
|
+
return true;
|
204
|
+
},
|
205
|
+
autosave: function() {
|
206
|
+
throw 'Not implemented yet';
|
143
207
|
}
|
144
|
-
|
145
|
-
|
208
|
+
},
|
209
|
+
has_one: {
|
210
|
+
nest_attributes: function() {
|
211
|
+
var association_name, association_names, associations_attributes, _i, _len, _results;
|
212
|
+
|
213
|
+
association_names = model[this.resource].has_one;
|
214
|
+
if (association_names) {
|
215
|
+
_results = [];
|
216
|
+
for (_i = 0, _len = association_names.length; _i < _len; _i++) {
|
217
|
+
association_name = association_names[_i];
|
218
|
+
associations_attributes = this["" + association_name + "_attributes"];
|
219
|
+
if (associations_attributes) {
|
220
|
+
this[association_name] = this["build_" + association_name](associations_attributes);
|
221
|
+
_results.push(delete this["" + association_name + "_attributes"]);
|
222
|
+
} else {
|
223
|
+
_results.push(void 0);
|
224
|
+
}
|
225
|
+
}
|
226
|
+
return _results;
|
227
|
+
}
|
146
228
|
}
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
229
|
+
}
|
230
|
+
};
|
231
|
+
|
232
|
+
associable = {
|
233
|
+
model: {
|
234
|
+
blender: function(definition) {
|
235
|
+
var model;
|
152
236
|
|
237
|
+
model = associable.model;
|
238
|
+
this.create_after_hooks = model.create_after_hooks;
|
239
|
+
this.create_before_hooks = model.create_before_hooks;
|
240
|
+
if (this.has_many && $.type(this.has_many) !== 'array') {
|
241
|
+
this.has_many = [this.has_many];
|
242
|
+
}
|
243
|
+
if (this.has_one && $.type(this.has_one) !== 'array') {
|
244
|
+
this.has_one = [this.has_one];
|
245
|
+
}
|
246
|
+
if (this.belongs_to && $.type(this.belongs_to) !== 'array') {
|
247
|
+
this.belongs_to = [this.belongs_to];
|
248
|
+
}
|
249
|
+
this.has_many || (this.has_many = []);
|
250
|
+
this.has_one || (this.has_one = []);
|
251
|
+
this.belongs_to || (this.belongs_to = []);
|
252
|
+
return true;
|
253
|
+
},
|
254
|
+
create_after_hooks: function(definition) {
|
255
|
+
var association_name, association_proxy, old_resource_id, options, resource, _i, _j, _k, _len, _len1, _len2, _ref, _ref1, _ref2, _results;
|
256
|
+
|
257
|
+
options = model[this.resource.name || this.resource.toString()];
|
153
258
|
if (options.has_many) {
|
154
259
|
_ref = options.has_many;
|
155
260
|
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
@@ -171,12 +276,14 @@ associable = {
|
|
171
276
|
resource = _ref1[_j];
|
172
277
|
association_proxy = {
|
173
278
|
resource: resource,
|
174
|
-
parent_resource: this.resource
|
279
|
+
parent_resource: this.resource,
|
280
|
+
owner: this
|
175
281
|
};
|
176
|
-
association_proxy[this.resource] = this;
|
282
|
+
association_proxy[this.resource.toString()] = this;
|
177
283
|
this["build_" + resource] = $.proxy(singular.build, association_proxy);
|
178
284
|
this["create_" + resource] = $.proxy(singular.create, association_proxy);
|
179
285
|
}
|
286
|
+
callbacks.has_one.nest_attributes.call(this);
|
180
287
|
}
|
181
288
|
if (options.belongs_to) {
|
182
289
|
_ref2 = options.belongs_to;
|
@@ -185,29 +292,69 @@ associable = {
|
|
185
292
|
resource = _ref2[_k];
|
186
293
|
association_proxy = {
|
187
294
|
resource: resource,
|
188
|
-
parent_resource: this.resource
|
295
|
+
parent_resource: this.resource,
|
296
|
+
parent: this,
|
297
|
+
owner: this
|
189
298
|
};
|
190
|
-
association_proxy[this.resource] = this;
|
299
|
+
association_proxy[this.resource.toString()] = this;
|
191
300
|
this["build_" + resource] = $.proxy(singular.build, association_proxy);
|
192
|
-
|
301
|
+
this["create_" + resource] = $.proxy(singular.create, association_proxy);
|
302
|
+
old_resource_id = this["" + resource + "_id"];
|
303
|
+
this["" + resource + "_id"] = null;
|
304
|
+
this.subscribe("" + resource + "_id", $.proxy(subscribers.belongs_to.foreign_key, association_proxy));
|
305
|
+
this.subscribe(resource.toString(), $.proxy(subscribers.belongs_to.associated_changed, association_proxy));
|
306
|
+
this.resource_id = old_resource_id;
|
307
|
+
if (this["" + resource + "_id"] && !this[resource]) {
|
308
|
+
_results.push(this.publish("" + resource + "_id", this["" + resource + "_id"]));
|
309
|
+
} else {
|
310
|
+
_results.push(void 0);
|
311
|
+
}
|
193
312
|
}
|
194
313
|
return _results;
|
195
314
|
}
|
196
|
-
}
|
315
|
+
},
|
316
|
+
create_before_hooks: function(record) {
|
317
|
+
var association_proxy, definition, resource, _i, _len, _ref, _results;
|
318
|
+
|
319
|
+
definition = this;
|
320
|
+
if (definition.belongs_to) {
|
321
|
+
_ref = definition.belongs_to;
|
322
|
+
_results = [];
|
323
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
324
|
+
resource = _ref[_i];
|
325
|
+
association_proxy = {
|
326
|
+
resource: resource,
|
327
|
+
parent_resource: this.resource,
|
328
|
+
owner: record
|
329
|
+
};
|
330
|
+
_results.push(modifiers.belongs_to.associated_loader.call(association_proxy));
|
331
|
+
}
|
332
|
+
return _results;
|
333
|
+
}
|
334
|
+
}
|
197
335
|
},
|
198
|
-
record:
|
199
|
-
|
200
|
-
|
336
|
+
record: {
|
337
|
+
after_initialize: function(attributes) {
|
338
|
+
if (this.resource == null) {
|
339
|
+
throw new Error('resource must be defined in order to associate');
|
340
|
+
}
|
341
|
+
return model[this.resource.name || this.resource.toString()].create_after_hooks.call(this);
|
342
|
+
},
|
343
|
+
before_initialize: function(creation) {
|
344
|
+
if (!this.resource) {
|
345
|
+
throw new Error('resource must be defined in order to associate');
|
346
|
+
}
|
347
|
+
return model[this.resource.name || this.resource.toString()].create_before_hooks(creation);
|
201
348
|
}
|
202
|
-
return model[this.resource.name || this.resource.toString()].create_associations.call(this);
|
203
349
|
}
|
204
350
|
};
|
205
351
|
|
206
352
|
model = root.model;
|
207
353
|
|
208
354
|
model.mix(function(modelable) {
|
209
|
-
modelable.after_mix.push(associable.model);
|
210
|
-
|
355
|
+
modelable.after_mix.push(associable.model.blender);
|
356
|
+
modelable.record.before_initialize.push(associable.record.before_initialize);
|
357
|
+
return modelable.record.after_initialize.push(associable.record.after_initialize);
|
211
358
|
});
|
212
359
|
|
213
360
|
model.associable = {
|
@@ -0,0 +1 @@
|
|
1
|
+
|
@@ -0,0 +1,32 @@
|
|
1
|
+
var handlers, model, persistable, record;
|
2
|
+
|
3
|
+
require('./queryable');
|
4
|
+
|
5
|
+
handlers = {
|
6
|
+
store_after_saved: function() {
|
7
|
+
var storage;
|
8
|
+
|
9
|
+
storage = model[this.resource.toString()].storage;
|
10
|
+
if (this._id) {
|
11
|
+
return storage.store(this._id, this);
|
12
|
+
}
|
13
|
+
}
|
14
|
+
};
|
15
|
+
|
16
|
+
persistable = {
|
17
|
+
record: {
|
18
|
+
after_initialize: function() {
|
19
|
+
return this.after('saved', handlers.store_after_saved);
|
20
|
+
}
|
21
|
+
}
|
22
|
+
};
|
23
|
+
|
24
|
+
model = window.model;
|
25
|
+
|
26
|
+
record = window.record;
|
27
|
+
|
28
|
+
model.persistable = true;
|
29
|
+
|
30
|
+
model.mix(function(modelable) {
|
31
|
+
return modelable.record.after_initialize.push(persistable.record.after_initialize);
|
32
|
+
});
|