graph_starter 0.12.5 → 0.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 46724f458f7aaf3d0444f7f15b35252a61941ee6
4
- data.tar.gz: 2a66cbb3406a49ba1064385932c94447ff7b28d3
3
+ metadata.gz: 8d1fa716435b1f5c2cbc5429b1dd9567651de86b
4
+ data.tar.gz: 4dd99e0d6f47c5d9591f2886060b199abf50a50f
5
5
  SHA512:
6
- metadata.gz: 78c387e83a2e2f0971fa1090152bb866a16f9fe7d8ad0a312610a82de582830cd14cdefa38055b0ebe55bed9f1001380c16da67d72618f93de2234b132ff8250
7
- data.tar.gz: 81b041fa06e79b9a0f3147ba97ce97e8aa923b07dadafcf2ed1c77cc334d8648c826362d5c54f00430f69f629e6f61826ce77c65cdcb55b36d5e731b015af271
6
+ metadata.gz: 8ad2a74e69e199ffdf7c32ca23fd2b8a0911f46ff47a74e49a36b5378aaaba3eab04bae3d7d9050cbbff99124c259290cf9492af6d8e444945ee84db36f32ddf
7
+ data.tar.gz: 1c54c2ae4913e699723a8b375be7b9a78aae8752458cbf7fff82e77d44521ab081f3f456b2b5ee1e289a15795acef8db3bc05c83fb912afbeedfb9c0183c37e5
@@ -43,11 +43,7 @@ module GraphStarter
43
43
 
44
44
  scope = scope.limit(limit)
45
45
 
46
- scope = if associations.present?
47
- scope.query_as(var).with(var).proxy_as(model_class, var).with_associations(*associations)
48
- else
49
- scope
50
- end
46
+ scope = apply_associations(scope, var)
51
47
 
52
48
  scope
53
49
  end
@@ -122,7 +118,7 @@ module GraphStarter
122
118
  end
123
119
 
124
120
  def asset
125
- model_class_scope.where(uuid: params[:id]).to_a[0]
121
+ apply_associations(model_class_scope.where(uuid: params[:id])).to_a[0]
126
122
  end
127
123
 
128
124
  def asset_with_access_level
@@ -141,5 +137,23 @@ module GraphStarter
141
137
  model_class.all(var)
142
138
  end
143
139
  end
140
+
141
+ def associations
142
+ return @associations if @associations.present?
143
+
144
+ @associations = []
145
+ @associations << model_class.image_association
146
+ @associations += model_class.category_associations
147
+ @associations.compact!
148
+ @associations
149
+ end
150
+
151
+ def apply_associations(scope, var = :asset)
152
+ if associations.present?
153
+ scope.query_as(var).with(var).proxy_as(model_class, var).with_associations(*associations)
154
+ else
155
+ scope
156
+ end
157
+ end
144
158
  end
145
159
  end
@@ -27,5 +27,9 @@ module GraphStarter
27
27
  def app_user
28
28
  defined?(:current_user) ? current_user : nil
29
29
  end
30
+
31
+ def missing_image_tag
32
+ @missing_image_tag ||= image_tag 'missing'
33
+ end
30
34
  end
31
35
  end
@@ -263,16 +263,18 @@ module GraphStarter
263
263
  end
264
264
  end
265
265
 
266
- def as_json(_options = {})
267
- {self.class.model_slug =>
268
- {id: id,
269
- title: title,
270
- name: title,
271
- model_slug: self.class.model_slug}
272
- }.tap do |result|
273
- result[:images] = images.map {|image| image.source.url } if self.class.has_images?
274
- result[:image] = image.source_url if self.class.has_image? && image
275
- end
266
+ def as_json(options = {})
267
+ data = {
268
+ id: id,
269
+ title: title,
270
+ name: title,
271
+ model_slug: self.class.model_slug
272
+ }.tap do |result|
273
+ result[:images] = images.map {|image| image.source.url } if self.class.has_images?
274
+ result[:image] = image.source_url if self.class.has_image? && image
275
+ end
276
+
277
+ options[:root] ? {self.class.model_slug.singularize => data} : data
276
278
  end
277
279
 
278
280
  def views
@@ -9,7 +9,7 @@
9
9
  - if asset.first_image_source_url.present?
10
10
  = image_tag asset.first_image_source_url
11
11
  - else
12
- = image_tag 'missing'
12
+ = missing_image_tag
13
13
  - categories = Array(asset.categories).sort_by(&:name)
14
14
  - if categories.present?
15
15
  .content
@@ -0,0 +1,11 @@
1
+ @asset.class.authorized_properties(current_user).each do |property|
2
+ json.set! property.name, @asset.read_attribute(property.name)
3
+ end
4
+
5
+
6
+ json.associations do
7
+ @asset.class.authorized_associations.each do |name, association|
8
+ json.set! name, @asset.send(name).to_a
9
+ end
10
+ end
11
+
data/config/routes.rb CHANGED
@@ -22,7 +22,7 @@ GraphStarter::Engine.routes.draw do
22
22
  get ':model_slug/new' => 'assets#new', as: :new_asset
23
23
  post ':model_slug' => 'assets#create', as: :create_asset
24
24
 
25
- get ':model_slug/:id' => 'assets#show', as: :asset
25
+ get ':model_slug/:id(.:format)' => 'assets#show', as: :asset
26
26
  get ':model_slug/:id/edit' => 'assets#edit', as: :edit_asset
27
27
  put ':model_slug/:id/rate(/:new_rating)' => 'assets#rate', as: :rate_asset
28
28
  get ':model_slug/search/:query.json' => 'assets#search', as: :search_assets
@@ -1,3 +1,3 @@
1
1
  module GraphStarter
2
- VERSION = "0.12.5"
2
+ VERSION = "0.13.0"
3
3
  end
@@ -20,7 +20,7 @@ module Dummy
20
20
  # config.i18n.default_locale = :de
21
21
 
22
22
  # Do not swallow errors in after_commit/after_rollback callbacks.
23
- config.active_record.raise_in_transactional_callbacks = true
23
+ config.neo4j.include_root_in_json = false
24
24
  end
25
25
  end
26
26
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: graph_starter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.5
4
+ version: 0.13.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Underwood
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-18 00:00:00.000000000 Z
11
+ date: 2015-11-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 6.0.0.alpha
33
+ version: 6.0.0.rc
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 6.0.0.alpha
40
+ version: 6.0.0.rc
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: semantic-ui-sass
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -150,6 +150,7 @@ files:
150
150
  - app/views/graph_starter/assets/index.html.slim
151
151
  - app/views/graph_starter/assets/new.html.slim
152
152
  - app/views/graph_starter/assets/show.html.slim
153
+ - app/views/graph_starter/assets/show.json.jbuilder
153
154
  - app/views/graph_starter/authorizables/show.json.jbuilder
154
155
  - app/views/graph_starter/authorizables/user_and_group_search.json.jbuilder
155
156
  - app/views/graph_starter/categories/show.html.slim