dagger_ruby 0.7.0 → 0.10.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 +4 -4
- data/CHANGELOG.md +52 -91
- data/LICENSE.txt +1 -1
- data/README.md +115 -240
- data/SECURITY.md +18 -0
- data/dagger_ruby.gemspec +17 -20
- data/lib/dagger_ruby/cache_volume.rb +0 -10
- data/lib/dagger_ruby/client.rb +25 -24
- data/lib/dagger_ruby/config.rb +38 -1
- data/lib/dagger_ruby/container.rb +88 -96
- data/lib/dagger_ruby/dagger_object.rb +18 -28
- data/lib/dagger_ruby/directory.rb +23 -60
- data/lib/dagger_ruby/errors.rb +1 -0
- data/lib/dagger_ruby/file.rb +17 -49
- data/lib/dagger_ruby/git_repository.rb +16 -29
- data/lib/dagger_ruby/host.rb +6 -18
- data/lib/dagger_ruby/query_builder.rb +14 -9
- data/lib/dagger_ruby/secret.rb +0 -14
- data/lib/dagger_ruby/service.rb +10 -59
- data/lib/dagger_ruby/version.rb +2 -1
- data/lib/dagger_ruby.rb +57 -38
- metadata +20 -18
|
@@ -4,12 +4,6 @@ require_relative "dagger_object"
|
|
|
4
4
|
|
|
5
5
|
module DaggerRuby
|
|
6
6
|
class Directory < DaggerObject
|
|
7
|
-
def self.from_id(id, client)
|
|
8
|
-
query = QueryBuilder.new("directory")
|
|
9
|
-
query.load_from_id(id)
|
|
10
|
-
new(query, client)
|
|
11
|
-
end
|
|
12
|
-
|
|
13
7
|
def self.root_field_name
|
|
14
8
|
"directory"
|
|
15
9
|
end
|
|
@@ -32,6 +26,9 @@ module DaggerRuby
|
|
|
32
26
|
args = { "path" => path, "source" => directory.is_a?(DaggerObject) ? directory.id : directory }
|
|
33
27
|
args["exclude"] = opts[:exclude] if opts[:exclude]
|
|
34
28
|
args["include"] = opts[:include] if opts[:include]
|
|
29
|
+
args["gitignore"] = opts[:gitignore] if opts[:gitignore]
|
|
30
|
+
args["owner"] = opts[:owner] if opts[:owner]
|
|
31
|
+
args["permissions"] = opts[:permissions] if opts[:permissions]
|
|
35
32
|
|
|
36
33
|
chain_operation("withDirectory", args)
|
|
37
34
|
end
|
|
@@ -55,6 +52,14 @@ module DaggerRuby
|
|
|
55
52
|
chain_operation("diff", { "other" => other.is_a?(DaggerObject) ? other.id : other })
|
|
56
53
|
end
|
|
57
54
|
|
|
55
|
+
def filter(opts = {})
|
|
56
|
+
args = {}
|
|
57
|
+
args["exclude"] = opts[:exclude] if opts[:exclude]
|
|
58
|
+
args["include"] = opts[:include] if opts[:include]
|
|
59
|
+
args["gitignore"] = opts[:gitignore] if opts[:gitignore]
|
|
60
|
+
chain_operation("filter", args)
|
|
61
|
+
end
|
|
62
|
+
|
|
58
63
|
def sync
|
|
59
64
|
get_scalar("id")
|
|
60
65
|
self
|
|
@@ -68,42 +73,30 @@ module DaggerRuby
|
|
|
68
73
|
get_object("directory", Directory, { "path" => path })
|
|
69
74
|
end
|
|
70
75
|
|
|
71
|
-
def as_tarball(opts = {})
|
|
72
|
-
args = {}
|
|
73
|
-
args["forcedCompression"] = opts[:forced_compression] if opts[:forced_compression]
|
|
74
|
-
|
|
75
|
-
get_object("asTarball", File, args)
|
|
76
|
-
end
|
|
77
|
-
|
|
78
76
|
def export(path, opts = {})
|
|
79
77
|
args = { "path" => path }
|
|
80
|
-
args["
|
|
81
|
-
|
|
82
|
-
query = @query_builder.build_query_with_selection("export(#{format_arguments(args)})")
|
|
83
|
-
result = @client.execute(query)
|
|
84
|
-
extract_value_from_result(result, "export")
|
|
78
|
+
args["wipe"] = opts[:wipe] if opts.key?(:wipe)
|
|
79
|
+
get_scalar("export", args)
|
|
85
80
|
end
|
|
86
81
|
|
|
87
82
|
def entries(path = ".")
|
|
88
|
-
|
|
89
|
-
result = @client.execute(query)
|
|
90
|
-
extract_value_from_result(result, "entries")
|
|
83
|
+
get_scalar("entries", { "path" => path })
|
|
91
84
|
end
|
|
92
85
|
|
|
93
86
|
def glob(pattern)
|
|
94
|
-
|
|
95
|
-
result = @client.execute(query)
|
|
96
|
-
extract_value_from_result(result, "glob")
|
|
87
|
+
get_scalar("glob", { "pattern" => pattern })
|
|
97
88
|
end
|
|
98
89
|
|
|
99
90
|
def docker_build(opts = {})
|
|
100
|
-
args = {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
91
|
+
args = {
|
|
92
|
+
"dockerfile" => opts[:dockerfile],
|
|
93
|
+
"platform" => opts[:platform],
|
|
94
|
+
"buildArgs" => opts[:build_args],
|
|
95
|
+
"target" => opts[:target],
|
|
96
|
+
}.compact
|
|
105
97
|
args["secrets"] = opts[:secrets].map { |s| s.is_a?(DaggerObject) ? s.id : s } if opts[:secrets]
|
|
106
98
|
args["noInit"] = opts[:no_init] if opts.key?(:no_init)
|
|
99
|
+
args["ssh"] = opts[:ssh].is_a?(DaggerObject) ? opts[:ssh].id : opts[:ssh] if opts[:ssh]
|
|
107
100
|
|
|
108
101
|
require_relative "container" unless defined?(Container)
|
|
109
102
|
get_object("dockerBuild", Container, args)
|
|
@@ -129,7 +122,7 @@ module DaggerRuby
|
|
|
129
122
|
end
|
|
130
123
|
end
|
|
131
124
|
|
|
132
|
-
def self.load_from_host(path, opts = {}
|
|
125
|
+
def self.load_from_host(path, client, opts = {})
|
|
133
126
|
args = { "path" => path }
|
|
134
127
|
args["exclude"] = opts[:exclude] if opts[:exclude]
|
|
135
128
|
args["include"] = opts[:include] if opts[:include]
|
|
@@ -138,35 +131,5 @@ module DaggerRuby
|
|
|
138
131
|
host_dir_query = host_query.chain_operation("directory", args)
|
|
139
132
|
Directory.new(host_dir_query, client)
|
|
140
133
|
end
|
|
141
|
-
|
|
142
|
-
private
|
|
143
|
-
|
|
144
|
-
def format_arguments(args)
|
|
145
|
-
return "" if args.empty?
|
|
146
|
-
|
|
147
|
-
args.map { |key, value| "#{key}: #{format_value(value)}" }.join(", ")
|
|
148
|
-
end
|
|
149
|
-
|
|
150
|
-
def format_value(value)
|
|
151
|
-
case value
|
|
152
|
-
when String
|
|
153
|
-
"\"#{value}\""
|
|
154
|
-
when Integer, Float
|
|
155
|
-
value.to_s
|
|
156
|
-
when TrueClass, FalseClass
|
|
157
|
-
value.to_s
|
|
158
|
-
when NilClass
|
|
159
|
-
"null"
|
|
160
|
-
when Array
|
|
161
|
-
"[#{value.map { |v| format_value(v) }.join(", ")}]"
|
|
162
|
-
when Hash
|
|
163
|
-
formatted_pairs = value.map { |k, v| "#{k}: #{format_value(v)}" }
|
|
164
|
-
"{ #{formatted_pairs.join(", ")} }"
|
|
165
|
-
when DaggerObject
|
|
166
|
-
value.id
|
|
167
|
-
else
|
|
168
|
-
"\"#{value}\""
|
|
169
|
-
end
|
|
170
|
-
end
|
|
171
134
|
end
|
|
172
135
|
end
|
data/lib/dagger_ruby/errors.rb
CHANGED
data/lib/dagger_ruby/file.rb
CHANGED
|
@@ -4,12 +4,6 @@ require_relative "dagger_object"
|
|
|
4
4
|
|
|
5
5
|
module DaggerRuby
|
|
6
6
|
class File < DaggerObject
|
|
7
|
-
def self.from_id(id, client)
|
|
8
|
-
query = QueryBuilder.new("file")
|
|
9
|
-
query.load_from_id(id)
|
|
10
|
-
new(query, client)
|
|
11
|
-
end
|
|
12
|
-
|
|
13
7
|
def self.root_field_name
|
|
14
8
|
"file"
|
|
15
9
|
end
|
|
@@ -18,20 +12,15 @@ module DaggerRuby
|
|
|
18
12
|
chain_operation("withName", { "name" => name })
|
|
19
13
|
end
|
|
20
14
|
|
|
21
|
-
def with_contents(contents)
|
|
22
|
-
chain_operation("withContents", { "contents" => contents })
|
|
23
|
-
end
|
|
24
|
-
|
|
25
15
|
def with_timestamps(timestamp)
|
|
26
16
|
chain_operation("withTimestamps", { "timestamp" => timestamp })
|
|
27
17
|
end
|
|
28
18
|
|
|
29
|
-
def
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
get_scalar("contents")
|
|
19
|
+
def contents(offset_lines: nil, limit_lines: nil)
|
|
20
|
+
args = {}
|
|
21
|
+
args["offsetLines"] = offset_lines if offset_lines
|
|
22
|
+
args["limitLines"] = limit_lines if limit_lines
|
|
23
|
+
get_scalar("contents", args)
|
|
35
24
|
end
|
|
36
25
|
|
|
37
26
|
def size
|
|
@@ -42,48 +31,27 @@ module DaggerRuby
|
|
|
42
31
|
get_scalar("name")
|
|
43
32
|
end
|
|
44
33
|
|
|
34
|
+
def chown(owner)
|
|
35
|
+
chain_operation("chown", { "owner" => owner })
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def with_replaced(search, replacement, opts = {})
|
|
39
|
+
args = { "search" => search, "replacement" => replacement }
|
|
40
|
+
args["all"] = opts[:all] if opts.key?(:all)
|
|
41
|
+
args["firstFrom"] = opts[:first_from] if opts[:first_from]
|
|
42
|
+
chain_operation("withReplaced", args)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
45
|
def export(path, opts = {})
|
|
46
46
|
args = { "path" => path }
|
|
47
47
|
args["allowParentDirPath"] = opts[:allow_parent_dir_path] if opts.key?(:allow_parent_dir_path)
|
|
48
48
|
|
|
49
|
-
|
|
50
|
-
result = @client.execute(query)
|
|
51
|
-
extract_value_from_result(result, "export")
|
|
49
|
+
get_scalar("export", args)
|
|
52
50
|
end
|
|
53
51
|
|
|
54
52
|
def sync
|
|
55
53
|
get_scalar("id")
|
|
56
54
|
self
|
|
57
55
|
end
|
|
58
|
-
|
|
59
|
-
private
|
|
60
|
-
|
|
61
|
-
def format_arguments(args)
|
|
62
|
-
return "" if args.empty?
|
|
63
|
-
|
|
64
|
-
args.map { |key, value| "#{key}: #{format_value(value)}" }.join(", ")
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
def format_value(value)
|
|
68
|
-
case value
|
|
69
|
-
when String
|
|
70
|
-
"\"#{value}\""
|
|
71
|
-
when Integer, Float
|
|
72
|
-
value.to_s
|
|
73
|
-
when TrueClass, FalseClass
|
|
74
|
-
value.to_s
|
|
75
|
-
when NilClass
|
|
76
|
-
"null"
|
|
77
|
-
when Array
|
|
78
|
-
"[#{value.map { |v| format_value(v) }.join(", ")}]"
|
|
79
|
-
when Hash
|
|
80
|
-
formatted_pairs = value.map { |k, v| "#{k}: #{format_value(v)}" }
|
|
81
|
-
"{ #{formatted_pairs.join(", ")} }"
|
|
82
|
-
when DaggerObject
|
|
83
|
-
value.id
|
|
84
|
-
else
|
|
85
|
-
"\"#{value}\""
|
|
86
|
-
end
|
|
87
|
-
end
|
|
88
56
|
end
|
|
89
57
|
end
|
|
@@ -4,12 +4,6 @@ require_relative "dagger_object"
|
|
|
4
4
|
|
|
5
5
|
module DaggerRuby
|
|
6
6
|
class GitRepository < DaggerObject
|
|
7
|
-
def self.from_id(id, client)
|
|
8
|
-
query = QueryBuilder.new("gitRepository")
|
|
9
|
-
query.load_from_id(id)
|
|
10
|
-
new(query, client)
|
|
11
|
-
end
|
|
12
|
-
|
|
13
7
|
def self.root_field_name
|
|
14
8
|
"gitRepository"
|
|
15
9
|
end
|
|
@@ -30,20 +24,16 @@ module DaggerRuby
|
|
|
30
24
|
get_object("head", GitRef)
|
|
31
25
|
end
|
|
32
26
|
|
|
33
|
-
def branches
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
def tags
|
|
38
|
-
get_scalar("tags")
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
def with_auth_token(token)
|
|
42
|
-
chain_operation("withAuthToken", { "token" => token.is_a?(DaggerObject) ? token.id : token })
|
|
27
|
+
def branches(patterns: nil)
|
|
28
|
+
args = {}
|
|
29
|
+
args["patterns"] = patterns if patterns
|
|
30
|
+
get_scalar("branches", args)
|
|
43
31
|
end
|
|
44
32
|
|
|
45
|
-
def
|
|
46
|
-
|
|
33
|
+
def tags(patterns: nil)
|
|
34
|
+
args = {}
|
|
35
|
+
args["patterns"] = patterns if patterns
|
|
36
|
+
get_scalar("tags", args)
|
|
47
37
|
end
|
|
48
38
|
|
|
49
39
|
def sync
|
|
@@ -53,12 +43,6 @@ module DaggerRuby
|
|
|
53
43
|
end
|
|
54
44
|
|
|
55
45
|
class GitRef < DaggerObject
|
|
56
|
-
def self.from_id(id, client)
|
|
57
|
-
query = QueryBuilder.new("gitRef")
|
|
58
|
-
query.load_from_id(id)
|
|
59
|
-
new(query, client)
|
|
60
|
-
end
|
|
61
|
-
|
|
62
46
|
def self.root_field_name
|
|
63
47
|
"gitRef"
|
|
64
48
|
end
|
|
@@ -73,11 +57,14 @@ module DaggerRuby
|
|
|
73
57
|
|
|
74
58
|
def tree(opts = {})
|
|
75
59
|
args = {}
|
|
76
|
-
args["
|
|
77
|
-
args["
|
|
78
|
-
args["
|
|
79
|
-
|
|
80
|
-
get_object("tree", Directory, args)
|
|
60
|
+
args["discardGitDir"] = opts[:discard_git_dir] if opts.key?(:discard_git_dir)
|
|
61
|
+
args["depth"] = opts[:depth] if opts[:depth]
|
|
62
|
+
args["includeTags"] = opts[:include_tags] if opts.key?(:include_tags)
|
|
63
|
+
|
|
64
|
+
directory = get_object("tree", Directory, args)
|
|
65
|
+
directory = directory.directory(opts[:path]) if opts[:path]
|
|
66
|
+
directory = directory.filter(exclude: opts[:exclude], include: opts[:include]) if opts[:exclude] || opts[:include]
|
|
67
|
+
directory
|
|
81
68
|
end
|
|
82
69
|
|
|
83
70
|
def sync
|
data/lib/dagger_ruby/host.rb
CHANGED
|
@@ -5,12 +5,6 @@ require_relative "dagger_object"
|
|
|
5
5
|
|
|
6
6
|
module DaggerRuby
|
|
7
7
|
class Host < DaggerObject
|
|
8
|
-
def self.from_id(id, client)
|
|
9
|
-
query = QueryBuilder.new("host")
|
|
10
|
-
query.load_from_id(id)
|
|
11
|
-
new(query, client)
|
|
12
|
-
end
|
|
13
|
-
|
|
14
8
|
def self.root_field_name
|
|
15
9
|
"host"
|
|
16
10
|
end
|
|
@@ -19,22 +13,22 @@ module DaggerRuby
|
|
|
19
13
|
args = { "path" => path }
|
|
20
14
|
args["exclude"] = opts[:exclude] if opts[:exclude]
|
|
21
15
|
args["include"] = opts[:include] if opts[:include]
|
|
16
|
+
args["noCache"] = opts[:no_cache] if opts.key?(:no_cache)
|
|
17
|
+
args["gitignore"] = opts[:gitignore] if opts[:gitignore]
|
|
22
18
|
|
|
23
19
|
get_object("directory", Directory, args)
|
|
24
20
|
end
|
|
25
21
|
|
|
26
|
-
def file(path)
|
|
27
|
-
|
|
22
|
+
def file(path, no_cache: nil)
|
|
23
|
+
args = { "path" => path }
|
|
24
|
+
args["noCache"] = no_cache unless no_cache.nil?
|
|
25
|
+
get_object("file", File, args)
|
|
28
26
|
end
|
|
29
27
|
|
|
30
28
|
def unix_socket(path)
|
|
31
29
|
get_object("unixSocket", Socket, { "path" => path })
|
|
32
30
|
end
|
|
33
31
|
|
|
34
|
-
def workdir
|
|
35
|
-
get_scalar("workdir")
|
|
36
|
-
end
|
|
37
|
-
|
|
38
32
|
def sync
|
|
39
33
|
get_scalar("id")
|
|
40
34
|
self
|
|
@@ -42,12 +36,6 @@ module DaggerRuby
|
|
|
42
36
|
end
|
|
43
37
|
|
|
44
38
|
class Socket < DaggerObject
|
|
45
|
-
def self.from_id(id, client)
|
|
46
|
-
query = QueryBuilder.new("socket")
|
|
47
|
-
query.load_from_id(id)
|
|
48
|
-
new(query, client)
|
|
49
|
-
end
|
|
50
|
-
|
|
51
39
|
def self.root_field_name
|
|
52
40
|
"socket"
|
|
53
41
|
end
|
|
@@ -7,6 +7,10 @@ module DaggerRuby
|
|
|
7
7
|
class QueryBuilder
|
|
8
8
|
attr_reader :root_field, :operation_chain, :variables
|
|
9
9
|
|
|
10
|
+
def self.enum_value(value)
|
|
11
|
+
value.is_a?(Hash) ? value : value.to_sym
|
|
12
|
+
end
|
|
13
|
+
|
|
10
14
|
def initialize(root_field = nil)
|
|
11
15
|
@root_field = root_field
|
|
12
16
|
@operation_chain = []
|
|
@@ -20,10 +24,6 @@ module DaggerRuby
|
|
|
20
24
|
new_query
|
|
21
25
|
end
|
|
22
26
|
|
|
23
|
-
def load_from_id(id)
|
|
24
|
-
chain_operation("loadFromId", { "id" => id })
|
|
25
|
-
end
|
|
26
|
-
|
|
27
27
|
def variable(name, type)
|
|
28
28
|
new_query = QueryBuilder.new(@root_field)
|
|
29
29
|
new_query.instance_variable_set(:@operation_chain, @operation_chain.dup)
|
|
@@ -31,7 +31,8 @@ module DaggerRuby
|
|
|
31
31
|
new_query
|
|
32
32
|
end
|
|
33
33
|
|
|
34
|
-
def build_query_with_selection(field)
|
|
34
|
+
def build_query_with_selection(field, args = {})
|
|
35
|
+
selection = field_selection(field, args)
|
|
35
36
|
query_parts = []
|
|
36
37
|
|
|
37
38
|
if @variables.any?
|
|
@@ -43,21 +44,25 @@ module DaggerRuby
|
|
|
43
44
|
|
|
44
45
|
if @root_field
|
|
45
46
|
if @operation_chain.empty?
|
|
46
|
-
query_parts << "{ #{@root_field} { #{
|
|
47
|
+
query_parts << "{ #{@root_field} { #{selection} } }"
|
|
47
48
|
else
|
|
48
|
-
operations_str = build_operations_chain_with_selection(
|
|
49
|
+
operations_str = build_operations_chain_with_selection(selection)
|
|
49
50
|
query_parts << "{ #{@root_field} { #{operations_str} } }"
|
|
50
51
|
end
|
|
51
52
|
elsif @operation_chain.any?
|
|
52
|
-
operations_str = build_operations_chain_with_selection(
|
|
53
|
+
operations_str = build_operations_chain_with_selection(selection)
|
|
53
54
|
query_parts << "{ #{operations_str} }"
|
|
54
55
|
else
|
|
55
|
-
query_parts << "{ #{
|
|
56
|
+
query_parts << "{ #{selection} }"
|
|
56
57
|
end
|
|
57
58
|
|
|
58
59
|
query_parts.join(" ")
|
|
59
60
|
end
|
|
60
61
|
|
|
62
|
+
def field_selection(field, args = {})
|
|
63
|
+
"#{field}#{format_arguments(args)}"
|
|
64
|
+
end
|
|
65
|
+
|
|
61
66
|
private
|
|
62
67
|
|
|
63
68
|
def build_operations_chain_with_selection(field)
|
data/lib/dagger_ruby/secret.rb
CHANGED
|
@@ -4,24 +4,10 @@ require_relative "dagger_object"
|
|
|
4
4
|
|
|
5
5
|
module DaggerRuby
|
|
6
6
|
class Secret < DaggerObject
|
|
7
|
-
def self.from_id(id, client)
|
|
8
|
-
query = QueryBuilder.new("secret")
|
|
9
|
-
query.load_from_id(id)
|
|
10
|
-
new(query, client)
|
|
11
|
-
end
|
|
12
|
-
|
|
13
7
|
def self.root_field_name
|
|
14
8
|
"secret"
|
|
15
9
|
end
|
|
16
10
|
|
|
17
|
-
def with_name(name)
|
|
18
|
-
chain_operation("withName", { "name" => name })
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
def with_plaintext(plaintext)
|
|
22
|
-
chain_operation("withPlaintext", { "plaintext" => plaintext })
|
|
23
|
-
end
|
|
24
|
-
|
|
25
11
|
def name
|
|
26
12
|
get_scalar("name")
|
|
27
13
|
end
|
data/lib/dagger_ruby/service.rb
CHANGED
|
@@ -4,12 +4,6 @@ require_relative "dagger_object"
|
|
|
4
4
|
|
|
5
5
|
module DaggerRuby
|
|
6
6
|
class Service < DaggerObject
|
|
7
|
-
def self.from_id(id, client)
|
|
8
|
-
query = QueryBuilder.new("service")
|
|
9
|
-
query.load_from_id(id)
|
|
10
|
-
new(query, client)
|
|
11
|
-
end
|
|
12
|
-
|
|
13
7
|
def self.root_field_name
|
|
14
8
|
"service"
|
|
15
9
|
end
|
|
@@ -19,13 +13,7 @@ module DaggerRuby
|
|
|
19
13
|
args["port"] = opts[:port] if opts[:port]
|
|
20
14
|
args["scheme"] = opts[:scheme] if opts[:scheme]
|
|
21
15
|
|
|
22
|
-
|
|
23
|
-
get_scalar("endpoint")
|
|
24
|
-
else
|
|
25
|
-
query = @query_builder.build_query_with_selection("endpoint(#{format_arguments(args)})")
|
|
26
|
-
result = @client.execute(query)
|
|
27
|
-
extract_value_from_result(result, "endpoint")
|
|
28
|
-
end
|
|
16
|
+
get_scalar("endpoint", args)
|
|
29
17
|
end
|
|
30
18
|
|
|
31
19
|
def hostname
|
|
@@ -33,42 +21,26 @@ module DaggerRuby
|
|
|
33
21
|
end
|
|
34
22
|
|
|
35
23
|
def ports
|
|
36
|
-
|
|
24
|
+
get_selection("ports", "port protocol description experimentalSkipHealthcheck")
|
|
37
25
|
end
|
|
38
26
|
|
|
39
27
|
def start
|
|
40
|
-
|
|
41
|
-
result = @client.execute(query)
|
|
42
|
-
extract_value_from_result(result, "start")
|
|
28
|
+
get_scalar("start")
|
|
43
29
|
end
|
|
44
30
|
|
|
45
31
|
def stop(opts = {})
|
|
46
32
|
args = {}
|
|
47
33
|
args["kill"] = opts[:kill] if opts.key?(:kill)
|
|
48
34
|
|
|
49
|
-
|
|
50
|
-
@query_builder.build_query_with_selection("stop")
|
|
51
|
-
else
|
|
52
|
-
@query_builder.build_query_with_selection("stop(#{format_arguments(args)})")
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
result = @client.execute(query)
|
|
56
|
-
extract_value_from_result(result, "stop")
|
|
35
|
+
get_scalar("stop", args)
|
|
57
36
|
end
|
|
58
37
|
|
|
59
38
|
def up(opts = {})
|
|
60
39
|
args = {}
|
|
61
|
-
args["ports"] = opts[:ports] if opts[:ports]
|
|
40
|
+
args["ports"] = opts[:ports].map { |port| normalize_port_forward(port) } if opts[:ports]
|
|
62
41
|
args["random"] = opts[:random] if opts.key?(:random)
|
|
63
42
|
|
|
64
|
-
|
|
65
|
-
@query_builder.build_query_with_selection("up")
|
|
66
|
-
else
|
|
67
|
-
@query_builder.build_query_with_selection("up(#{format_arguments(args)})")
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
result = @client.execute(query)
|
|
71
|
-
extract_value_from_result(result, "up")
|
|
43
|
+
get_scalar("up", args)
|
|
72
44
|
end
|
|
73
45
|
|
|
74
46
|
def with_hostname(hostname)
|
|
@@ -82,31 +54,10 @@ module DaggerRuby
|
|
|
82
54
|
|
|
83
55
|
private
|
|
84
56
|
|
|
85
|
-
def
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
end
|
|
90
|
-
|
|
91
|
-
def format_value(value)
|
|
92
|
-
case value
|
|
93
|
-
when String
|
|
94
|
-
"\"#{value}\""
|
|
95
|
-
when Integer, Float
|
|
96
|
-
value.to_s
|
|
97
|
-
when TrueClass, FalseClass
|
|
98
|
-
value.to_s
|
|
99
|
-
when NilClass
|
|
100
|
-
"null"
|
|
101
|
-
when Array
|
|
102
|
-
"[#{value.map { |v| format_value(v) }.join(", ")}]"
|
|
103
|
-
when Hash
|
|
104
|
-
formatted_pairs = value.map { |k, v| "#{k}: #{format_value(v)}" }
|
|
105
|
-
"{ #{formatted_pairs.join(", ")} }"
|
|
106
|
-
when DaggerObject
|
|
107
|
-
value.id
|
|
108
|
-
else
|
|
109
|
-
"\"#{value}\""
|
|
57
|
+
def normalize_port_forward(port)
|
|
58
|
+
port.to_h do |key, value|
|
|
59
|
+
normalized = key.to_s == "protocol" ? QueryBuilder.enum_value(value) : value
|
|
60
|
+
[key, normalized]
|
|
110
61
|
end
|
|
111
62
|
end
|
|
112
63
|
end
|