neo4j-meta_model 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/README.rdoc +19 -2
  3. data/app/assets/javascripts/meta_model.js.coffee +132 -130
  4. data/app/controllers/neo4j/meta_model/application_controller.rb +14 -0
  5. data/app/controllers/neo4j/meta_model/meta/has_associations_controller.rb +46 -0
  6. data/app/controllers/neo4j/meta_model/meta/models_controller.rb +82 -0
  7. data/app/controllers/neo4j/meta_model/meta/properties_controller.rb +38 -0
  8. data/app/controllers/neo4j/meta_model/meta_controller.rb +9 -0
  9. data/app/controllers/neo4j/meta_model/models_controller.rb +71 -0
  10. data/app/helpers/neo4j/meta_model/application_helper.rb +12 -0
  11. data/app/helpers/neo4j/meta_model/model_helper.rb +12 -0
  12. data/app/models/concerns/neo4j/meta_model/model_base.rb +45 -0
  13. data/app/models/neo4j/meta_model/has_association.rb +48 -0
  14. data/app/models/neo4j/meta_model/meta_model_base.rb +9 -0
  15. data/app/models/neo4j/meta_model/model.rb +53 -0
  16. data/app/models/neo4j/meta_model/property.rb +13 -0
  17. data/app/serializers/neo4j/meta_model/has_association_serializer.rb +15 -0
  18. data/app/serializers/neo4j/meta_model/model_serializer.rb +13 -0
  19. data/app/serializers/neo4j/meta_model/property_serializer.rb +8 -0
  20. data/app/views/{meta_model → neo4j/meta_model}/meta/associations/index.html.slim +0 -0
  21. data/app/views/{meta_model → neo4j/meta_model}/meta/index.html.slim +0 -0
  22. data/app/views/{meta_model → neo4j/meta_model}/meta/models/edit.html.slim +0 -0
  23. data/app/views/{meta_model → neo4j/meta_model}/models/_form.html.slim +16 -8
  24. data/app/views/{meta_model → neo4j/meta_model}/models/_has_many_association.html.slim +0 -0
  25. data/app/views/{meta_model → neo4j/meta_model}/models/_record_details.html.slim +0 -0
  26. data/app/views/{meta_model → neo4j/meta_model}/models/edit.html.slim +0 -0
  27. data/app/views/{meta_model → neo4j/meta_model}/models/index.html.slim +0 -0
  28. data/app/views/{meta_model → neo4j/meta_model}/models/meta_index.html.slim +0 -0
  29. data/app/views/{meta_model → neo4j/meta_model}/models/new.html.slim +0 -0
  30. data/app/views/{meta_model → neo4j/meta_model}/models/show.html.slim +0 -0
  31. data/config/routes.rb +1 -1
  32. data/lib/meta_models.rb +9 -7
  33. data/lib/neo4j/meta_model.rb +6 -0
  34. data/lib/neo4j/meta_model/engine.rb +25 -0
  35. data/lib/neo4j/meta_model/version.rb +5 -0
  36. data/test/dummy/config/application.rb +1 -1
  37. metadata +31 -31
  38. data/app/controllers/meta_model/application_controller.rb +0 -12
  39. data/app/controllers/meta_model/meta/has_associations_controller.rb +0 -44
  40. data/app/controllers/meta_model/meta/models_controller.rb +0 -80
  41. data/app/controllers/meta_model/meta/properties_controller.rb +0 -36
  42. data/app/controllers/meta_model/meta_controller.rb +0 -7
  43. data/app/controllers/meta_model/models_controller.rb +0 -69
  44. data/app/helpers/meta_model/application_helper.rb +0 -10
  45. data/app/helpers/meta_model/model_helper.rb +0 -10
  46. data/app/models/concerns/meta_model/model_base.rb +0 -43
  47. data/app/models/meta_model/has_association.rb +0 -46
  48. data/app/models/meta_model/meta_model_base.rb +0 -7
  49. data/app/models/meta_model/model.rb +0 -51
  50. data/app/models/meta_model/property.rb +0 -11
  51. data/app/serializers/meta_model/has_association_serializer.rb +0 -13
  52. data/app/serializers/meta_model/model_serializer.rb +0 -11
  53. data/app/serializers/meta_model/property_serializer.rb +0 -6
  54. data/lib/meta_model.rb +0 -4
  55. data/lib/meta_model/engine.rb +0 -23
  56. data/lib/meta_model/version.rb +0 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 07e1c07aba0b7ca1af37de940a7360a857b2a694
4
- data.tar.gz: 653df4a5130509b8dae8d9c92a1b3a24f85ba7e0
3
+ metadata.gz: d8b58308204208e41b5480533cd4b4c6baa76fb2
4
+ data.tar.gz: 8899b11af6fb6c6e6f43f84782b7c5a3ac27dc10
5
5
  SHA512:
6
- metadata.gz: 25a6f101b7448a6978dddc5bbaa8c1f7120b8b1c457827d2fae70ae0e8357ded94d4173ab0ff0eace99874fc9eed83bfafe1f7c7b342d3c8fbc2f95d8d4c5461
7
- data.tar.gz: ab92afb8847b05562a909efe8f69211081317ef0a1dca17de257de878a291ad9c477a78ff1f9194d4c6e88f435fdb2ec90c6fa0c6b7afdfc9932283674e4c99a
6
+ metadata.gz: b79e053021ca2485262eaa9fe9a651c4fca420f552f913142a8f0265b65bcedc24232ba27fb1bd33e8ebc279c7c6eed8d74cbcdb79f4a3f3f53c6089b474d3d3
7
+ data.tar.gz: a987b60db44c01677e618803b852a0c3c993cdf73f995bb2fee2da0e47b8de1cb6c7caf867dbaabbbf434307f5e69427fa632f1165506e3e96eb7440436869bd
@@ -1,3 +1,20 @@
1
- = MetaModel
1
+ = Neo4j MetaModel
2
2
 
3
- This project rocks and uses MIT-LICENSE.
3
+ == Usage
4
+
5
+ `Gemfile`
6
+
7
+ gem 'neo4j-meta_model', require: 'neo4j/meta_model'
8
+
9
+ In your environment (`config/application.rb` or `config/environments/development.rb` for example)
10
+
11
+ config.neo4j.session_type = :server_db
12
+ config.neo4j.session_path = 'http://localhost:7474'
13
+
14
+ `config/routes.rb`
15
+
16
+ mount Neo4j::MetaModel::Engine => "/mount/path"
17
+
18
+
19
+
20
+ This project rocks and uses MIT-LICENSE.
@@ -33,185 +33,187 @@ mm_path = (path) ->
33
33
 
34
34
  base_path + '/' + p
35
35
 
36
+ ready = ->
37
+ if $('#ember-application').length
38
+ # for more details see: http://emberjs.com/guides/application/
39
+ window.MetaModel = Ember.Application.create(rootElement: '#ember-application')
36
40
 
37
- # for more details see: http://emberjs.com/guides/application/
38
- #window.MetaModel = Ember.Application.create(rootElement: '#ember-application')
41
+ MetaModel.ApplicationController = Ember.Controller.extend()
39
42
 
40
- MetaModel.ApplicationController = Ember.Controller.extend()
43
+ MetaModel.Model = DS.Model.extend()
41
44
 
42
- MetaModel.Model = DS.Model.extend()
45
+ console.log {path: mm_path('meta')[1..-1]}
46
+ MetaModel.MetaModelAdapter = DS.RESTAdapter.extend
47
+ namespace: mm_path('meta')[1..-1]
43
48
 
44
- console.log {path: mm_path('meta')[1..-1]}
45
- MetaModel.MetaModelAdapter = DS.RESTAdapter.extend
46
- namespace: mm_path('meta')[1..-1]
49
+ MetaModel.ModelAdapter = MetaModel.MetaModelAdapter.extend()
50
+ MetaModel.PropertyAdapter = MetaModel.MetaModelAdapter.extend()
47
51
 
48
- MetaModel.ModelAdapter = MetaModel.MetaModelAdapter.extend()
49
- MetaModel.PropertyAdapter = MetaModel.MetaModelAdapter.extend()
52
+ MetaModel.HasAssociationAdapter = MetaModel.MetaModelAdapter.extend
53
+ buildURL: (type, id, record) ->
54
+ result = "/meta/has_associations"
55
+ result += "/#{id}" if id
56
+ mm_path result
50
57
 
51
- MetaModel.HasAssociationAdapter = MetaModel.MetaModelAdapter.extend
52
- buildURL: (type, id, record) ->
53
- result = "/meta/has_associations"
54
- result += "/#{id}" if id
55
- mm_path result
56
58
 
59
+ MetaModel.Router.map ->
60
+ @route 'index', path: "/"
57
61
 
58
- MetaModel.Router.map ->
59
- @route 'index', path: "/"
62
+ @resource 'models', path: '/models', ->
63
+ @route 'hierarchy', path: "/"
64
+ @route 'edit', path: "/:class_name/edit"
60
65
 
61
- @resource 'models', path: '/models', ->
62
- @route 'hierarchy', path: "/"
63
- @route 'edit', path: "/:class_name/edit"
66
+ @resource 'has_associations', ->
67
+ @route 'index', path: '/'
68
+ @route 'new', path: '/new'
64
69
 
65
- @resource 'has_associations', ->
66
- @route 'index', path: '/'
67
- @route 'new', path: '/new'
68
70
 
69
71
 
72
+ MetaModel.ApplicationAdapter = DS.ActiveModelAdapter.extend()
70
73
 
71
- MetaModel.ApplicationAdapter = DS.ActiveModelAdapter.extend()
74
+ MetaModel.ApplicationSerializer = DS.ActiveModelSerializer.extend()
72
75
 
73
- MetaModel.ApplicationSerializer = DS.ActiveModelSerializer.extend()
76
+ # Components
74
77
 
75
- # Components
78
+ MetaModel.FocusInputComponent = Ember.TextField.extend
79
+ becomeFocused: (->
80
+ @$().focus()
81
+ ).on('didInsertElement')
76
82
 
77
- MetaModel.FocusInputComponent = Ember.TextField.extend
78
- becomeFocused: (->
79
- @$().focus()
80
- ).on('didInsertElement')
81
83
 
82
84
 
85
+ MetaModel.ModelListItemComponent = Ember.Component.extend
86
+ action: 'meta_model_clicked'
87
+ actions:
88
+ clicked: ->
89
+ @sendAction 'action', @get('model')
90
+ goto_metamodel: (model) ->
91
+ @sendAction 'action', model
83
92
 
84
- MetaModel.ModelListItemComponent = Ember.Component.extend
85
- action: 'meta_model_clicked'
86
- actions:
87
- clicked: ->
88
- @sendAction 'action', @get('model')
89
- goto_metamodel: (model) ->
90
- @sendAction 'action', model
93
+ MetaModel.ModelListComponent = Ember.Component.extend
94
+ action: 'goto_metamodel'
95
+ actions:
96
+ meta_model_clicked: (model) ->
97
+ @sendAction 'action', model
91
98
 
92
- MetaModel.ModelListComponent = Ember.Component.extend
93
- action: 'goto_metamodel'
94
- actions:
95
- meta_model_clicked: (model) ->
96
- @sendAction 'action', model
97
99
 
100
+ # Models
98
101
 
99
- # Models
102
+ MetaModel.Property = DS.Model.extend
103
+ name: DS.attr 'string'
104
+ type: DS.attr 'string'
105
+ model: DS.belongsTo 'Model', inverse: 'properties'
100
106
 
101
- MetaModel.Property = DS.Model.extend
102
- name: DS.attr 'string'
103
- type: DS.attr 'string'
104
- model: DS.belongsTo 'Model', inverse: 'properties'
107
+ MetaModel.Model = DS.Model.extend
108
+ class_name: DS.attr 'string'
109
+ superclass_model: DS.belongsTo 'Model'
110
+ #superclass_model: DS.attr 'string'
111
+ properties: DS.hasMany 'Property'
112
+ source_has_associations: DS.hasMany 'HasAssociation', inverse: 'to_model'
113
+ destination_has_associations: DS.hasMany 'HasAssociation', inverse: 'from_model'
105
114
 
106
- MetaModel.Model = DS.Model.extend
107
- class_name: DS.attr 'string'
108
- superclass_model: DS.belongsTo 'Model'
109
- #superclass_model: DS.attr 'string'
110
- properties: DS.hasMany 'Property'
111
- source_has_associations: DS.hasMany 'HasAssociation', inverse: 'to_model'
112
- destination_has_associations: DS.hasMany 'HasAssociation', inverse: 'from_model'
115
+ MetaModel.HasAssociation = DS.Model.extend
116
+ join_type: DS.attr 'string'
117
+ name: DS.attr 'string'
118
+ opposite_name: DS.attr 'string'
119
+ relationship_type: DS.attr 'string'
120
+ from_model: DS.belongsTo 'Model', async: true
121
+ to_model: DS.belongsTo 'Model', async: true
113
122
 
114
- MetaModel.HasAssociation = DS.Model.extend
115
- join_type: DS.attr 'string'
116
- name: DS.attr 'string'
117
- opposite_name: DS.attr 'string'
118
- relationship_type: DS.attr 'string'
119
- from_model: DS.belongsTo 'Model', async: true
120
- to_model: DS.belongsTo 'Model', async: true
123
+ source_join_type: (->
124
+ @get('join_type')?.split('_to_')[0]
125
+ ).property('join_type')
121
126
 
122
- source_join_type: (->
123
- @get('join_type')?.split('_to_')[0]
124
- ).property('join_type')
127
+ destination_join_type: (->
128
+ @get('join_type')?.split('_to_')[1]
129
+ ).property('join_type')
125
130
 
126
- destination_join_type: (->
127
- @get('join_type')?.split('_to_')[1]
128
- ).property('join_type')
131
+ source_is_defined: (->
132
+ @get('source_join_type') and @get('from_model')
133
+ ).property('source_join_type', 'from_model')
129
134
 
130
- source_is_defined: (->
131
- @get('source_join_type') and @get('from_model')
132
- ).property('source_join_type', 'from_model')
135
+ destination_is_defined: (->
136
+ @get('destination_join_type') and @get('to_model')
137
+ ).property('destination_join_type', 'to_model')
133
138
 
134
- destination_is_defined: (->
135
- @get('destination_join_type') and @get('to_model')
136
- ).property('destination_join_type', 'to_model')
139
+ models_are_defined: (->
140
+ @get('from_model') and @get('to_model')
141
+ ).property('from_model', 'to_model')
137
142
 
138
- models_are_defined: (->
139
- @get('from_model') and @get('to_model')
140
- ).property('from_model', 'to_model')
141
143
 
144
+ standardize_relationship_type: (->
145
+ @set 'relationship_type', @get('relationship_type').toLowerCase().replace(/[^a-z0-9]+/g, '_')
146
+ ).observes('relationship_type')
142
147
 
143
- standardize_relationship_type: (->
144
- @set 'relationship_type', @get('relationship_type').toLowerCase().replace(/[^a-z0-9]+/g, '_')
145
- ).observes('relationship_type')
146
148
 
149
+ # Routes / Controllers
147
150
 
148
- # Routes / Controllers
149
151
 
152
+ MetaModel.ModelsHierarchyRoute = Ember.Route.extend
153
+ model: ->
154
+ Ember.$.getJSON(mm_path '/meta/models/hierarchy.json').then (data) ->
155
+ data.models
156
+ actions:
157
+ goto_metamodel: (model) ->
158
+ @transitionTo 'models.edit', model.class_name
150
159
 
151
- MetaModel.ModelsHierarchyRoute = Ember.Route.extend
152
- model: ->
153
- Ember.$.getJSON(mm_path '/meta/models/hierarchy.json').then (data) ->
154
- data.models
155
- actions:
156
- goto_metamodel: (model) ->
157
- @transitionTo 'models.edit', model.class_name
158
160
 
161
+ MetaModel.ModelsHierarchyController = Ember.Controller.extend
162
+ new_model_name: ''
159
163
 
160
- MetaModel.ModelsHierarchyController = Ember.Controller.extend
161
- new_model_name: ''
164
+ actions:
165
+ add: (class_name) ->
166
+ @store.createRecord('model', class_name: @new_model_name).save().then (record) =>
167
+ @transitionToRoute 'models.edit', queryParams: class_name: record.class_name
162
168
 
163
- actions:
164
- add: (class_name) ->
165
- @store.createRecord('model', class_name: @new_model_name).save().then (record) =>
166
- @transitionToRoute 'models.edit', queryParams: class_name: record.class_name
167
169
 
170
+ MetaModel.ModelsEditRoute = Ember.Route.extend
171
+ model: (params) ->
172
+ Ember.RSVP.hash
173
+ model: @store.find 'model', params.class_name
174
+ models: @store.find 'model'
175
+ property_types: ['String', 'DateTime']
168
176
 
169
- MetaModel.ModelsEditRoute = Ember.Route.extend
170
- model: (params) ->
171
- Ember.RSVP.hash
172
- model: @store.find 'model', params.class_name
173
- models: @store.find 'model'
174
- property_types: ['String', 'DateTime']
177
+ actions:
178
+ add_property: (model) ->
179
+ property = model.get('properties').createRecord name: '', type: 'String', model_id: model.id
180
+ property.save()
175
181
 
176
- actions:
177
- add_property: (model) ->
178
- property = model.get('properties').createRecord name: '', type: 'String', model_id: model.id
179
- property.save()
182
+ delete_property: (property) ->
183
+ property.destroyRecord()
180
184
 
181
- delete_property: (property) ->
182
- property.destroyRecord()
185
+ save: (model) ->
186
+ model.save() #if model.get 'isDirty'
187
+ model.get('properties').forEach (property) ->
188
+ property.save() if property.get 'isDirty'
183
189
 
184
- save: (model) ->
185
- model.save() #if model.get 'isDirty'
186
- model.get('properties').forEach (property) ->
187
- property.save() if property.get 'isDirty'
190
+ delete: (model) ->
191
+ model.destroyRecord().then =>
192
+ @transitionTo 'models.hierarchy'
188
193
 
189
- delete: (model) ->
190
- model.destroyRecord().then =>
191
- @transitionTo 'models.hierarchy'
194
+ MetaModel.HasAssociationsIndexRoute = Ember.Route.extend
195
+ model: (params) ->
196
+ @store.find 'has_association'
192
197
 
193
- MetaModel.HasAssociationsIndexRoute = Ember.Route.extend
194
- model: (params) ->
195
- @store.find 'has_association'
198
+ actions:
199
+ delete: (has_association) ->
200
+ has_association.destroyRecord()
196
201
 
197
- actions:
198
- delete: (has_association) ->
199
- has_association.destroyRecord()
200
202
 
201
203
 
204
+ MetaModel.HasAssociationsNewRoute = Ember.Route.extend
205
+ model: (params) ->
206
+ Ember.RSVP.hash
207
+ has_association: @store.createRecord 'has_association'
208
+ models: @store.find 'model'
209
+ join_types: ['one_to_many', 'many_to_one', 'many_to_many']
202
210
 
203
- MetaModel.HasAssociationsNewRoute = Ember.Route.extend
204
- model: (params) ->
205
- Ember.RSVP.hash
206
- has_association: @store.createRecord 'has_association'
207
- models: @store.find 'model'
208
- join_types: ['one_to_many', 'many_to_one', 'many_to_many']
209
-
210
- actions:
211
- create: (has_association) ->
212
- console.log 'create!'
213
- has_association.save().then (record) =>
214
- @transitionToRoute 'has_associations.index'
215
-
211
+ actions:
212
+ create: (has_association) ->
213
+ console.log 'create!'
214
+ has_association.save().then (record) =>
215
+ @transitionToRoute 'has_associations.index'
216
216
 
217
217
 
218
+ $(document).ready ready
219
+ $(document).on 'page:load', ready
@@ -0,0 +1,14 @@
1
+ require 'meta_models.rb'
2
+ create_models
3
+
4
+ module Neo4j
5
+ module MetaModel
6
+ class ApplicationController < ::ApplicationController
7
+ protect_from_forgery with: :exception
8
+
9
+ helper Neo4j::MetaModel::Engine.helpers
10
+
11
+ layout 'layouts/meta_model'
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,46 @@
1
+ module Neo4j
2
+ module MetaModel
3
+ module Meta
4
+ class HasAssociationsController < ApplicationController
5
+ before_action :get_has_association, only: [:edit, :show, :update, :destroy]
6
+
7
+ def index
8
+ render json: HasAssociation.all
9
+ end
10
+
11
+ def show
12
+ respond_to do |format|
13
+ format.json { render json: @has_association }
14
+ end
15
+ end
16
+
17
+ def create
18
+ has_association = HasAssociation.create(has_association_params)
19
+
20
+ create_models
21
+
22
+ render json: has_association
23
+ end
24
+
25
+ def destroy
26
+ @has_association.destroy
27
+
28
+ create_models
29
+
30
+ render json: nil
31
+ end
32
+
33
+
34
+ private
35
+
36
+ def get_has_association
37
+ @has_association = HasAssociation.find(params[:id])
38
+ end
39
+
40
+ def has_association_params
41
+ params.require(:has_association).permit(:join_type, :name, :opposite_name, :relationship_type, :from_model_id, :to_model_id)
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,82 @@
1
+ module Neo4j
2
+ module MetaModel
3
+ module Meta
4
+ class ModelsController < ApplicationController
5
+ before_action :get_model, only: [:edit, :show, :update, :destroy]
6
+
7
+ def index
8
+ respond_to do |format|
9
+ format.html { @hierarchy = Model.all.hierarchically }
10
+ format.json { render json: Model.all }
11
+ end
12
+ end
13
+
14
+ def hierarchy
15
+ respond_to do |format|
16
+ format.json { render json: Model.all.hierarchically }
17
+ end
18
+ end
19
+
20
+ def show
21
+ respond_to do |format|
22
+ format.json do
23
+ render json: @model
24
+ end
25
+ end
26
+ end
27
+
28
+ def edit
29
+ @models = Model.all.order(:name)
30
+ end
31
+
32
+ def create
33
+ model = Model.create(model_params)
34
+
35
+ create_models
36
+
37
+ render json: model
38
+ end
39
+
40
+ def update
41
+ model_params.each do |key, value|
42
+ @model.send("#{key}=", value)
43
+ end
44
+ @model.save
45
+
46
+ create_models
47
+
48
+ render json: @model
49
+ end
50
+
51
+ def destroy
52
+ @model.destroy
53
+
54
+ create_models
55
+
56
+ render json: nil
57
+ end
58
+
59
+ private
60
+
61
+ def get_model
62
+ @model = if model_param_class_name
63
+ Model.where(class_name: model_param_class_name).first
64
+ end || Model.find(params[:id])
65
+ end
66
+
67
+ def model_param_class_name
68
+ if params[:id]
69
+ @model_param_class_name ||= params[:id].classify
70
+ end
71
+ rescue NameError
72
+ end
73
+
74
+ def model_params
75
+ superclass_model = params[:model].delete(:superclass_model_id)
76
+ params.require(:model).permit(:class_name, :superclass_model).merge(superclass_model: superclass_model)
77
+ end
78
+ end
79
+ end
80
+ end
81
+
82
+ end