summaryrefslogtreecommitdiff
path: root/app/serializers
diff options
context:
space:
mode:
authorDouwe Maan <douwe@selenight.nl>2017-05-26 13:51:24 -0500
committerDouwe Maan <douwe@selenight.nl>2017-05-26 13:51:24 -0500
commit2ae9c890e7037ec13b1882fda9ab90fc73f04fcc (patch)
tree1cb909e5ed6d9e3450d2d0e214d02a97981c97d2 /app/serializers
parent33b622e353ba244ac62e61b6db0e382275ca905c (diff)
downloadgitlab-ce-2ae9c890e7037ec13b1882fda9ab90fc73f04fcc.tar.gz
Add experimental JSON format for tree controller
Diffstat (limited to 'app/serializers')
-rw-r--r--app/serializers/blob_entity.rb13
-rw-r--r--app/serializers/submodule_entity.rb23
-rw-r--r--app/serializers/tree_entity.rb13
-rw-r--r--app/serializers/tree_root_entity.rb8
-rw-r--r--app/serializers/tree_serializer.rb3
5 files changed, 60 insertions, 0 deletions
diff --git a/app/serializers/blob_entity.rb b/app/serializers/blob_entity.rb
new file mode 100644
index 00000000000..f05416be65b
--- /dev/null
+++ b/app/serializers/blob_entity.rb
@@ -0,0 +1,13 @@
+class BlobEntity < Grape::Entity
+ include RequestAwareEntity
+
+ expose :id, :path, :name, :mode
+
+ expose :icon do |blob|
+ IconsHelper.file_type_icon_class('file', blob.mode, blob.name)
+ end
+
+ expose :url do |blob|
+ namespace_project_blob_path(request.project.namespace, request.project, File.join(request.ref, blob.path))
+ end
+end
diff --git a/app/serializers/submodule_entity.rb b/app/serializers/submodule_entity.rb
new file mode 100644
index 00000000000..9a7eb5e7880
--- /dev/null
+++ b/app/serializers/submodule_entity.rb
@@ -0,0 +1,23 @@
+class SubmoduleEntity < Grape::Entity
+ include RequestAwareEntity
+
+ expose :id, :path, :name, :mode
+
+ expose :icon do |blob|
+ 'archive'
+ end
+
+ expose :project_url do |blob|
+ submodule_links(blob, request).first
+ end
+
+ expose :tree_url do |blob|
+ submodule_links(blob, request).last
+ end
+
+ private
+
+ def submodule_links(blob, request)
+ @submodule_links ||= SubmoduleHelper.submodule_links(blob, request.ref, request.repository)
+ end
+end
diff --git a/app/serializers/tree_entity.rb b/app/serializers/tree_entity.rb
new file mode 100644
index 00000000000..e7d3dc38571
--- /dev/null
+++ b/app/serializers/tree_entity.rb
@@ -0,0 +1,13 @@
+class TreeEntity < Grape::Entity
+ include RequestAwareEntity
+
+ expose :id, :path, :name, :mode
+
+ expose :icon do |tree|
+ IconsHelper.file_type_icon_class('folder', tree.mode, tree.name)
+ end
+
+ expose :url do |tree|
+ namespace_project_tree_path(request.project.namespace, request.project, File.join(request.ref, tree.path))
+ end
+end
diff --git a/app/serializers/tree_root_entity.rb b/app/serializers/tree_root_entity.rb
new file mode 100644
index 00000000000..23b65aa4a4c
--- /dev/null
+++ b/app/serializers/tree_root_entity.rb
@@ -0,0 +1,8 @@
+# TODO: Inherit from TreeEntity, when `Tree` implements `id` and `name` like `Gitlab::Git::Tree`.
+class TreeRootEntity < Grape::Entity
+ expose :path
+
+ expose :trees, using: TreeEntity
+ expose :blobs, using: BlobEntity
+ expose :submodules, using: SubmoduleEntity
+end
diff --git a/app/serializers/tree_serializer.rb b/app/serializers/tree_serializer.rb
new file mode 100644
index 00000000000..713ade23bc9
--- /dev/null
+++ b/app/serializers/tree_serializer.rb
@@ -0,0 +1,3 @@
+class TreeSerializer < BaseSerializer
+ entity TreeRootEntity
+end