aruba 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +72 -1
- data/CONTRIBUTING.md +11 -31
- data/README.md +1 -2
- data/exe/aruba +2 -2
- data/lib/aruba.rb +1 -1
- data/lib/aruba/api.rb +11 -12
- data/lib/aruba/api/bundler.rb +18 -3
- data/lib/aruba/api/commands.rb +19 -22
- data/lib/aruba/api/core.rb +65 -48
- data/lib/aruba/api/environment.rb +13 -5
- data/lib/aruba/api/filesystem.rb +69 -39
- data/lib/aruba/api/text.rb +15 -3
- data/lib/aruba/aruba_path.rb +3 -4
- data/lib/aruba/basic_configuration.rb +52 -71
- data/lib/aruba/basic_configuration/option.rb +2 -2
- data/lib/aruba/cli.rb +9 -6
- data/lib/aruba/command.rb +4 -4
- data/lib/aruba/config/jruby.rb +9 -9
- data/lib/aruba/config_wrapper.rb +17 -2
- data/lib/aruba/configuration.rb +37 -32
- data/lib/aruba/console.rb +11 -13
- data/lib/aruba/console/help.rb +9 -6
- data/lib/aruba/contracts/absolute_path.rb +2 -2
- data/lib/aruba/contracts/enum.rb +1 -1
- data/lib/aruba/contracts/is_power_of_two.rb +3 -3
- data/lib/aruba/contracts/relative_path.rb +2 -2
- data/lib/aruba/cucumber.rb +7 -7
- data/lib/aruba/cucumber/command.rb +106 -95
- data/lib/aruba/cucumber/environment.rb +7 -7
- data/lib/aruba/cucumber/file.rb +50 -26
- data/lib/aruba/cucumber/hooks.rb +32 -29
- data/lib/aruba/cucumber/testing_frameworks.rb +32 -30
- data/lib/aruba/event_bus.rb +6 -4
- data/lib/aruba/event_bus/name_resolver.rb +12 -11
- data/lib/aruba/events.rb +2 -1
- data/lib/aruba/file_size.rb +1 -1
- data/lib/aruba/generators/script_file.rb +2 -2
- data/lib/aruba/hooks.rb +2 -4
- data/lib/aruba/in_config_wrapper.rb +8 -5
- data/lib/aruba/initializer.rb +14 -12
- data/lib/aruba/matchers/base/base_matcher.rb +3 -12
- data/lib/aruba/matchers/base/message_indenter.rb +2 -2
- data/lib/aruba/matchers/base/object_formatter.rb +2 -5
- data/lib/aruba/matchers/collection.rb +1 -1
- data/lib/aruba/matchers/collection/all.rb +1 -1
- data/lib/aruba/matchers/collection/include_an_object.rb +6 -6
- data/lib/aruba/matchers/command.rb +1 -1
- data/lib/aruba/matchers/command/be_successfully_executed.rb +6 -4
- data/lib/aruba/matchers/command/have_exit_status.rb +3 -1
- data/lib/aruba/matchers/command/have_finished_in_time.rb +4 -2
- data/lib/aruba/matchers/command/have_output.rb +4 -2
- data/lib/aruba/matchers/command/have_output_on_stderr.rb +3 -1
- data/lib/aruba/matchers/command/have_output_on_stdout.rb +3 -1
- data/lib/aruba/matchers/directory.rb +1 -1
- data/lib/aruba/matchers/directory/be_an_existing_directory.rb +2 -2
- data/lib/aruba/matchers/directory/have_sub_directory.rb +9 -4
- data/lib/aruba/matchers/environment.rb +1 -1
- data/lib/aruba/matchers/file.rb +1 -1
- data/lib/aruba/matchers/file/be_a_command_found_in_path.rb +1 -1
- data/lib/aruba/matchers/file/be_an_existing_executable.rb +2 -2
- data/lib/aruba/matchers/file/be_an_existing_file.rb +2 -2
- data/lib/aruba/matchers/file/have_file_content.rb +1 -1
- data/lib/aruba/matchers/file/have_file_size.rb +5 -3
- data/lib/aruba/matchers/file/have_same_file_content.rb +2 -2
- data/lib/aruba/matchers/path.rb +1 -1
- data/lib/aruba/matchers/path/a_path_matching_pattern.rb +1 -1
- data/lib/aruba/matchers/path/be_an_absolute_path.rb +1 -1
- data/lib/aruba/matchers/path/be_an_existing_path.rb +1 -1
- data/lib/aruba/matchers/path/have_permissions.rb +9 -6
- data/lib/aruba/matchers/string.rb +1 -1
- data/lib/aruba/matchers/string/include_output_string.rb +1 -1
- data/lib/aruba/matchers/string/match_output_string.rb +1 -1
- data/lib/aruba/matchers/string/output_string_eq.rb +1 -1
- data/lib/aruba/platform.rb +2 -2
- data/lib/aruba/platforms/announcer.rb +29 -17
- data/lib/aruba/platforms/aruba_file_creator.rb +3 -1
- data/lib/aruba/platforms/aruba_fixed_size_file_creator.rb +7 -2
- data/lib/aruba/platforms/aruba_logger.rb +11 -10
- data/lib/aruba/platforms/command_monitor.rb +7 -9
- data/lib/aruba/platforms/determine_disk_usage.rb +2 -4
- data/lib/aruba/platforms/filesystem_status.rb +20 -14
- data/lib/aruba/platforms/simple_table.rb +3 -3
- data/lib/aruba/platforms/unix_command_string.rb +2 -2
- data/lib/aruba/platforms/unix_environment_variables.rb +2 -4
- data/lib/aruba/platforms/unix_platform.rb +23 -23
- data/lib/aruba/platforms/unix_which.rb +2 -2
- data/lib/aruba/platforms/windows_command_string.rb +2 -2
- data/lib/aruba/platforms/windows_environment_variables.rb +3 -2
- data/lib/aruba/platforms/windows_platform.rb +7 -7
- data/lib/aruba/platforms/windows_which.rb +8 -4
- data/lib/aruba/processes/basic_process.rb +4 -4
- data/lib/aruba/processes/debug_process.rb +5 -3
- data/lib/aruba/processes/in_process.rb +10 -8
- data/lib/aruba/processes/spawn_process.rb +28 -25
- data/lib/aruba/rspec.rb +30 -20
- data/lib/aruba/runtime.rb +16 -9
- data/lib/aruba/setup.rb +25 -12
- data/lib/aruba/version.rb +1 -1
- metadata +77 -88
- data/.cucumberproignore +0 -3
- data/.document +0 -5
- data/.github/ISSUE_TEMPLATE.md +0 -48
- data/.github/PULL_REQUEST_TEMPLATE.md +0 -41
- data/.gitignore +0 -38
- data/.rspec +0 -3
- data/.rubocop.yml +0 -31
- data/.rubocop_todo.yml +0 -262
- data/.simplecov +0 -36
- data/.travis.yml +0 -62
- data/.yardopts +0 -11
- data/Dockerfile +0 -67
- data/Gemfile +0 -12
- data/Rakefile +0 -80
- data/TODO.md +0 -13
- data/appveyor.yml +0 -29
- data/aruba.gemspec +0 -54
- data/bin/console +0 -7
- data/bin/test +0 -9
- data/config/.gitignore +0 -1
- data/cucumber.yml +0 -6
- data/docker-compose.yml +0 -26
- data/fixtures/cli-app/.gitignore +0 -9
- data/fixtures/cli-app/.rspec +0 -2
- data/fixtures/cli-app/README.md +0 -39
- data/fixtures/cli-app/Rakefile +0 -1
- data/fixtures/cli-app/bin/aruba-test-cli +0 -6
- data/fixtures/cli-app/cli-app.gemspec +0 -25
- data/fixtures/cli-app/features/support/aruba.rb +0 -1
- data/fixtures/cli-app/features/support/env.rb +0 -1
- data/fixtures/cli-app/lib/cli/app.rb +0 -9
- data/fixtures/cli-app/lib/cli/app/suppress_simple_cov_output.rb +0 -15
- data/fixtures/cli-app/lib/cli/app/version.rb +0 -5
- data/fixtures/cli-app/script/console +0 -14
- data/fixtures/cli-app/spec/spec_helper.rb +0 -7
- data/fixtures/cli-app/spec/support/aruba.rb +0 -1
- data/fixtures/copy/file.txt +0 -1
- data/fixtures/empty-app/.gitignore +0 -9
- data/fixtures/empty-app/.rspec +0 -2
- data/fixtures/empty-app/README.md +0 -24
- data/fixtures/empty-app/Rakefile +0 -1
- data/fixtures/empty-app/cli-app.gemspec +0 -25
- data/fixtures/empty-app/lib/cli/app.rb +0 -7
- data/fixtures/empty-app/lib/cli/app/version.rb +0 -5
- data/fixtures/getting-started-app/.gitignore +0 -4
- data/fixtures/getting-started-app/Gemfile +0 -4
- data/fixtures/getting-started-app/README.md +0 -3
- data/fixtures/getting-started-app/features/support/env.rb +0 -1
- data/lib/aruba/extensions/string/strip.rb +0 -25
- data/lib/aruba/tasks/docker_helpers.rb +0 -154
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "aruba/platform"
|
2
2
|
|
3
3
|
# Aruba
|
4
4
|
module Aruba
|
@@ -23,7 +23,9 @@ module Aruba
|
|
23
23
|
aruba.environment[name] = value
|
24
24
|
new_environment = aruba.environment.to_h
|
25
25
|
|
26
|
-
environment_change = { old: old_environment,
|
26
|
+
environment_change = { old: old_environment,
|
27
|
+
new: new_environment,
|
28
|
+
changed: { name: name, value: value } }
|
27
29
|
aruba.event_bus.notify Events::AddedEnvironmentVariable.new(environment_change)
|
28
30
|
|
29
31
|
self
|
@@ -46,7 +48,9 @@ module Aruba
|
|
46
48
|
aruba.environment.append name, value
|
47
49
|
new_environment = aruba.environment.to_h
|
48
50
|
|
49
|
-
environment_change = { old: old_environment,
|
51
|
+
environment_change = { old: old_environment,
|
52
|
+
new: new_environment,
|
53
|
+
changed: { name: name, value: value } }
|
50
54
|
aruba.event_bus.notify Events::ChangedEnvironmentVariable.new(environment_change)
|
51
55
|
|
52
56
|
self
|
@@ -69,7 +73,9 @@ module Aruba
|
|
69
73
|
aruba.environment.prepend name, value
|
70
74
|
new_environment = aruba.environment.to_h
|
71
75
|
|
72
|
-
environment_change = { old: old_environment,
|
76
|
+
environment_change = { old: old_environment,
|
77
|
+
new: new_environment,
|
78
|
+
changed: { name: name, value: value } }
|
73
79
|
aruba.event_bus.notify Events::ChangedEnvironmentVariable.new(environment_change)
|
74
80
|
|
75
81
|
self
|
@@ -88,7 +94,9 @@ module Aruba
|
|
88
94
|
aruba.environment.delete name
|
89
95
|
new_environment = aruba.environment.to_h
|
90
96
|
|
91
|
-
environment_change = { old: old_environment,
|
97
|
+
environment_change = { old: old_environment,
|
98
|
+
new: new_environment,
|
99
|
+
changed: { name: name, value: "" } }
|
92
100
|
aruba.event_bus.notify Events::ChangedEnvironmentVariable.new(environment_change)
|
93
101
|
|
94
102
|
self
|
data/lib/aruba/api/filesystem.rb
CHANGED
@@ -1,11 +1,10 @@
|
|
1
|
-
require
|
1
|
+
require "pathname"
|
2
2
|
|
3
|
-
require
|
4
|
-
require 'aruba/extensions/string/strip'
|
3
|
+
require "aruba/platform"
|
5
4
|
|
6
|
-
Aruba.platform.require_matching_files(
|
7
|
-
Aruba.platform.require_matching_files(
|
8
|
-
Aruba.platform.require_matching_files(
|
5
|
+
Aruba.platform.require_matching_files("../matchers/file/*.rb", __FILE__)
|
6
|
+
Aruba.platform.require_matching_files("../matchers/directory/*.rb", __FILE__)
|
7
|
+
Aruba.platform.require_matching_files("../matchers/path/*.rb", __FILE__)
|
9
8
|
|
10
9
|
# Aruba
|
11
10
|
module Aruba
|
@@ -68,7 +67,7 @@ module Aruba
|
|
68
67
|
# @return [Array]
|
69
68
|
# List of files and directories
|
70
69
|
def all_paths
|
71
|
-
list(
|
70
|
+
list(".").map { |path| expand_path(path) }
|
72
71
|
end
|
73
72
|
|
74
73
|
# Return all existing files in current directory
|
@@ -76,7 +75,7 @@ module Aruba
|
|
76
75
|
# @return [Array]
|
77
76
|
# List of files
|
78
77
|
def all_files
|
79
|
-
list(
|
78
|
+
list(".").select { |p| file? p }.map { |p| expand_path(p) }
|
80
79
|
end
|
81
80
|
|
82
81
|
# Return all existing directories in current directory
|
@@ -84,7 +83,7 @@ module Aruba
|
|
84
83
|
# @return [Array]
|
85
84
|
# List of files
|
86
85
|
def all_directories
|
87
|
-
list(
|
86
|
+
list(".").select { |p| directory? p }.map { |p| expand_path(p) }
|
88
87
|
end
|
89
88
|
|
90
89
|
# Create directory object
|
@@ -92,7 +91,7 @@ module Aruba
|
|
92
91
|
# @return [Dir]
|
93
92
|
# The directory object
|
94
93
|
def directory(path)
|
95
|
-
|
94
|
+
raise ArgumentError, %(Path "#{name}" does not exist.) unless exist? name
|
96
95
|
|
97
96
|
Dir.new(expand_path(path))
|
98
97
|
end
|
@@ -102,22 +101,31 @@ module Aruba
|
|
102
101
|
# @return [Array]
|
103
102
|
# The content of directory
|
104
103
|
def list(name)
|
105
|
-
|
106
|
-
fail ArgumentError, %(Only directories are supported. Path "#{name}" is not a directory.) unless directory? name
|
104
|
+
raise ArgumentError, %(Path "#{name}" does not exist.) unless exist? name
|
107
105
|
|
108
|
-
|
109
|
-
|
106
|
+
unless directory? name
|
107
|
+
raise ArgumentError,
|
108
|
+
%(Only directories are supported. Path "#{name}" is not a directory.)
|
109
|
+
end
|
110
|
+
|
111
|
+
existing_files = Dir.glob(expand_path(File.join(name, "**", "*")))
|
112
|
+
current_working_directory = Pathname.new(expand_path("."))
|
110
113
|
|
111
|
-
existing_files.map
|
114
|
+
existing_files.map do |d|
|
115
|
+
Pathname.new(d).relative_path_from(current_working_directory).to_s
|
116
|
+
end
|
112
117
|
end
|
113
118
|
|
114
119
|
# Return content of file
|
115
120
|
#
|
116
121
|
# @return [Array]
|
117
|
-
# The content of file, without "\n" or "\r\n" at the end.
|
122
|
+
# The content of file, without "\n" or "\r\n" at the end.
|
123
|
+
# To rebuild the file use `content.join("\n")`
|
118
124
|
def read(name)
|
119
|
-
|
120
|
-
|
125
|
+
raise ArgumentError, %(Path "#{name}" does not exist.) unless exist? name
|
126
|
+
unless file? name
|
127
|
+
raise ArgumentError, %(Only files are supported. Path "#{name}" is not a file.)
|
128
|
+
end
|
121
129
|
|
122
130
|
File.readlines(expand_path(name)).map(&:chomp)
|
123
131
|
end
|
@@ -145,7 +153,7 @@ module Aruba
|
|
145
153
|
def touch(*args)
|
146
154
|
args = args.flatten
|
147
155
|
|
148
|
-
options = if args.last.
|
156
|
+
options = if args.last.is_a? Hash
|
149
157
|
args.pop
|
150
158
|
else
|
151
159
|
{}
|
@@ -168,9 +176,6 @@ module Aruba
|
|
168
176
|
# @param [String] destination
|
169
177
|
# A file or directory name. If multiple sources are given the destination
|
170
178
|
# needs to be a directory
|
171
|
-
#
|
172
|
-
# rubocop:disable Metrics/CyclomaticComplexity
|
173
|
-
# def copy(*source, destination)
|
174
179
|
def copy(*args)
|
175
180
|
args = args.flatten
|
176
181
|
destination = args.pop
|
@@ -181,11 +186,12 @@ module Aruba
|
|
181
186
|
end
|
182
187
|
|
183
188
|
if destination.start_with? aruba.config.fixtures_path_prefix
|
184
|
-
raise ArgumentError,
|
189
|
+
raise ArgumentError,
|
190
|
+
"Using a fixture as destination (#{destination}) is not supported"
|
185
191
|
end
|
186
192
|
|
187
193
|
if source.count > 1 && exist?(destination) && !directory?(destination)
|
188
|
-
raise ArgumentError,
|
194
|
+
raise ArgumentError, "Multiples sources can only be copied to a directory"
|
189
195
|
end
|
190
196
|
|
191
197
|
source_paths = source.map { |f| expand_path(f) }
|
@@ -202,7 +208,6 @@ module Aruba
|
|
202
208
|
|
203
209
|
self
|
204
210
|
end
|
205
|
-
# rubocop:enable Metrics/CyclomaticComplexity
|
206
211
|
|
207
212
|
# Move a file and/or directory
|
208
213
|
#
|
@@ -214,20 +219,20 @@ module Aruba
|
|
214
219
|
# @param [String] destination
|
215
220
|
# A file or directory name. If multiple sources are given the destination
|
216
221
|
# needs to be a directory
|
217
|
-
#
|
218
|
-
# rubocop:disable Metrics/CyclomaticComplexity
|
219
|
-
# rubocop:disable Metrics/MethodLength
|
220
222
|
def move(*args)
|
221
223
|
args = args.flatten
|
222
224
|
destination = args.pop
|
223
225
|
source = args
|
224
226
|
|
225
227
|
source.each do |s|
|
226
|
-
|
228
|
+
if s.start_with? aruba.config.fixtures_path_prefix
|
229
|
+
raise ArgumentError, "Using a fixture as source (#{source}) is not supported"
|
230
|
+
end
|
227
231
|
end
|
228
232
|
|
229
233
|
if destination.start_with? aruba.config.fixtures_path_prefix
|
230
|
-
raise ArgumentError,
|
234
|
+
raise ArgumentError,
|
235
|
+
"Using a fixture as destination (#{destination}) is not supported"
|
231
236
|
end
|
232
237
|
|
233
238
|
source.each do |s|
|
@@ -235,7 +240,7 @@ module Aruba
|
|
235
240
|
end
|
236
241
|
|
237
242
|
if source.count > 1 && exist?(destination) && !directory?(destination)
|
238
|
-
raise ArgumentError,
|
243
|
+
raise ArgumentError, "Multiple sources can only be copied to a directory"
|
239
244
|
end
|
240
245
|
|
241
246
|
source_paths = source.map { |f| expand_path(f) }
|
@@ -252,8 +257,6 @@ module Aruba
|
|
252
257
|
|
253
258
|
self
|
254
259
|
end
|
255
|
-
# rubocop:enable Metrics/MethodLength
|
256
|
-
# rubocop:enable Metrics/CyclomaticComplexity
|
257
260
|
|
258
261
|
# Create a file with the given size
|
259
262
|
#
|
@@ -285,21 +288,21 @@ module Aruba
|
|
285
288
|
# Change file system permissions of file
|
286
289
|
#
|
287
290
|
# @param [Octal] mode
|
288
|
-
# File system mode, eg.
|
291
|
+
# File system mode, eg. 0o755
|
289
292
|
#
|
290
293
|
# @param [String] file_name
|
291
294
|
# Name of file to be modified. This file needs to be present to succeed
|
292
295
|
def chmod(*args)
|
293
296
|
args = args.flatten
|
294
297
|
|
295
|
-
options = if args.last.
|
298
|
+
options = if args.last.is_a? Hash
|
296
299
|
args.pop
|
297
300
|
else
|
298
301
|
{}
|
299
302
|
end
|
300
303
|
|
301
304
|
mode = args.shift
|
302
|
-
mode = if mode.
|
305
|
+
mode = if mode.is_a? String
|
303
306
|
mode.to_i(8)
|
304
307
|
else
|
305
308
|
mode
|
@@ -323,8 +326,35 @@ module Aruba
|
|
323
326
|
def append_to_file(file_name, file_content)
|
324
327
|
file_name = expand_path(file_name)
|
325
328
|
|
326
|
-
|
327
|
-
|
329
|
+
unless File.exist? file_name
|
330
|
+
Aruba.platform.deprecated("The ability to call #append_to_file with a file that" \
|
331
|
+
" does not exist is deprecated and will be removed in" \
|
332
|
+
" Aruba 2.0.")
|
333
|
+
Aruba.platform.mkdir(File.dirname(file_name))
|
334
|
+
end
|
335
|
+
File.open(file_name, "a") { |f| f << file_content }
|
336
|
+
end
|
337
|
+
|
338
|
+
# Append lines to a (text) file. This will make sure a newline is present
|
339
|
+
# between the old content and the new.
|
340
|
+
#
|
341
|
+
# @param [String] file_name
|
342
|
+
# The name of the file to be used
|
343
|
+
#
|
344
|
+
# @param [String] file_content
|
345
|
+
# The lines which should be appended to file
|
346
|
+
def append_lines_to_file(file_name, file_content)
|
347
|
+
file_name = expand_path(file_name)
|
348
|
+
|
349
|
+
last = File.open(file_name) do |f|
|
350
|
+
f.seek(-3, IO::SEEK_END)
|
351
|
+
f.read
|
352
|
+
end
|
353
|
+
|
354
|
+
File.open(file_name, "a") do |f|
|
355
|
+
f << "\n" unless last.end_with? "\n"
|
356
|
+
f << file_content
|
357
|
+
end
|
328
358
|
end
|
329
359
|
|
330
360
|
# Create a directory in current directory
|
@@ -344,7 +374,7 @@ module Aruba
|
|
344
374
|
def remove(*args)
|
345
375
|
args = args.flatten
|
346
376
|
|
347
|
-
options = if args.last.
|
377
|
+
options = if args.last.is_a? Hash
|
348
378
|
args.pop
|
349
379
|
else
|
350
380
|
{}
|
data/lib/aruba/api/text.rb
CHANGED
@@ -14,7 +14,14 @@ module Aruba
|
|
14
14
|
# @param [#to_s] text
|
15
15
|
# Input
|
16
16
|
def unescape_text(text)
|
17
|
-
text
|
17
|
+
text
|
18
|
+
.gsub('\n', "\n")
|
19
|
+
.gsub('\"', '"')
|
20
|
+
.gsub('\e', "\e")
|
21
|
+
.gsub('\033', "\e")
|
22
|
+
.gsub('\016', "\016")
|
23
|
+
.gsub('\017', "\017")
|
24
|
+
.gsub('\t', "\t")
|
18
25
|
end
|
19
26
|
|
20
27
|
# Remove ansi characters from text
|
@@ -22,7 +29,10 @@ module Aruba
|
|
22
29
|
# @param [#to_s] text
|
23
30
|
# Input
|
24
31
|
def extract_text(text)
|
25
|
-
text
|
32
|
+
text
|
33
|
+
.gsub(/(?:\e|\033)\[\d+(?>(;\d+)*)m/, "")
|
34
|
+
.gsub(/\\\[|\\\]/, "")
|
35
|
+
.gsub(/\007|\016|\017/, "")
|
26
36
|
end
|
27
37
|
|
28
38
|
# Unescape special characters and remove ANSI characters
|
@@ -41,7 +51,9 @@ module Aruba
|
|
41
51
|
# @param [#to_s] text
|
42
52
|
# The text to parse
|
43
53
|
def replace_variables(text)
|
44
|
-
|
54
|
+
if text.include? "<pid-last-command-started>"
|
55
|
+
text = text.gsub(/<pid-last-command-started>/, last_command_started.pid.to_s)
|
56
|
+
end
|
45
57
|
|
46
58
|
text
|
47
59
|
end
|
data/lib/aruba/aruba_path.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "pathname"
|
2
2
|
|
3
3
|
# Aruba
|
4
4
|
module Aruba
|
@@ -57,9 +57,8 @@ module Aruba
|
|
57
57
|
# Get path
|
58
58
|
def to_pathname
|
59
59
|
current_path = @obj.inject do |path, element|
|
60
|
-
if element.start_with?
|
61
|
-
|
62
|
-
elsif Aruba.platform.absolute_path? element
|
60
|
+
if element.start_with?("~") ||
|
61
|
+
Aruba.platform.absolute_path?(element)
|
63
62
|
element
|
64
63
|
else
|
65
64
|
File.join(path, element)
|
@@ -1,6 +1,6 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require "contracts"
|
2
|
+
require "aruba/basic_configuration/option"
|
3
|
+
require "aruba/in_config_wrapper"
|
4
4
|
|
5
5
|
# Aruba
|
6
6
|
module Aruba
|
@@ -20,27 +20,18 @@ module Aruba
|
|
20
20
|
# @param [Symbol] name
|
21
21
|
# The name of the reader
|
22
22
|
#
|
23
|
-
# @
|
24
|
-
#
|
25
|
-
#
|
26
|
-
# @option [Class, Module] contract
|
27
|
-
# The contract for the option
|
23
|
+
# @option [Class, Module] type
|
24
|
+
# The type contract for the option
|
28
25
|
#
|
29
26
|
# @option [Object] default
|
30
27
|
# The default value
|
31
|
-
def option_reader(name,
|
32
|
-
|
33
|
-
default = opts[:default]
|
34
|
-
|
35
|
-
fail ArgumentError, 'Either use block or default value' if block_given? && default
|
36
|
-
fail ArgumentError, 'contract-options is required' if contract.nil?
|
28
|
+
def option_reader(name, type:, default: nil)
|
29
|
+
raise ArgumentError, "Either use block or default value" if block_given? && default
|
37
30
|
|
38
|
-
Contract contract
|
39
31
|
add_option(name, block_given? ? yield(InConfigWrapper.new(known_options)) : default)
|
40
32
|
|
33
|
+
Contract None => type
|
41
34
|
define_method(name) { find_option(name).value }
|
42
|
-
|
43
|
-
self
|
44
35
|
end
|
45
36
|
|
46
37
|
# Define an option reader and writer
|
@@ -48,31 +39,23 @@ module Aruba
|
|
48
39
|
# @param [Symbol] name
|
49
40
|
# The name of the reader
|
50
41
|
#
|
51
|
-
# @
|
52
|
-
#
|
53
|
-
#
|
54
|
-
# @option [Class, Module] contract
|
55
|
-
# The contract for the option
|
42
|
+
# @option [Class, Module] type
|
43
|
+
# The type contract for the option
|
56
44
|
#
|
57
45
|
# @option [Object] default
|
58
46
|
# The default value
|
59
47
|
#
|
60
|
-
def option_accessor(name,
|
61
|
-
|
62
|
-
default = opts[:default]
|
63
|
-
|
64
|
-
fail ArgumentError, 'Either use block or default value' if block_given? && default
|
65
|
-
# fail ArgumentError, 'Either use block or default value' if !block_given? && default.nil? && default.to_s.empty?
|
66
|
-
fail ArgumentError, 'contract-options is required' if contract.nil?
|
48
|
+
def option_accessor(name, type:, default: nil)
|
49
|
+
raise ArgumentError, "Either use block or default value" if block_given? && default
|
67
50
|
|
68
51
|
# Add writer
|
69
52
|
add_option(name, block_given? ? yield(InConfigWrapper.new(known_options)) : default)
|
70
53
|
|
71
|
-
Contract
|
54
|
+
Contract type => type
|
72
55
|
define_method("#{name}=") { |v| find_option(name).value = v }
|
73
56
|
|
74
57
|
# Add reader
|
75
|
-
option_reader name,
|
58
|
+
option_reader name, type: type
|
76
59
|
end
|
77
60
|
|
78
61
|
private
|
@@ -91,8 +74,6 @@ module Aruba
|
|
91
74
|
attr_accessor :local_options
|
92
75
|
attr_writer :hooks
|
93
76
|
|
94
|
-
# attr_reader :hooks
|
95
|
-
|
96
77
|
public
|
97
78
|
|
98
79
|
# Create configuration
|
@@ -121,68 +102,68 @@ module Aruba
|
|
121
102
|
obj
|
122
103
|
end
|
123
104
|
|
124
|
-
# Define
|
105
|
+
# Define before-hook
|
125
106
|
#
|
126
107
|
# @param [Symbol, String] name
|
127
108
|
# The name of the hook
|
128
109
|
#
|
129
|
-
# @param [Proc] context
|
130
|
-
# The context a hook should run in. This is a runtime only option.
|
131
|
-
#
|
132
|
-
# @param [Array] args
|
133
|
-
# Arguments for the run of hook. This is a runtime only option.
|
134
|
-
#
|
135
110
|
# @yield
|
136
111
|
# The code block which should be run. This is a configure time only option
|
137
|
-
def before(name,
|
138
|
-
name = format(
|
112
|
+
def before(name, &block)
|
113
|
+
name = format("%s_%s", "before_", name.to_s).to_sym
|
114
|
+
raise ArgumentError, "A block is required" unless block
|
139
115
|
|
140
|
-
|
141
|
-
@hooks.append(name, block)
|
116
|
+
@hooks.append(name, block)
|
142
117
|
|
143
|
-
|
144
|
-
else
|
145
|
-
@hooks.execute(name, context, *args)
|
146
|
-
end
|
118
|
+
self
|
147
119
|
end
|
148
120
|
|
149
|
-
#
|
121
|
+
# Run before-hook
|
150
122
|
#
|
151
123
|
# @param [Symbol, String] name
|
152
124
|
# The name of the hook
|
153
125
|
#
|
154
126
|
# @param [Proc] context
|
155
|
-
# The context a hook should run in
|
127
|
+
# The context a hook should run in
|
156
128
|
#
|
157
129
|
# @param [Array] args
|
158
|
-
# Arguments for the run of hook
|
130
|
+
# Arguments for the run of hook
|
131
|
+
def run_before_hook(name, context, *args)
|
132
|
+
name = format("%s_%s", "before_", name.to_s).to_sym
|
133
|
+
|
134
|
+
@hooks.execute(name, context, *args)
|
135
|
+
end
|
136
|
+
|
137
|
+
# Define after-hook
|
138
|
+
#
|
139
|
+
# @param [Symbol, String] name
|
140
|
+
# The name of the hook
|
159
141
|
#
|
160
142
|
# @yield
|
161
143
|
# The code block which should be run. This is a configure time only option
|
162
|
-
def after(name,
|
163
|
-
name = format(
|
164
|
-
|
165
|
-
if block_given?
|
166
|
-
@hooks.append(name, block)
|
167
|
-
|
168
|
-
self
|
169
|
-
else
|
170
|
-
@hooks.execute(name, context, *args)
|
171
|
-
end
|
172
|
-
end
|
144
|
+
def after(name, &block)
|
145
|
+
name = format("%s_%s", "after_", name.to_s).to_sym
|
146
|
+
raise ArgumentError, "A block is required" unless block
|
173
147
|
|
174
|
-
|
175
|
-
def before?(name)
|
176
|
-
name = format('%s_%s', 'before_', name.to_s).to_sym
|
148
|
+
@hooks.append(name, block)
|
177
149
|
|
178
|
-
|
150
|
+
self
|
179
151
|
end
|
180
152
|
|
181
|
-
#
|
182
|
-
|
183
|
-
|
153
|
+
# Run after-hook
|
154
|
+
#
|
155
|
+
# @param [Symbol, String] name
|
156
|
+
# The name of the hook
|
157
|
+
#
|
158
|
+
# @param [Proc] context
|
159
|
+
# The context a hook should run in
|
160
|
+
#
|
161
|
+
# @param [Array] args
|
162
|
+
# Arguments for the run of hook
|
163
|
+
def run_after_hook(name, context, *args)
|
164
|
+
name = format("%s_%s", "after_", name.to_s).to_sym
|
184
165
|
|
185
|
-
@hooks.
|
166
|
+
@hooks.execute(name, context, *args)
|
186
167
|
end
|
187
168
|
|
188
169
|
# Check if <name> is option
|
@@ -210,7 +191,7 @@ module Aruba
|
|
210
191
|
end
|
211
192
|
|
212
193
|
def find_option(name)
|
213
|
-
|
194
|
+
raise NotImplementedError, %(Unknown option "#{name}") unless option? name
|
214
195
|
|
215
196
|
local_options[name]
|
216
197
|
end
|