hyperdock 0.17.2 → 0.18.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 63871912a12abea8df840ea5747142414eb862bb
4
- data.tar.gz: db21f72589316c54a6561faee46f38d4a5ee7397
3
+ metadata.gz: 7ec46235f6d4db465a60a6138f72e744a9d670c4
4
+ data.tar.gz: 03f86a66ba6899cc5f9a44efa2579939c09c61d0
5
5
  SHA512:
6
- metadata.gz: 0273ce7bca9f7e48c82a28eec8a952e3a7f81ae5ef2d25cdce82cb519a5fb1b520872da40d6a76f54b312fd76c133336a6d80d7d8ee2170bb79954979f26007d
7
- data.tar.gz: a70acebd9544318667c372436026b4f184de1cbc2247e4db518a2882327cfd5f92d57123ba61a433cba2290b2639dfc026f755462dbe1320b497d443aed64dd9
6
+ metadata.gz: 58621532d09f16fda798cca212beeb99f156c27103f4127b4e61b6deaa7cadbaa2391a4bcf6512deebf40aea97bf09f5745f9250bd75aeae21830709e496d162
7
+ data.tar.gz: 2acad595e0becd32c96c5b328e15819e811f973401d0cc0028c177eeb09b62c185caf552bf6898f5f973b2a3e80cf0424a952cd6a65e58ca0e3cf9d1c00b8901
@@ -7,7 +7,6 @@ Webmachine.application.routes do
7
7
  add [], HyperDock::Resource::Root
8
8
  add ['projects'], HyperDock::Resource::Projects
9
9
  add ['project', :project], HyperDock::Resource::Project
10
- add ['project', :project, 'services'], HyperDock::Resource::ProjectServices
11
10
  add ['project', :project, 'service', :service], HyperDock::Resource::ProjectService
12
11
  add ['containers'], HyperDock::Resource::Containers
13
12
  add ['container', :container], HyperDock::Resource::Container
@@ -4,22 +4,52 @@ require_relative 'core'
4
4
  module HyperDock
5
5
  module Resource
6
6
  class Project < Core
7
- Contract None => ArrayOf[String]
8
- def projects
9
- @projects ||= ::Docker::Container.all.map do |container|
10
- container.info.dig 'Labels', 'com.docker.compose.project'
7
+ Contract None => String
8
+ def project
9
+ @project ||= request.path_info[:project]
10
+ end
11
+
12
+ Contract None => ArrayOf[::Docker::Container]
13
+ def containers
14
+ @containers ||= ::Docker::Container.all.select do |container|
15
+ container.info.dig('Labels', 'com.docker.compose.project') == project
11
16
  end
12
17
  end
13
18
 
14
19
  Contract None => Bool
15
20
  def resource_exists?
16
- projects.include? request.path_info[:project]
21
+ !containers.empty?
22
+ end
23
+
24
+ Contract None => ArrayOf[String]
25
+ def services
26
+ @services ||= containers.map do |container|
27
+ container.info.dig('Labels', 'com.docker.compose.service')
28
+ end.uniq
29
+ end
30
+
31
+ Contract None => ArrayOf[Hash]
32
+ def service_links
33
+ @service_links ||= services.map do |service|
34
+ { name: service, href: "/project/#{project}/service/#{service}" }
35
+ end
36
+ end
37
+
38
+ Contract None => Hash
39
+ def named_links
40
+ @named_links ||= service_links.map do |service|
41
+ { "service:#{service[:name]}" => service }
42
+ end.reduce(&:merge)
17
43
  end
18
44
 
19
45
  def links
20
46
  @links ||= {
21
- services: { href: "/#{request.disp_path}/services" }
22
- }
47
+ services: service_links
48
+ }.merge(named_links)
49
+ end
50
+
51
+ def attributes
52
+ { names: services }
23
53
  end
24
54
  end
25
55
  end
@@ -26,15 +26,32 @@ module HyperDock
26
26
  def containers
27
27
  @containers ||= ::Docker::Container.all.select do |container|
28
28
  matches_project?(container) && matches_service?(container)
29
- end.map(&:id)
29
+ end
30
+ end
31
+
32
+ def container_links
33
+ @container_links ||= containers.flat_map do |container|
34
+ # TODO: Determine how this should be presented.
35
+ [container.info.fetch('Names').first].map do |name|
36
+ { name: name, href: "/container/#{container.id}" }
37
+ end
38
+ end
39
+ end
40
+
41
+ def named_links
42
+ @named_links ||= container_links.map do |container|
43
+ { "container:#{container[:name]}" => container }
44
+ end.reduce(&:merge)
30
45
  end
31
46
 
32
47
  def links
33
48
  @links ||= {
34
- 'containers' => containers.map do |container|
35
- { href: "/container/#{container}" }
36
- end
37
- }
49
+ containers: container_links
50
+ }.merge(named_links)
51
+ end
52
+
53
+ def attributes
54
+ { name: service }
38
55
  end
39
56
  end
40
57
  end
@@ -5,7 +5,6 @@ require_relative 'resource/networks'
5
5
  require_relative 'resource/network'
6
6
  require_relative 'resource/project'
7
7
  require_relative 'resource/project_service'
8
- require_relative 'resource/project_services'
9
8
  require_relative 'resource/projects'
10
9
  require_relative 'resource/root'
11
10
  require_relative 'resource/volumes'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hyperdock
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.17.2
4
+ version: 0.18.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Olstrom
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-17 00:00:00.000000000 Z
11
+ date: 2016-08-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rakuna
@@ -91,7 +91,6 @@ files:
91
91
  - lib/hyperdock/resource/networks.rb
92
92
  - lib/hyperdock/resource/project.rb
93
93
  - lib/hyperdock/resource/project_service.rb
94
- - lib/hyperdock/resource/project_services.rb
95
94
  - lib/hyperdock/resource/projects.rb
96
95
  - lib/hyperdock/resource/root.rb
97
96
  - lib/hyperdock/resource/volume.rb
@@ -1,47 +0,0 @@
1
- require 'docker-api'
2
- require_relative 'core'
3
-
4
- module HyperDock
5
- module Resource
6
- class ProjectServices < Core
7
- Contract None => String
8
- def project
9
- @project ||= request.path_info[:project]
10
- end
11
-
12
- Contract None => ArrayOf[::Docker::Container]
13
- def containers
14
- @containers ||= ::Docker::Container.all.select do |container|
15
- container.info.dig('Labels', 'com.docker.compose.project') == project
16
- end
17
- end
18
-
19
- Contract None => Bool
20
- def resource_exists?
21
- !containers.empty?
22
- end
23
-
24
- Contract None => ArrayOf[String]
25
- def services
26
- @services ||= containers.map do |container|
27
- container.info.dig('Labels', 'com.docker.compose.service')
28
- end.uniq
29
- end
30
-
31
- Contract None => HashOf[RespondTo[:to_s], Hash]
32
- def links
33
- @links ||= services.map do |service|
34
- {
35
- "service:#{service}" => {
36
- href: "/project/#{project}/service/#{service}"
37
- }
38
- }
39
- end.reduce(&:merge)
40
- end
41
-
42
- def attributes
43
- { services: services }
44
- end
45
- end
46
- end
47
- end