ende 0.5.1 → 0.5.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/component.json +2 -2
- data/components/indefinido/indemma/master/component.json +27 -17
- data/components/indefinido/indemma/master/lib/record/associable.js +74 -75
- data/components/indefinido/indemma/master/lib/record/dirtyable.js +40 -0
- data/components/indefinido/indemma/master/lib/record/queryable.js +2 -2
- data/components/indefinido/indemma/master/lib/record/resource.js +1 -1
- data/components/indefinido/indemma/master/lib/record/rest.js +7 -2
- data/components/indefinido/indemma/master/lib/record/restfulable.js +37 -10
- data/components/indefinido/indemma/master/lib/record/scopable.js +20 -47
- data/components/indefinido/indemma/master/lib/record/storable.js +11 -0
- data/components/indefinido/indemma/master/lib/record/validatable.js +195 -1068
- data/components/indefinido/indemma/master/lib/record.js +1 -1
- data/components/indefinido/indemma/master/vendor/stampit.js +568 -242
- data/components/indefinido/observable/es6-modules/component.json +39 -0
- data/components/indefinido/{indemma/master/components/indefinido-observable → observable/es6-modules}/lib/adapters/rivets.js +3 -1
- data/components/indefinido/observable/es6-modules/lib/legacy/notifierable.js +145 -0
- data/components/indefinido/observable/es6-modules/lib/legacy/schedulerable.js +114 -0
- data/components/indefinido/observable/es6-modules/lib/lookup.js +38 -0
- data/components/indefinido/observable/es6-modules/lib/observable/keypath_observer.js +38 -0
- data/components/indefinido/observable/es6-modules/lib/observable/observation.js +45 -0
- data/components/indefinido/observable/es6-modules/lib/observable/selection.js +57 -0
- data/components/indefinido/observable/es6-modules/lib/observable/self_observer.js +38 -0
- data/components/indefinido/observable/es6-modules/lib/observable.js +90 -0
- data/components/indefinido/observable/es6-modules/lib/platform.js +12 -0
- data/components/indefinido/observable/es6-modules/vendor/observe-js/observe.js +1631 -0
- data/components/indefinido/{indemma/master/components/indefinido-observable → observable/es6-modules}/vendor/shims/accessors.js +85 -10
- data/lib/assets/javascripts/aura/extensions/rivets.js.coffee +1 -1
- data/lib/ende/version.rb +1 -1
- data/vendor/assets/components/ende_build.js +18379 -26828
- metadata +20 -128
- data/components/indefinido/indemma/master/.gitignore +0 -17
- data/components/indefinido/indemma/master/.ruby-gemset +0 -1
- data/components/indefinido/indemma/master/.ruby-version +0 -1
- data/components/indefinido/indemma/master/Gemfile +0 -13
- data/components/indefinido/indemma/master/Guardfile +0 -39
- data/components/indefinido/indemma/master/History.md +0 -0
- data/components/indefinido/indemma/master/Readme.md +0 -447
- data/components/indefinido/indemma/master/build/build.js +0 -26288
- data/components/indefinido/indemma/master/build/development.js +0 -22200
- data/components/indefinido/indemma/master/build/release.js +0 -22139
- data/components/indefinido/indemma/master/build/test.js +0 -22200
- data/components/indefinido/indemma/master/components/chaijs-assertion-error/component.json +0 -18
- data/components/indefinido/indemma/master/components/chaijs-assertion-error/index.js +0 -110
- data/components/indefinido/indemma/master/components/chaijs-chai/component.json +0 -47
- data/components/indefinido/indemma/master/components/chaijs-chai/index.js +0 -1
- data/components/indefinido/indemma/master/components/chaijs-chai/lib/chai/assertion.js +0 -130
- data/components/indefinido/indemma/master/components/chaijs-chai/lib/chai/core/assertions.js +0 -1270
- data/components/indefinido/indemma/master/components/chaijs-chai/lib/chai/interface/assert.js +0 -1080
- data/components/indefinido/indemma/master/components/chaijs-chai/lib/chai/interface/expect.js +0 -12
- data/components/indefinido/indemma/master/components/chaijs-chai/lib/chai/interface/should.js +0 -76
- data/components/indefinido/indemma/master/components/chaijs-chai/lib/chai/utils/addChainableMethod.js +0 -94
- data/components/indefinido/indemma/master/components/chaijs-chai/lib/chai/utils/addMethod.js +0 -37
- data/components/indefinido/indemma/master/components/chaijs-chai/lib/chai/utils/addProperty.js +0 -40
- data/components/indefinido/indemma/master/components/chaijs-chai/lib/chai/utils/eql.js +0 -129
- data/components/indefinido/indemma/master/components/chaijs-chai/lib/chai/utils/flag.js +0 -32
- data/components/indefinido/indemma/master/components/chaijs-chai/lib/chai/utils/getActual.js +0 -19
- data/components/indefinido/indemma/master/components/chaijs-chai/lib/chai/utils/getEnumerableProperties.js +0 -25
- data/components/indefinido/indemma/master/components/chaijs-chai/lib/chai/utils/getMessage.js +0 -49
- data/components/indefinido/indemma/master/components/chaijs-chai/lib/chai/utils/getName.js +0 -20
- data/components/indefinido/indemma/master/components/chaijs-chai/lib/chai/utils/getPathValue.js +0 -102
- data/components/indefinido/indemma/master/components/chaijs-chai/lib/chai/utils/getProperties.js +0 -35
- data/components/indefinido/indemma/master/components/chaijs-chai/lib/chai/utils/index.js +0 -108
- data/components/indefinido/indemma/master/components/chaijs-chai/lib/chai/utils/inspect.js +0 -320
- data/components/indefinido/indemma/master/components/chaijs-chai/lib/chai/utils/objDisplay.js +0 -48
- data/components/indefinido/indemma/master/components/chaijs-chai/lib/chai/utils/overwriteMethod.js +0 -51
- data/components/indefinido/indemma/master/components/chaijs-chai/lib/chai/utils/overwriteProperty.js +0 -54
- data/components/indefinido/indemma/master/components/chaijs-chai/lib/chai/utils/test.js +0 -26
- data/components/indefinido/indemma/master/components/chaijs-chai/lib/chai/utils/transferFlags.js +0 -44
- data/components/indefinido/indemma/master/components/chaijs-chai/lib/chai/utils/type.js +0 -45
- data/components/indefinido/indemma/master/components/chaijs-chai/lib/chai.js +0 -80
- data/components/indefinido/indemma/master/components/component-bind/component.json +0 -14
- data/components/indefinido/indemma/master/components/component-bind/index.js +0 -24
- data/components/indefinido/indemma/master/components/component-jquery/component.json +0 -14
- data/components/indefinido/indemma/master/components/component-jquery/index.js +0 -9601
- data/components/indefinido/indemma/master/components/component-type/component.json +0 -18
- data/components/indefinido/indemma/master/components/component-type/index.js +0 -32
- data/components/indefinido/indemma/master/components/indefinido-advisable/component.json +0 -21
- data/components/indefinido/indemma/master/components/indefinido-advisable/index.js +0 -1
- data/components/indefinido/indemma/master/components/indefinido-advisable/lib/advisable.js +0 -60
- data/components/indefinido/indemma/master/components/indefinido-observable/component.json +0 -25
- data/components/indefinido/indemma/master/components/indefinido-observable/components/cjohansen-sinon/sinon.js +0 -4290
- data/components/indefinido/indemma/master/components/indefinido-observable/lib/observable.js +0 -323
- data/components/indefinido/indemma/master/components/kapit-observe-utils/component.json +0 -13
- data/components/indefinido/indemma/master/components/paulmillr-es6-shim/component.json +0 -17
- data/components/indefinido/indemma/master/components/paulmillr-es6-shim/es6-shim.js +0 -996
- data/components/indefinido/indemma/master/components/pluma-assimilate/component.json +0 -25
- data/components/indefinido/indemma/master/components/pluma-assimilate/dist/assimilate.js +0 -127
- data/components/indefinido/indemma/master/karma.conf.js +0 -76
- data/components/indefinido/indemma/master/package.json +0 -9
- data/components/indefinido/indemma/master/spec/record/associable_spec.js +0 -137
- data/components/indefinido/indemma/master/spec/record/persistable_spec.js +0 -36
- data/components/indefinido/indemma/master/spec/record/queryable_spec.js +0 -33
- data/components/indefinido/indemma/master/spec/record/resource_spec.js +0 -93
- data/components/indefinido/indemma/master/spec/record/rest_spec.js +0 -32
- data/components/indefinido/indemma/master/spec/record/restfulable_spec.js +0 -300
- data/components/indefinido/indemma/master/spec/record/scopable_spec.js +0 -212
- data/components/indefinido/indemma/master/spec/record/storable_spec.js +0 -53
- data/components/indefinido/indemma/master/spec/record/translationable.js +0 -28
- data/components/indefinido/indemma/master/spec/record/validatable_spec.js +0 -111
- data/components/indefinido/indemma/master/spec/record/validations/associated_spec.js +0 -43
- data/components/indefinido/indemma/master/spec/record/validations/confirmation_spec.js +0 -36
- data/components/indefinido/indemma/master/spec/record/validations/cpf_spec.js +0 -35
- data/components/indefinido/indemma/master/spec/record/validations/presence_spec.js +0 -28
- data/components/indefinido/indemma/master/spec/record/validations/remote_spec.js +0 -87
- data/components/indefinido/indemma/master/spec/record/validations/type_spec.js +0 -48
- data/components/indefinido/indemma/master/spec/record_spec.js +0 -37
- data/components/indefinido/indemma/master/spec/spec_helper.js +0 -11
- data/components/indefinido/indemma/master/spec/support/value_objects/phone.js +0 -45
- data/components/indefinido/indemma/master/src/lib/extensions/rivets.coffee +0 -17
- data/components/indefinido/indemma/master/src/lib/record/associable.coffee +0 -380
- data/components/indefinido/indemma/master/src/lib/record/errors.coffee +0 -20
- data/components/indefinido/indemma/master/src/lib/record/maid.coffee +0 -16
- data/components/indefinido/indemma/master/src/lib/record/persistable.coffee +0 -32
- data/components/indefinido/indemma/master/src/lib/record/queryable.coffee +0 -30
- data/components/indefinido/indemma/master/src/lib/record/resource.coffee +0 -106
- data/components/indefinido/indemma/master/src/lib/record/rest.coffee +0 -28
- data/components/indefinido/indemma/master/src/lib/record/restfulable.coffee +0 -447
- data/components/indefinido/indemma/master/src/lib/record/scopable.coffee +0 -294
- data/components/indefinido/indemma/master/src/lib/record/storable.coffee +0 -46
- data/components/indefinido/indemma/master/src/lib/record/translationable.coffee +0 -18
- data/components/indefinido/indemma/master/src/lib/record/validatable.coffee +0 -207
- data/components/indefinido/indemma/master/src/lib/record/validations/associated.coffee +0 -30
- data/components/indefinido/indemma/master/src/lib/record/validations/confirmation.coffee +0 -17
- data/components/indefinido/indemma/master/src/lib/record/validations/cpf.coffee +0 -57
- data/components/indefinido/indemma/master/src/lib/record/validations/presence.coffee +0 -16
- data/components/indefinido/indemma/master/src/lib/record/validations/remote.coffee +0 -61
- data/components/indefinido/indemma/master/src/lib/record/validations/type.coffee +0 -31
- data/components/indefinido/indemma/master/src/lib/record/validations/validatorable.coffee +0 -5
- data/components/indefinido/indemma/master/src/lib/record.coffee +0 -138
- data/components/indefinido/indemma/master/src/spec/record/associable_spec.coffee +0 -130
- data/components/indefinido/indemma/master/src/spec/record/persistable_spec.coffee +0 -30
- data/components/indefinido/indemma/master/src/spec/record/queryable_spec.coffee +0 -27
- data/components/indefinido/indemma/master/src/spec/record/resource_spec.coffee +0 -69
- data/components/indefinido/indemma/master/src/spec/record/rest_spec.coffee +0 -22
- data/components/indefinido/indemma/master/src/spec/record/restfulable_spec.coffee +0 -215
- data/components/indefinido/indemma/master/src/spec/record/scopable_spec.coffee +0 -191
- data/components/indefinido/indemma/master/src/spec/record/storable_spec.coffee +0 -40
- data/components/indefinido/indemma/master/src/spec/record/translationable.coffee +0 -19
- data/components/indefinido/indemma/master/src/spec/record/validatable_spec.coffee +0 -100
- data/components/indefinido/indemma/master/src/spec/record/validations/associated_spec.coffee +0 -35
- data/components/indefinido/indemma/master/src/spec/record/validations/confirmation_spec.coffee +0 -25
- data/components/indefinido/indemma/master/src/spec/record/validations/cpf_spec.coffee +0 -28
- data/components/indefinido/indemma/master/src/spec/record/validations/presence_spec.coffee +0 -24
- data/components/indefinido/indemma/master/src/spec/record/validations/remote_spec.coffee +0 -74
- data/components/indefinido/indemma/master/src/spec/record/validations/type_spec.coffee +0 -33
- data/components/indefinido/indemma/master/src/spec/record_spec.coffee +0 -23
- data/components/indefinido/indemma/master/src/spec/spec_helper.coffee +0 -9
- data/components/indefinido/indemma/master/src/spec/support/value_objects/phone.coffee +0 -30
- data/components/indefinido/indemma/master/vendor/object/mixin.js +0 -196
- data/components/indefinido/indemma/master/vendor/sinon.js +0 -4290
- /data/components/indefinido/{indemma/master/components/indefinido-observable → observable/es6-modules}/index.js +0 -0
- /data/components/indefinido/{indemma/master/components/indefinido-observable → observable/es6-modules}/vendor/shims/accessors-legacy.js +0 -0
- /data/components/indefinido/{indemma/master/components/indefinido-observable → observable/es6-modules}/vendor/shims/array.indexOf.js +0 -0
- /data/components/indefinido/{indemma/master/components/indefinido-observable → observable/es6-modules}/vendor/shims/object.create.js +0 -0
@@ -1,380 +0,0 @@
|
|
1
|
-
root = window
|
2
|
-
$ = require 'jquery'
|
3
|
-
extend = require 'assimilate'
|
4
|
-
|
5
|
-
require './resource'
|
6
|
-
|
7
|
-
# Store association methods
|
8
|
-
# TODO Implement setter for route
|
9
|
-
plural = # has_many ## TODO embeds_many
|
10
|
-
add : (params...) ->
|
11
|
-
# TODO check for id and instantly add resource
|
12
|
-
# TODO Set foreign keys?
|
13
|
-
@push @build attributes for attributes in params
|
14
|
-
|
15
|
-
create: (params...) ->
|
16
|
-
for attributes in params
|
17
|
-
record = @build attributes
|
18
|
-
@push record
|
19
|
-
record.save()
|
20
|
-
build: (data = {}) ->
|
21
|
-
data.parent_resource = @parent_resource
|
22
|
-
|
23
|
-
# TODO Setup a before save callback to generate route when there is no id
|
24
|
-
data.route ||= "#{@parent.route}/#{@parent._id}/#{model.pluralize @resource.toString()}" if @parent?
|
25
|
-
throw "associable.has_many: cannot redefine route of association #{@parent_resource}.#{@resource} from #{@route} to #{data.route}" if @route isnt data.route and @route
|
26
|
-
# Adds parent record to children side of association, if not set
|
27
|
-
# TODO check if this reference is unmade on instance elimination
|
28
|
-
data[@parent_resource] ||= @parent
|
29
|
-
|
30
|
-
# TODO store a singular copy of the resource for better performace
|
31
|
-
model[model.singularize @resource] data
|
32
|
-
push : ->
|
33
|
-
console.warn "#{@resource}.push is deprecated and will be removed, please use add instead"
|
34
|
-
Array.prototype.push.apply @, arguments
|
35
|
-
|
36
|
-
length : 0
|
37
|
-
json : (methods, omissions) -> record.json(methods, omissions) for record in @
|
38
|
-
|
39
|
-
|
40
|
-
singular = # belongs_to, has_one ## TODO embeds_one, embedded_in
|
41
|
-
# @ = record
|
42
|
-
create: (data) -> model[@resource].create extend {}, @, data
|
43
|
-
# @ = record
|
44
|
-
# TODO convert to association proxy
|
45
|
-
build : (data) ->
|
46
|
-
# Adds child record of association to parent, and returns new
|
47
|
-
# record
|
48
|
-
@owner[@resource.toString()] = model[@resource.toString()] extend {}, @, data
|
49
|
-
|
50
|
-
subscribers =
|
51
|
-
belongs_to:
|
52
|
-
foreign_key: (resource_id) ->
|
53
|
-
association_name = @resource.toString()
|
54
|
-
|
55
|
-
# TODO faster nullifing association check
|
56
|
-
# TODO check if its usefull to only allow disassociating with null
|
57
|
-
unless resource_id
|
58
|
-
@dirty = true
|
59
|
-
@owner[association_name] = resource_id
|
60
|
-
return resource_id
|
61
|
-
|
62
|
-
# TODO Discover and update inverse side of association
|
63
|
-
# associated[@owner.resource.toString()] = @owner
|
64
|
-
current_resource_id = @owner.observed[association_name]?._id
|
65
|
-
if resource_id != current_resource_id
|
66
|
-
# Update association with blank resource that will update
|
67
|
-
resource = model[association_name]
|
68
|
-
unless resource
|
69
|
-
console.warn "subscribers.belongs_to.foreign_key: associated factory not found for model: #{association_name}"
|
70
|
-
return resource_id
|
71
|
-
|
72
|
-
# TODO remote find or local find automatically, and implement find_or_initialize_by
|
73
|
-
# this code is not needed, since the association loader already loads the associated record when trying to get it
|
74
|
-
# associated = resource.find resource_id
|
75
|
-
# associated ||= resource _id: resource_id
|
76
|
-
|
77
|
-
# Nullify associated object, so next time user accesses it,
|
78
|
-
# association loader loads the new object
|
79
|
-
@owner.observed[association_name] = null
|
80
|
-
|
81
|
-
resource_id
|
82
|
-
|
83
|
-
# Called when associated record changes, so we can silently update the id
|
84
|
-
associated_changed: (associated) ->
|
85
|
-
@owner.observed["#{@resource.toString()}_id"] = if associated then associated._id else null
|
86
|
-
|
87
|
-
modifiers =
|
88
|
-
# Called before record initialization to create the a lazy loader
|
89
|
-
# for other records
|
90
|
-
belongs_to:
|
91
|
-
associated_loader: ->
|
92
|
-
association_name = @resource.toString()
|
93
|
-
|
94
|
-
unless @owner.observed?
|
95
|
-
# When initializing a owner record in legacy browsers, we will
|
96
|
-
# run the getter to set the default value for the associate
|
97
|
-
# property
|
98
|
-
#
|
99
|
-
# TODO in the accessors shim, better way of getting the
|
100
|
-
# default value for further usage
|
101
|
-
@owner.observed = {}
|
102
|
-
temporary_observed = true
|
103
|
-
|
104
|
-
definition = Object.defineProperty @owner, association_name,
|
105
|
-
# Observable already sets property for us
|
106
|
-
set: (associated) ->
|
107
|
-
@observed[association_name] = associated
|
108
|
-
|
109
|
-
get: =>
|
110
|
-
associated = @owner.observed[association_name]
|
111
|
-
associated_id = @owner.observed[association_name + '_id']
|
112
|
-
|
113
|
-
# Returns null or undefined depending on sustained state of
|
114
|
-
# resource and on retrievability of the resource
|
115
|
-
return associated unless associated?._id? or associated_id
|
116
|
-
|
117
|
-
# Returns imediatelly for resources on storage
|
118
|
-
# TODO make this extenxible
|
119
|
-
return associated if associated?.sustained
|
120
|
-
|
121
|
-
resource = model[association_name]
|
122
|
-
unless resource
|
123
|
-
console.warn "subscribers.belongs_to.foreign_key: associated factory not found for model: #{association_name}"
|
124
|
-
return associated
|
125
|
-
|
126
|
-
# Search through stored resources to see if it is stored
|
127
|
-
associated = resource.find associated_id || associated._id
|
128
|
-
|
129
|
-
# Found associated in storage, update this model and return associated
|
130
|
-
return @owner.observed[association_name] = associated if associated
|
131
|
-
|
132
|
-
# Not found associated in storage
|
133
|
-
associated ||= resource _id: associated_id # initialize and store a new record
|
134
|
-
associated.reload() # fetch resource
|
135
|
-
|
136
|
-
# Store temporary unloaded resource in this model
|
137
|
-
@owner.observed[association_name] = associated
|
138
|
-
|
139
|
-
configurable: true
|
140
|
-
enumerable: true
|
141
|
-
|
142
|
-
delete @owner.observed if temporary_observed
|
143
|
-
|
144
|
-
definition
|
145
|
-
|
146
|
-
callbacks =
|
147
|
-
has_many:
|
148
|
-
# Forward association nested attributes
|
149
|
-
# TODO write attribute setter, and remove this code
|
150
|
-
nest_attributes: ->
|
151
|
-
# TODO only nest specified nested attributes on model definition
|
152
|
-
# TODO remove associations iteration, and pass throught parameter
|
153
|
-
# TODO DO not support '_attributes' property on instantiating!
|
154
|
-
association_names = model[@resource].has_many
|
155
|
-
if association_names
|
156
|
-
for association_name in association_names
|
157
|
-
|
158
|
-
# Instantiate new records for the association attributes
|
159
|
-
# TODO DO not support '_attributes' property on instantiating!
|
160
|
-
# TODO define setter for attributes
|
161
|
-
associations_attributes = @["#{association_name}_attributes"]
|
162
|
-
association = @[model.pluralize association_name]
|
163
|
-
|
164
|
-
if associations_attributes and associations_attributes.length
|
165
|
-
|
166
|
-
unless 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
|
-
# TODO store a singular copy of the resource for better performace
|
172
|
-
association.resource = model.singularize association.resource
|
173
|
-
association.add.apply association, associations_attributes
|
174
|
-
association.resource = model.pluralize association.resource
|
175
|
-
|
176
|
-
# TODO Update route after setting the id
|
177
|
-
# TODO Update route association only once for each associated record
|
178
|
-
update_association: (data) ->
|
179
|
-
id = @_id || data && (data._id || data.id)
|
180
|
-
|
181
|
-
# Keep trying until we have a id
|
182
|
-
return unless id
|
183
|
-
|
184
|
-
for association_name in model[@resource.toString()].has_many
|
185
|
-
pluralized_association = model.pluralize association_name
|
186
|
-
association = @[pluralized_association]
|
187
|
-
# TODO setter of association.route
|
188
|
-
# to automatically update associated records
|
189
|
-
unless association.route
|
190
|
-
association.route = "/#{model.pluralize @resource.toString()}/#{id}/#{model.pluralize association.resource}"
|
191
|
-
|
192
|
-
for associated in association when not associated.route and associated.parent?
|
193
|
-
associated.route = "/#{model.pluralize @resource.toString()}/#{id}/#{model.pluralize association.resource}"
|
194
|
-
|
195
|
-
true
|
196
|
-
autosave: ->
|
197
|
-
throw 'Not implemented yet'
|
198
|
-
# @save()
|
199
|
-
|
200
|
-
has_one:
|
201
|
-
# Forward association nested attributes
|
202
|
-
# TODO write attribute setter, and remove this code
|
203
|
-
nest_attributes: ->
|
204
|
-
# TODO only nest specified nested attributes on model definition
|
205
|
-
# TODO convert to associations instead of association name
|
206
|
-
# TODO remove associations iteration, and pass throught parameter
|
207
|
-
# TODO DO not support '_attributes' property on instantiating!
|
208
|
-
association_names = model[@resource].has_one
|
209
|
-
if association_names
|
210
|
-
for association_name in association_names
|
211
|
-
associations_attributes = @["#{association_name}_attributes"]
|
212
|
-
if associations_attributes
|
213
|
-
@[association_name] = @["build_#{association_name}"] associations_attributes
|
214
|
-
delete @["#{association_name}_attributes"]
|
215
|
-
|
216
|
-
|
217
|
-
# TODO Better association segregation
|
218
|
-
associable =
|
219
|
-
model:
|
220
|
-
|
221
|
-
# @ = model instance
|
222
|
-
# param definition modable
|
223
|
-
blender: (definition) ->
|
224
|
-
{model} = associable
|
225
|
-
|
226
|
-
@create_after_hooks = model.create_after_hooks
|
227
|
-
@create_before_hooks = model.create_before_hooks
|
228
|
-
|
229
|
-
# TODO better default definition of associations
|
230
|
-
@has_many = [@has_many ] if @has_many and $.type(@has_many) != 'array'
|
231
|
-
@has_one = [@has_one ] if @has_one and $.type(@has_one) != 'array'
|
232
|
-
@belongs_to = [@belongs_to] if @belongs_to and $.type(@belongs_to) != 'array'
|
233
|
-
|
234
|
-
@has_many ||= []
|
235
|
-
@has_one ||= []
|
236
|
-
@belongs_to ||= []
|
237
|
-
|
238
|
-
true
|
239
|
-
|
240
|
-
|
241
|
-
# TODO better organisation of this code
|
242
|
-
# inside this function: @ = record (running on after_initialize)
|
243
|
-
create_after_hooks: (definition) ->
|
244
|
-
|
245
|
-
# TODO Rename options to definition
|
246
|
-
options = model[@resource.name || @resource.toString()]
|
247
|
-
|
248
|
-
# Create association methods
|
249
|
-
# Setup one to many association in model
|
250
|
-
if options.has_many
|
251
|
-
|
252
|
-
# TODO accept more options on has_many association creation
|
253
|
-
for resource in options.has_many
|
254
|
-
# unless model[resource]
|
255
|
-
# throw "Model not found for association with resource '#{resource}', on association 'has_many' "
|
256
|
-
|
257
|
-
# TODO instantiate default resources in has_many association
|
258
|
-
# @resource = model[resource].resource
|
259
|
-
|
260
|
-
# TODO Remember to clear association proxy when object is destroyed
|
261
|
-
association_proxy = resource: resource, parent_resource: @resource, parent: @
|
262
|
-
association_name = model.pluralize resource
|
263
|
-
|
264
|
-
# When deserializing has many associated resources from
|
265
|
-
# server, it is common to send as the association without
|
266
|
-
# suffix
|
267
|
-
association_attributes = @[association_name] || []
|
268
|
-
@["#{association_name}_attributes"] ||= []
|
269
|
-
@["#{association_name}_attributes"] = @["#{association_name}_attributes"].concat association_attributes if association_attributes.length
|
270
|
-
|
271
|
-
# Create or Override sent attributes by the association proxy
|
272
|
-
@[association_name] = $.extend association_proxy, plural
|
273
|
-
|
274
|
-
|
275
|
-
# Update association attribute
|
276
|
-
@after 'saved', callbacks.has_many.update_association
|
277
|
-
|
278
|
-
# Forward nested attributes
|
279
|
-
callbacks.has_many.nest_attributes.call @
|
280
|
-
|
281
|
-
if options.has_one
|
282
|
-
for resource in options.has_one
|
283
|
-
# unless model[resource]
|
284
|
-
# throw "Model not found for association with resource '#{resource}', on association 'has_one' "
|
285
|
-
|
286
|
-
# TODO deprecate parent_resource
|
287
|
-
association_proxy = resource: resource, parent_resource: @resource, owner: @
|
288
|
-
association_proxy[@resource.toString()] = @
|
289
|
-
|
290
|
-
@["build_#{resource}" ] = $.proxy singular.build , association_proxy
|
291
|
-
@["create_#{resource}"] = $.proxy singular.create, association_proxy
|
292
|
-
|
293
|
-
# Update association attribute
|
294
|
-
# TODO @after 'saved', callbacks.has_many.update_association
|
295
|
-
|
296
|
-
# Forward nested attributes
|
297
|
-
callbacks.has_one.nest_attributes.call @
|
298
|
-
|
299
|
-
# Externalize this to a file
|
300
|
-
if options.belongs_to
|
301
|
-
# TODO implement association reflection!
|
302
|
-
for resource in options.belongs_to
|
303
|
-
# unless model[resource]
|
304
|
-
# throw "Model not found for association with resource '#{resource}', on association 'belongs_to' "
|
305
|
-
|
306
|
-
# TODO put deprecation warning on parent key
|
307
|
-
association_proxy = resource: resource, parent_resource: @resource, parent: @, owner: @
|
308
|
-
|
309
|
-
# TODO see why this code is here, since we have the owner key
|
310
|
-
association_proxy[@resource.toString()] = @
|
311
|
-
|
312
|
-
@["build_#{resource}"] = $.proxy singular.build , association_proxy
|
313
|
-
@["create_#{resource}"] = $.proxy singular.create, association_proxy
|
314
|
-
|
315
|
-
# TODO copy from active record and better modularization of
|
316
|
-
# this internals
|
317
|
-
# To prevent association loading request we must nullify the
|
318
|
-
# association when subscribing
|
319
|
-
old_resource_id = @["#{resource}_id"]
|
320
|
-
old_dirty = @dirty
|
321
|
-
@["#{resource}_id"] = null
|
322
|
-
|
323
|
-
@subscribe "#{resource}_id" , $.proxy subscribers.belongs_to.foreign_key, association_proxy
|
324
|
-
@subscribe resource.toString(), $.proxy subscribers.belongs_to.associated_changed, association_proxy
|
325
|
-
|
326
|
-
# Restore id after loader prevention has passed
|
327
|
-
@["#{resource}_id"] = old_resource_id
|
328
|
-
@dirty = old_dirty
|
329
|
-
|
330
|
-
# Execute relation attributes binding
|
331
|
-
# TODO validate bindings! When @resource._id != @["#{resource}_id"]
|
332
|
-
# TODO write test for this case
|
333
|
-
# if @["#{resource}_id"] and not @[resource]
|
334
|
-
# @publish "#{resource}_id", @["#{resource}_id"]
|
335
|
-
|
336
|
-
# TODO better organization of this code, probably transforming the
|
337
|
-
# association into a composable object inside this function: @ =
|
338
|
-
# record (running on before_initialize) Beware there is no
|
339
|
-
# advisable or observable features
|
340
|
-
# @ = model
|
341
|
-
# param record = record instance
|
342
|
-
create_before_hooks: (record) ->
|
343
|
-
definition = @
|
344
|
-
|
345
|
-
# TODO Externalize this to a file
|
346
|
-
if definition.belongs_to
|
347
|
-
|
348
|
-
# TODO implement association reflection!
|
349
|
-
for resource in definition.belongs_to
|
350
|
-
# unless model[resource]
|
351
|
-
# throw "Model not found for association with resource '#{resource}', on association 'belongs_to' "
|
352
|
-
|
353
|
-
# TODO put deprecation warning on parent key
|
354
|
-
association_proxy = resource: resource, parent_resource: @resource, owner: record
|
355
|
-
|
356
|
-
modifiers.belongs_to.associated_loader.call association_proxy
|
357
|
-
|
358
|
-
|
359
|
-
# @ = record
|
360
|
-
record:
|
361
|
-
after_initialize: (attributes) ->
|
362
|
-
throw new Error 'resource must be defined in order to associate' unless @resource?
|
363
|
-
model[@resource.name || @resource.toString()].create_after_hooks.call @
|
364
|
-
|
365
|
-
before_initialize: (creation) ->
|
366
|
-
throw new Error 'resource must be defined in order to associate' unless @resource
|
367
|
-
model[@resource.name || @resource.toString()].create_before_hooks creation
|
368
|
-
|
369
|
-
|
370
|
-
# Extend indemma
|
371
|
-
model = root.model # TODO better way to get parent
|
372
|
-
model.mix (modelable) ->
|
373
|
-
modelable.after_mix.push associable.model.blender
|
374
|
-
modelable.record.before_initialize.push associable.record.before_initialize
|
375
|
-
modelable.record.after_initialize.push associable.record.after_initialize
|
376
|
-
|
377
|
-
# This allows to extendind the associable mixin
|
378
|
-
model.associable =
|
379
|
-
mix : (blender) ->
|
380
|
-
blender singular, plural
|
@@ -1,20 +0,0 @@
|
|
1
|
-
# TODO externalize errorsable from validatable
|
2
|
-
# errorsable = stampit
|
3
|
-
# add: (attribute, message_key, options) ->
|
4
|
-
#
|
5
|
-
# @push [attribute, message_key, options]
|
6
|
-
# @messages[attribute_name] messages[message_key](attribute_name)
|
7
|
-
#
|
8
|
-
# clear: ->
|
9
|
-
# if @length
|
10
|
-
# @length = 0
|
11
|
-
# @messages = {}
|
12
|
-
#
|
13
|
-
# push: Array.prototype.push
|
14
|
-
# splice: Array.prototype.splice
|
15
|
-
# ,
|
16
|
-
# messages: {}
|
17
|
-
# length: 0
|
18
|
-
# , ->
|
19
|
-
# @messages = []
|
20
|
-
# @
|
@@ -1,16 +0,0 @@
|
|
1
|
-
maid =
|
2
|
-
|
3
|
-
model : ->
|
4
|
-
@record.after_initialize.push maid.record if @washing?
|
5
|
-
|
6
|
-
record: ->
|
7
|
-
|
8
|
-
@subscribe 'dirty', (dirty) ->
|
9
|
-
dirty && setTimeout =>
|
10
|
-
@save()
|
11
|
-
, 500
|
12
|
-
|
13
|
-
# Extend indemma
|
14
|
-
model = window.model
|
15
|
-
model.mix (modelable) ->
|
16
|
-
modelable.after_mix.unshift maid.model
|
@@ -1,32 +0,0 @@
|
|
1
|
-
require './queryable'
|
2
|
-
|
3
|
-
handlers =
|
4
|
-
store_after_saved: ->
|
5
|
-
# TODO remove global model usage
|
6
|
-
{storage} = model[@resource.toString()]
|
7
|
-
|
8
|
-
# TODO check persistable configuration before attaching handlers
|
9
|
-
# and remove the @_id presence check
|
10
|
-
storage.store @_id, @ if @_id
|
11
|
-
|
12
|
-
|
13
|
-
persistable =
|
14
|
-
record:
|
15
|
-
after_initialize: ->
|
16
|
-
if @_id
|
17
|
-
# TODO remove global model usage
|
18
|
-
{storage} = model[@resource.toString()]
|
19
|
-
storage.store @_id, @
|
20
|
-
else
|
21
|
-
# TODO check persistable configuration before attaching handlers
|
22
|
-
@after 'saved', handlers.store_after_saved
|
23
|
-
|
24
|
-
# Extend indemma
|
25
|
-
# TODO use stampit to extend record and model
|
26
|
-
model = window.model # TODO better way to get parent
|
27
|
-
record = window.record # TODO better way to get parent
|
28
|
-
|
29
|
-
model.persistable = true
|
30
|
-
|
31
|
-
model.mix (modelable) ->
|
32
|
-
modelable.record.after_initialize.push persistable.record.after_initialize
|
@@ -1,30 +0,0 @@
|
|
1
|
-
extend = require 'assimilate'
|
2
|
-
storable = require './storable'
|
3
|
-
# merge = extend.withStrategy 'deep'
|
4
|
-
stampit = require '../../vendor/stampit'
|
5
|
-
|
6
|
-
queryable =
|
7
|
-
# FIXME don't let everyone use the same storage instance! or let it?
|
8
|
-
storage: storable()
|
9
|
-
find: (key) ->
|
10
|
-
throw new TypeError "InvalidFind: resource.find was called with a falsey value" unless key
|
11
|
-
@storage.store key
|
12
|
-
every: ->
|
13
|
-
@storage.values()
|
14
|
-
where: ->
|
15
|
-
throw new Error 'queryable.where: Not implemented yet'
|
16
|
-
|
17
|
-
# Extend indemma
|
18
|
-
# TODO use stampit to extend record and model
|
19
|
-
model = window.model # TODO better way to get parent
|
20
|
-
record = window.record # TODO better way to get parent
|
21
|
-
|
22
|
-
# queryable = stampit.compose queryable, storable
|
23
|
-
|
24
|
-
|
25
|
-
model.queryable = true
|
26
|
-
module.exports = queryable
|
27
|
-
|
28
|
-
model.mix (modelable) ->
|
29
|
-
# TODO use stampit to extend record and model
|
30
|
-
extend modelable, queryable
|
@@ -1,106 +0,0 @@
|
|
1
|
-
stampit = require '../../vendor/stampit'
|
2
|
-
require '../../vendor/owl/pluralize'
|
3
|
-
|
4
|
-
# TODO Think of a better name
|
5
|
-
resource = stampit
|
6
|
-
toString: -> @name
|
7
|
-
# TODO move resourceable.route() to here
|
8
|
-
,
|
9
|
-
name : 'unknown'
|
10
|
-
scope : null
|
11
|
-
singular: false
|
12
|
-
, ->
|
13
|
-
|
14
|
-
# TODO better integration with record.coffee, and stop storing
|
15
|
-
# original reference
|
16
|
-
if @original_reference
|
17
|
-
stampit.mixIn @original_reference, @
|
18
|
-
@original_reference.toString = @toString
|
19
|
-
@original_reference.param_name ||= @name
|
20
|
-
|
21
|
-
return @original_reference
|
22
|
-
|
23
|
-
@param_name ||= @name
|
24
|
-
|
25
|
-
@
|
26
|
-
|
27
|
-
# TODO Think of a better name, and move to a composable stampit item
|
28
|
-
descriptors =
|
29
|
-
route:
|
30
|
-
get: ->
|
31
|
-
# TODO use resource object on associations!
|
32
|
-
@resource = name: @resource if typeof @resource == 'string'
|
33
|
-
|
34
|
-
route = '/'
|
35
|
-
route += "#{@parent.route}/#{@parent._id}/" if @parent?
|
36
|
-
route += @resource.scope + '/' if @resource.scope?
|
37
|
-
|
38
|
-
route += if @resource.singular then @resource.name else model.pluralize @resource.name
|
39
|
-
|
40
|
-
@route = route
|
41
|
-
|
42
|
-
configurable: true
|
43
|
-
# set: (value) -> @initial_route = value
|
44
|
-
|
45
|
-
# TODO Deprecated! Remove on 15/02/2014
|
46
|
-
# parent_id:
|
47
|
-
# get: -> @[@parent_resource]._id if @[@parent_resource]
|
48
|
-
# set: -> console.error 'Warning changing associations throught parent_id not allowed for security and style guide purposes' # TODO
|
49
|
-
# configurable: true
|
50
|
-
# enumerable: true
|
51
|
-
|
52
|
-
# TODO Think of a better name, and move to a composable stampit item
|
53
|
-
resourceable =
|
54
|
-
pluralize: (word, count, plural) ->
|
55
|
-
throw new TypeError "Invalid string passed to pluralize '#{word}'" unless word and word.length
|
56
|
-
|
57
|
-
unless word.indexOf('s') == word.length - 1
|
58
|
-
owl.pluralize word, count, plural
|
59
|
-
else
|
60
|
-
word
|
61
|
-
|
62
|
-
singularize: (word) ->
|
63
|
-
throw new TypeError "Invalid string passed to singularize '#{word}'" unless word and word.length
|
64
|
-
|
65
|
-
if word.lastIndexOf('s') == word.length - 1
|
66
|
-
word.substring 0, word.length - 1
|
67
|
-
else
|
68
|
-
word
|
69
|
-
|
70
|
-
initialize: ->
|
71
|
-
|
72
|
-
# Deprecated! Remove on 15/02/2014
|
73
|
-
# Set parent attribute and default nested route
|
74
|
-
# If you're using the associable plugin, this getter and setter will be overwritten!
|
75
|
-
# if @parent_resource
|
76
|
-
# Object.defineProperty @, "#{@parent_resource}_id", descriptors.parent_id
|
77
|
-
|
78
|
-
# Setup resource
|
79
|
-
resource_definition = {}
|
80
|
-
resource_definition = name: @resource if typeof @resource == 'string'
|
81
|
-
if typeof @resource == 'object'
|
82
|
-
# TODO deeper resource integration with record.coffee, and remove original reference
|
83
|
-
# To prevent reference lost and allow dinamic modification of resources
|
84
|
-
# we need to preserve the original reference
|
85
|
-
@resource.original_reference = @resource
|
86
|
-
|
87
|
-
resource_definition = @resource
|
88
|
-
|
89
|
-
# TODO remove mentions of @parent_resource and use only resource: {parent: ...}
|
90
|
-
resource_definition.parent = @parent_resource
|
91
|
-
|
92
|
-
@resource = resource resource_definition
|
93
|
-
|
94
|
-
# TODO Support route parsing, and change route to /parents/:id/childrens
|
95
|
-
@route ? Object.defineProperty @, 'route', descriptors.route
|
96
|
-
|
97
|
-
|
98
|
-
# Extend indemma
|
99
|
-
model = window.model # TODO better way to get parent
|
100
|
-
|
101
|
-
model.mix (modelable) ->
|
102
|
-
modelable.record.after_initialize.unshift resourceable.initialize
|
103
|
-
modelable.after_mix.unshift resourceable.initialize
|
104
|
-
|
105
|
-
model.singularize = resourceable.singularize
|
106
|
-
model.pluralize = resourceable.pluralize
|
@@ -1,28 +0,0 @@
|
|
1
|
-
$ = require 'jquery'
|
2
|
-
|
3
|
-
module.exports =
|
4
|
-
# TODO render route in the object itself with getter, and normalize this methods
|
5
|
-
get : (data) -> request.call @, 'get' , (if @_id then "#{@route}/#{@_id}" else @route), data
|
6
|
-
put : (data) -> request.call @, 'put' , (if @_id then "#{@route}/#{@_id}" else @route), data # TODO change from put to patch
|
7
|
-
post : (data) -> request.call @, 'post' , @route, data
|
8
|
-
delete: (data) -> request.call @, 'delete', (if @_id then "#{@route}/#{@_id}" else @route), data
|
9
|
-
|
10
|
-
request = (method, url, data) ->
|
11
|
-
param_name = @resource.param_name || @resource.toString()
|
12
|
-
|
13
|
-
# TODO optmize this serialization lookup
|
14
|
-
if not data and @json
|
15
|
-
data = {}
|
16
|
-
data[param_name] = @json()
|
17
|
-
|
18
|
-
if data and data[param_name]
|
19
|
-
delete data[param_name]['id']
|
20
|
-
delete data[param_name]['_id']
|
21
|
-
|
22
|
-
|
23
|
-
$.ajax
|
24
|
-
url : url
|
25
|
-
data : data
|
26
|
-
type : method
|
27
|
-
dataType: 'json'
|
28
|
-
context : @
|