aruba 1.0.0.pre.alpha.2 → 1.0.1

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.
Files changed (135) hide show
  1. checksums.yaml +5 -5
  2. data/.github/PULL_REQUEST_TEMPLATE.md +2 -1
  3. data/.rspec +0 -1
  4. data/.rubocop.yml +46 -182
  5. data/.rubocop_todo.yml +216 -0
  6. data/.simplecov +7 -5
  7. data/.travis.yml +56 -40
  8. data/.yardopts +3 -0
  9. data/CHANGELOG.md +1312 -0
  10. data/CONTRIBUTING.md +175 -83
  11. data/Gemfile +5 -69
  12. data/LICENSE +1 -1
  13. data/README.md +58 -21
  14. data/Rakefile +27 -54
  15. data/appveyor.yml +7 -10
  16. data/aruba.gemspec +38 -19
  17. data/bin/console +3 -12
  18. data/cucumber.yml +4 -22
  19. data/exe/aruba +1 -1
  20. data/fixtures/cli-app/README.md +1 -1
  21. data/fixtures/cli-app/Rakefile +1 -1
  22. data/fixtures/cli-app/bin/aruba-test-cli +1 -1
  23. data/fixtures/cli-app/cli-app.gemspec +4 -4
  24. data/fixtures/cli-app/lib/cli/app.rb +1 -1
  25. data/fixtures/cli-app/lib/cli/app/suppress_simple_cov_output.rb +3 -3
  26. data/fixtures/cli-app/lib/cli/app/version.rb +1 -1
  27. data/fixtures/cli-app/spec/spec_helper.rb +3 -2
  28. data/fixtures/empty-app/Rakefile +1 -1
  29. data/fixtures/empty-app/cli-app.gemspec +4 -4
  30. data/fixtures/empty-app/lib/cli/app.rb +0 -2
  31. data/fixtures/empty-app/lib/cli/app/version.rb +1 -1
  32. data/fixtures/getting-started-app/Gemfile +1 -1
  33. data/lib/aruba/api.rb +8 -15
  34. data/lib/aruba/api/bundler.rb +16 -0
  35. data/lib/aruba/api/commands.rb +272 -0
  36. data/lib/aruba/api/core.rb +82 -43
  37. data/lib/aruba/api/environment.rb +24 -7
  38. data/lib/aruba/api/filesystem.rb +66 -64
  39. data/lib/aruba/api/text.rb +17 -11
  40. data/lib/aruba/aruba_path.rb +25 -111
  41. data/lib/aruba/basic_configuration.rb +8 -25
  42. data/lib/aruba/basic_configuration/option.rb +2 -2
  43. data/lib/aruba/cli.rb +4 -1
  44. data/lib/aruba/colorizer.rb +10 -99
  45. data/lib/aruba/command.rb +4 -0
  46. data/lib/aruba/config/jruby.rb +15 -5
  47. data/lib/aruba/config_wrapper.rb +17 -2
  48. data/lib/aruba/configuration.rb +107 -0
  49. data/lib/aruba/console.rb +5 -7
  50. data/lib/aruba/console/help.rb +5 -2
  51. data/lib/aruba/contracts/absolute_path.rb +3 -3
  52. data/lib/aruba/contracts/is_power_of_two.rb +2 -2
  53. data/lib/aruba/contracts/relative_path.rb +3 -3
  54. data/lib/aruba/cucumber.rb +0 -3
  55. data/lib/aruba/cucumber/command.rb +227 -190
  56. data/lib/aruba/cucumber/environment.rb +1 -1
  57. data/lib/aruba/cucumber/file.rb +56 -50
  58. data/lib/aruba/cucumber/hooks.rb +10 -63
  59. data/lib/aruba/cucumber/testing_frameworks.rb +76 -50
  60. data/lib/aruba/event_bus.rb +4 -2
  61. data/lib/aruba/event_bus/name_resolver.rb +10 -10
  62. data/lib/aruba/events.rb +2 -1
  63. data/lib/aruba/hooks.rb +3 -5
  64. data/lib/aruba/in_config_wrapper.rb +10 -3
  65. data/lib/aruba/initializer.rb +40 -34
  66. data/lib/aruba/matchers/base/base_matcher.rb +2 -11
  67. data/lib/aruba/matchers/base/message_indenter.rb +19 -0
  68. data/lib/aruba/matchers/base/object_formatter.rb +2 -7
  69. data/lib/aruba/matchers/collection/include_an_object.rb +11 -13
  70. data/lib/aruba/matchers/command/be_successfully_executed.rb +8 -4
  71. data/lib/aruba/matchers/command/have_exit_status.rb +16 -4
  72. data/lib/aruba/matchers/command/have_finished_in_time.rb +5 -5
  73. data/lib/aruba/matchers/command/have_output.rb +12 -5
  74. data/lib/aruba/matchers/command/have_output_on_stderr.rb +4 -2
  75. data/lib/aruba/matchers/command/have_output_on_stdout.rb +4 -2
  76. data/lib/aruba/matchers/command/have_output_size.rb +2 -2
  77. data/lib/aruba/matchers/directory/be_an_existing_directory.rb +5 -7
  78. data/lib/aruba/matchers/directory/have_sub_directory.rb +10 -7
  79. data/lib/aruba/matchers/file/be_a_command_found_in_path.rb +2 -4
  80. data/lib/aruba/matchers/file/be_an_existing_executable.rb +4 -6
  81. data/lib/aruba/matchers/file/be_an_existing_file.rb +5 -7
  82. data/lib/aruba/matchers/file/have_file_content.rb +4 -4
  83. data/lib/aruba/matchers/file/have_file_size.rb +8 -8
  84. data/lib/aruba/matchers/file/have_same_file_content.rb +9 -12
  85. data/lib/aruba/matchers/path/a_path_matching_pattern.rb +2 -4
  86. data/lib/aruba/matchers/path/be_an_absolute_path.rb +3 -5
  87. data/lib/aruba/matchers/path/be_an_existing_path.rb +4 -6
  88. data/lib/aruba/matchers/path/have_permissions.rb +8 -8
  89. data/lib/aruba/matchers/string/include_output_string.rb +8 -10
  90. data/lib/aruba/matchers/string/match_output_string.rb +9 -11
  91. data/lib/aruba/matchers/string/output_string_eq.rb +7 -9
  92. data/lib/aruba/platform.rb +0 -8
  93. data/lib/aruba/platforms/announcer.rb +60 -85
  94. data/lib/aruba/platforms/aruba_file_creator.rb +4 -2
  95. data/lib/aruba/platforms/aruba_fixed_size_file_creator.rb +8 -3
  96. data/lib/aruba/platforms/aruba_logger.rb +22 -2
  97. data/lib/aruba/platforms/command_monitor.rb +15 -102
  98. data/lib/aruba/platforms/determine_disk_usage.rb +56 -19
  99. data/lib/aruba/platforms/filesystem_status.rb +9 -9
  100. data/lib/aruba/platforms/local_environment.rb +2 -2
  101. data/lib/aruba/platforms/simple_table.rb +3 -11
  102. data/lib/aruba/platforms/unix_command_string.rb +7 -4
  103. data/lib/aruba/platforms/unix_environment_variables.rb +19 -26
  104. data/lib/aruba/platforms/unix_platform.rb +18 -39
  105. data/lib/aruba/platforms/unix_which.rb +3 -2
  106. data/lib/aruba/platforms/windows_command_string.rb +20 -7
  107. data/lib/aruba/platforms/windows_environment_variables.rb +42 -30
  108. data/lib/aruba/platforms/windows_platform.rb +4 -0
  109. data/lib/aruba/platforms/windows_which.rb +9 -4
  110. data/lib/aruba/processes/basic_process.rb +21 -27
  111. data/lib/aruba/processes/debug_process.rb +16 -5
  112. data/lib/aruba/processes/in_process.rb +20 -9
  113. data/lib/aruba/processes/spawn_process.rb +64 -36
  114. data/lib/aruba/rspec.rb +28 -31
  115. data/lib/aruba/runtime.rb +16 -7
  116. data/lib/aruba/setup.rb +32 -17
  117. data/lib/aruba/tasks/docker_helpers.rb +4 -2
  118. data/lib/aruba/version.rb +1 -1
  119. metadata +194 -64
  120. data/History.md +0 -612
  121. data/bin/bootstrap +0 -34
  122. data/bin/build +0 -3
  123. data/bin/release +0 -3
  124. data/fixtures/spawn_process/stderr.sh +0 -3
  125. data/lib/aruba/api/command.rb +0 -309
  126. data/lib/aruba/api/deprecated.rb +0 -895
  127. data/lib/aruba/api/rvm.rb +0 -44
  128. data/lib/aruba/config.rb +0 -101
  129. data/lib/aruba/cucumber/rvm.rb +0 -3
  130. data/lib/aruba/in_process.rb +0 -14
  131. data/lib/aruba/jruby.rb +0 -4
  132. data/lib/aruba/matchers/path/match_path_pattern.rb +0 -41
  133. data/lib/aruba/matchers/rspec_matcher_include_regexp.rb +0 -25
  134. data/lib/aruba/platforms/disk_usage_calculator.rb +0 -20
  135. data/lib/aruba/spawn_process.rb +0 -11
@@ -13,6 +13,8 @@ module Aruba
13
13
  #
14
14
  # @param [String] value
15
15
  # The value of the environment variable. Needs to be a string.
16
+ #
17
+ # @return [self]
16
18
  def set_environment_variable(name, value)
17
19
  name = name.to_s
18
20
  value = value.to_s
@@ -21,7 +23,10 @@ module Aruba
21
23
  aruba.environment[name] = value
22
24
  new_environment = aruba.environment.to_h
23
25
 
24
- aruba.event_bus.notify Events::AddedEnvironmentVariable.new(:old => old_environment, :new => new_environment, :changed => { :name => name, :value => value })
26
+ environment_change = { old: old_environment,
27
+ new: new_environment,
28
+ changed: { name: name, value: value } }
29
+ aruba.event_bus.notify Events::AddedEnvironmentVariable.new(environment_change)
25
30
 
26
31
  self
27
32
  end
@@ -33,6 +38,8 @@ module Aruba
33
38
  #
34
39
  # @param [String] value
35
40
  # The value of the environment variable. Needs to be a string.
41
+ #
42
+ # @return [self]
36
43
  def append_environment_variable(name, value)
37
44
  name = name.to_s
38
45
  value = value.to_s
@@ -41,7 +48,10 @@ module Aruba
41
48
  aruba.environment.append name, value
42
49
  new_environment = aruba.environment.to_h
43
50
 
44
- aruba.event_bus.notify Events::ChangedEnvironmentVariable.new(:old => old_environment, :new => new_environment, :changed => { :name => name, :value => value })
51
+ environment_change = { old: old_environment,
52
+ new: new_environment,
53
+ changed: { name: name, value: value } }
54
+ aruba.event_bus.notify Events::ChangedEnvironmentVariable.new(environment_change)
45
55
 
46
56
  self
47
57
  end
@@ -53,6 +63,8 @@ module Aruba
53
63
  #
54
64
  # @param [String] value
55
65
  # The value of the environment variable. Needs to be a string.
66
+ #
67
+ # @return [self]
56
68
  def prepend_environment_variable(name, value)
57
69
  name = name.to_s
58
70
  value = value.to_s
@@ -61,18 +73,20 @@ module Aruba
61
73
  aruba.environment.prepend name, value
62
74
  new_environment = aruba.environment.to_h
63
75
 
64
- aruba.event_bus.notify Events::ChangedEnvironmentVariable.new(:old => old_environment, :new => new_environment, :changed => { :name => name, :value => value })
76
+ environment_change = { old: old_environment,
77
+ new: new_environment,
78
+ changed: { name: name, value: value } }
79
+ aruba.event_bus.notify Events::ChangedEnvironmentVariable.new(environment_change)
65
80
 
66
81
  self
67
82
  end
68
83
 
69
84
  # Remove existing environment variable
70
85
  #
71
- # @param [String] key
86
+ # @param [String] name
72
87
  # The name of the environment variable as string, e.g. 'HOME'
73
88
  #
74
- # @param [String] value
75
- # The value of the environment variable. Needs to be a string.
89
+ # @return [self]
76
90
  def delete_environment_variable(name)
77
91
  name = name.to_s
78
92
 
@@ -80,7 +94,10 @@ module Aruba
80
94
  aruba.environment.delete name
81
95
  new_environment = aruba.environment.to_h
82
96
 
83
- aruba.event_bus.notify Events::DeletedEnvironmentVariable.new(:old => old_environment, :new => new_environment, :changed => { :name => name, :value => '' })
97
+ environment_change = { old: old_environment,
98
+ new: new_environment,
99
+ changed: { name: name, value: '' } }
100
+ aruba.event_bus.notify Events::ChangedEnvironmentVariable.new(environment_change)
84
101
 
85
102
  self
86
103
  end
@@ -1,9 +1,8 @@
1
- require 'aruba/platform'
1
+ require 'pathname'
2
2
 
3
+ require 'aruba/platform'
3
4
  require 'aruba/extensions/string/strip'
4
5
 
5
- require 'aruba/aruba_path'
6
-
7
6
  Aruba.platform.require_matching_files('../matchers/file/*.rb', __FILE__)
8
7
  Aruba.platform.require_matching_files('../matchers/directory/*.rb', __FILE__)
9
8
  Aruba.platform.require_matching_files('../matchers/path/*.rb', __FILE__)
@@ -40,8 +39,10 @@ module Aruba
40
39
 
41
40
  # Check if file exist and is executable
42
41
  #
43
- # @param [String] file
44
- # The file which should exist
42
+ # @param [String] path
43
+ # The path which should exist and be executable
44
+ #
45
+ # @return [Boolean]
45
46
  def executable?(path)
46
47
  path = expand_path(path)
47
48
 
@@ -50,18 +51,16 @@ module Aruba
50
51
 
51
52
  # Check if path is absolute
52
53
  #
53
- # @return [TrueClass, FalseClass]
54
- # Result of check
54
+ # @return [Boolean]
55
55
  def absolute?(path)
56
- ArubaPath.new(path).absolute?
56
+ Aruba.platform.absolute_path?(path)
57
57
  end
58
58
 
59
59
  # Check if path is relative
60
60
  #
61
- # @return [TrueClass, FalseClass]
62
- # Result of check
61
+ # @return [Boolean]
63
62
  def relative?(path)
64
- ArubaPath.new(path).relative?
63
+ Aruba.platform.relative_path?(path)
65
64
  end
66
65
 
67
66
  # Return all existing paths (directories, files) in current dir
@@ -69,7 +68,7 @@ module Aruba
69
68
  # @return [Array]
70
69
  # List of files and directories
71
70
  def all_paths
72
- list('.').map { |p| expand_path(p) }
71
+ list('.').map { |path| expand_path(path) }
73
72
  end
74
73
 
75
74
  # Return all existing files in current directory
@@ -93,7 +92,7 @@ module Aruba
93
92
  # @return [Dir]
94
93
  # The directory object
95
94
  def directory(path)
96
- fail ArgumentError, %(Path "#{name}" does not exist.) unless exist? name
95
+ raise ArgumentError, %(Path "#{name}" does not exist.) unless exist? name
97
96
 
98
97
  Dir.new(expand_path(path))
99
98
  end
@@ -103,22 +102,31 @@ module Aruba
103
102
  # @return [Array]
104
103
  # The content of directory
105
104
  def list(name)
106
- fail ArgumentError, %(Path "#{name}" does not exist.) unless exist? name
107
- fail ArgumentError, %(Only directories are supported. Path "#{name}" is not a directory.) unless directory? name
105
+ raise ArgumentError, %(Path "#{name}" does not exist.) unless exist? name
106
+
107
+ unless directory? name
108
+ raise ArgumentError,
109
+ %(Only directories are supported. Path "#{name}" is not a directory.)
110
+ end
108
111
 
109
112
  existing_files = Dir.glob(expand_path(File.join(name, '**', '*')))
110
- current_working_directory = ArubaPath.new(expand_path('.'))
113
+ current_working_directory = Pathname.new(expand_path('.'))
111
114
 
112
- existing_files.map { |d| ArubaPath.new(d).relative_path_from(current_working_directory).to_s }
115
+ existing_files.map do |d|
116
+ Pathname.new(d).relative_path_from(current_working_directory).to_s
117
+ end
113
118
  end
114
119
 
115
120
  # Return content of file
116
121
  #
117
122
  # @return [Array]
118
- # The content of file, without "\n" or "\r\n" at the end. To rebuild the file use `content.join("\n")`
123
+ # The content of file, without "\n" or "\r\n" at the end.
124
+ # To rebuild the file use `content.join("\n")`
119
125
  def read(name)
120
- fail ArgumentError, %(Path "#{name}" does not exist.) unless exist? name
121
- fail ArgumentError, %(Only files are supported. Path "#{name}" is not a file.) unless file? name
126
+ raise ArgumentError, %(Path "#{name}" does not exist.) unless exist? name
127
+ unless file? name
128
+ raise ArgumentError, %(Only files are supported. Path "#{name}" is not a file.)
129
+ end
122
130
 
123
131
  File.readlines(expand_path(name)).map(&:chomp)
124
132
  end
@@ -128,10 +136,10 @@ module Aruba
128
136
  # The method does not check if file already exists. If the file name is a
129
137
  # path the method will create all neccessary directories.
130
138
  #
131
- # @param [String] file_name
139
+ # @param [String] name
132
140
  # The name of the file
133
141
  #
134
- # @param [String] file_content
142
+ # @param [String] content
135
143
  # The content which should be written to the file
136
144
  def write_file(name, content)
137
145
  Aruba.platform.create_file(expand_path(name), content, false)
@@ -146,7 +154,7 @@ module Aruba
146
154
  def touch(*args)
147
155
  args = args.flatten
148
156
 
149
- options = if args.last.kind_of? Hash
157
+ options = if args.last.is_a? Hash
150
158
  args.pop
151
159
  else
152
160
  {}
@@ -169,9 +177,6 @@ module Aruba
169
177
  # @param [String] destination
170
178
  # A file or directory name. If multiple sources are given the destination
171
179
  # needs to be a directory
172
- #
173
- # rubocop:disable Metrics/CyclomaticComplexity
174
- # def copy(*source, destination)
175
180
  def copy(*args)
176
181
  args = args.flatten
177
182
  destination = args.pop
@@ -181,8 +186,14 @@ module Aruba
181
186
  raise ArgumentError, %(The following source "#{s}" does not exist.) unless exist? s
182
187
  end
183
188
 
184
- raise ArgumentError, "Using a fixture as destination (#{destination}) is not supported" if destination.start_with? aruba.config.fixtures_path_prefix
185
- raise ArgumentError, "Multiples sources can only be copied to a directory" if source.count > 1 && exist?(destination) && !directory?(destination)
189
+ if destination.start_with? aruba.config.fixtures_path_prefix
190
+ raise ArgumentError,
191
+ "Using a fixture as destination (#{destination}) is not supported"
192
+ end
193
+
194
+ if source.count > 1 && exist?(destination) && !directory?(destination)
195
+ raise ArgumentError, 'Multiples sources can only be copied to a directory'
196
+ end
186
197
 
187
198
  source_paths = source.map { |f| expand_path(f) }
188
199
  destination_path = expand_path(destination)
@@ -198,7 +209,6 @@ module Aruba
198
209
 
199
210
  self
200
211
  end
201
- # rubocop:enable Metrics/CyclomaticComplexity
202
212
 
203
213
  # Move a file and/or directory
204
214
  #
@@ -210,25 +220,29 @@ module Aruba
210
220
  # @param [String] destination
211
221
  # A file or directory name. If multiple sources are given the destination
212
222
  # needs to be a directory
213
- #
214
- # rubocop:disable Metrics/CyclomaticComplexity
215
- # rubocop:disable Metrics/MethodLength
216
223
  def move(*args)
217
224
  args = args.flatten
218
225
  destination = args.pop
219
226
  source = args
220
227
 
221
228
  source.each do |s|
222
- raise ArgumentError, "Using a fixture as source (#{source}) is not supported" if s.start_with? aruba.config.fixtures_path_prefix
229
+ if s.start_with? aruba.config.fixtures_path_prefix
230
+ raise ArgumentError, "Using a fixture as source (#{source}) is not supported"
231
+ end
223
232
  end
224
233
 
225
- raise ArgumentError, "Using a fixture as destination (#{destination}) is not supported" if destination.start_with? aruba.config.fixtures_path_prefix
234
+ if destination.start_with? aruba.config.fixtures_path_prefix
235
+ raise ArgumentError,
236
+ "Using a fixture as destination (#{destination}) is not supported"
237
+ end
226
238
 
227
239
  source.each do |s|
228
240
  raise ArgumentError, %(The following source "#{s}" does not exist.) unless exist? s
229
241
  end
230
242
 
231
- raise ArgumentError, "Multiple sources can only be copied to a directory" if source.count > 1 && exist?(destination) && !directory?(destination)
243
+ if source.count > 1 && exist?(destination) && !directory?(destination)
244
+ raise ArgumentError, 'Multiple sources can only be copied to a directory'
245
+ end
232
246
 
233
247
  source_paths = source.map { |f| expand_path(f) }
234
248
  destination_path = expand_path(destination)
@@ -244,18 +258,16 @@ module Aruba
244
258
 
245
259
  self
246
260
  end
247
- # rubocop:enable Metrics/MethodLength
248
- # rubocop:enable Metrics/CyclomaticComplexity
249
261
 
250
262
  # Create a file with the given size
251
263
  #
252
264
  # The method does not check if file already exists. If the file name is a
253
265
  # path the method will create all neccessary directories.
254
266
  #
255
- # @param [String] file_name
267
+ # @param [String] name
256
268
  # The name of the file
257
269
  #
258
- # @param [Integer] file_size
270
+ # @param [Integer] size
259
271
  # The size of the file
260
272
  def write_fixed_size_file(name, size)
261
273
  Aruba.platform.create_fixed_size_file(expand_path(name), size, false)
@@ -284,21 +296,21 @@ module Aruba
284
296
  def chmod(*args)
285
297
  args = args.flatten
286
298
 
287
- options = if args.last.kind_of? Hash
299
+ options = if args.last.is_a? Hash
288
300
  args.pop
289
301
  else
290
302
  {}
291
303
  end
292
304
 
293
305
  mode = args.shift
294
- mode = if mode.kind_of? String
306
+ mode = if mode.is_a? String
295
307
  mode.to_i(8)
296
308
  else
297
309
  mode
298
310
  end
299
311
 
300
- args.each { |p| raise "Expected #{p} to be present" unless exist?(p) }
301
- paths = args.map { |p| expand_path(p) }
312
+ args.each { |path| raise "Expected #{path} to be present" unless exist?(path) }
313
+ paths = args.map { |path| expand_path(path) }
302
314
 
303
315
  Aruba.platform.chmod(mode, paths, options)
304
316
 
@@ -336,13 +348,13 @@ module Aruba
336
348
  def remove(*args)
337
349
  args = args.flatten
338
350
 
339
- options = if args.last.kind_of? Hash
351
+ options = if args.last.is_a? Hash
340
352
  args.pop
341
353
  else
342
354
  {}
343
355
  end
344
356
 
345
- args = args.map { |p| expand_path(p) }
357
+ args = args.map { |path| expand_path(path) }
346
358
 
347
359
  Aruba.platform.rm(args, options)
348
360
  end
@@ -354,7 +366,7 @@ module Aruba
354
366
  #
355
367
  # @yield
356
368
  # Pass the content of the given file to this block
357
- def with_file_content(file, &block)
369
+ def with_file_content(file)
358
370
  expect(file).to be_an_existing_path
359
371
 
360
372
  content = read(file).join("\n")
@@ -370,31 +382,21 @@ module Aruba
370
382
  # @param [Array, Path] paths
371
383
  # The paths
372
384
  #
373
- # @result [FileSize]
385
+ # @return [FileSize]
374
386
  # Bytes on disk
375
-
376
387
  def disk_usage(*paths)
377
- expect(paths.flatten).to Aruba::Matchers.all be_an_existing_path
378
- expanded = paths.flatten.map { |p| ArubaPath.new(expand_path(p)) }
379
-
380
- # TODO: change the API so that you could set something like
381
- # aruba.config.fs_allocation_unit_size directly
388
+ paths = paths.flatten
389
+ expect(paths).to Aruba::Matchers.all be_an_existing_path
390
+ expanded = paths.map { |path| expand_path(path) }
382
391
 
383
- typical_fs_unit = 4096 # very typical, except for giant or embedded filesystems
384
- typical_dev_bsize = 512 # google dev_bsize for more info
385
-
386
- block_multiplier = typical_fs_unit / typical_dev_bsize
387
- fs_unit_size = aruba.config.physical_block_size * block_multiplier
388
-
389
- # TODO: the size argument here is unnecessary - ArubaPath should decide
390
- # what the disk usage of a file is (even if Aruba.config needs to be
391
- # read)
392
- deprecated_block_count = fs_unit_size / block_multiplier
393
- Aruba.platform.determine_disk_usage(expanded, deprecated_block_count)
392
+ Aruba.platform.determine_disk_usage(expanded)
394
393
  end
395
394
 
396
395
  # Get size of file
397
396
  #
397
+ # @param [String] name
398
+ # File name
399
+ #
398
400
  # @return [Numeric]
399
401
  # The size of the file
400
402
  def file_size(name)
@@ -14,7 +14,14 @@ module Aruba
14
14
  # @param [#to_s] text
15
15
  # Input
16
16
  def unescape_text(text)
17
- text.gsub('\n', "\n").gsub('\"', '"').gsub('\e', "\e").gsub('\033', "\e").gsub('\016', "\016").gsub('\017', "\017").gsub('\t', "\t")
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,11 +29,10 @@ module Aruba
22
29
  # @param [#to_s] text
23
30
  # Input
24
31
  def extract_text(text)
25
- if Aruba::VERSION < '1'
26
- text.gsub(/(?:\e|\033)\[\d+(?>(;\d+)*)m/, '')
27
- else
28
- text.gsub(/(?:\e|\033)\[\d+(?>(;\d+)*)m/, '').gsub(/\\\[|\\\]/, '').gsub(/\007|\016|\017/, '')
29
- end
32
+ text
33
+ .gsub(/(?:\e|\033)\[\d+(?>(;\d+)*)m/, '')
34
+ .gsub(/\\\[|\\\]/, '')
35
+ .gsub(/\007|\016|\017/, '')
30
36
  end
31
37
 
32
38
  # Unescape special characters and remove ANSI characters
@@ -35,19 +41,19 @@ module Aruba
35
41
  # The text to sanitize
36
42
  def sanitize_text(text)
37
43
  text = unescape_text(text)
38
- text = extract_text(text) if !aruba.config.keep_ansi || aruba.config.remove_ansi_escape_sequences
44
+ text = extract_text(text) if aruba.config.remove_ansi_escape_sequences
39
45
 
40
46
  text.chomp
41
47
  end
42
48
 
43
- # @experimental
44
- #
45
- # Replace variables in command string
49
+ # Replace variables in command string (experimental)
46
50
  #
47
51
  # @param [#to_s] text
48
52
  # The text to parse
49
53
  def replace_variables(text)
50
- text = text.gsub(/<pid-last-command-started>/, last_command_started.pid.to_s) if text.include? '<pid-last-command-started>'
54
+ if text.include? '<pid-last-command-started>'
55
+ text = text.gsub(/<pid-last-command-started>/, last_command_started.pid.to_s)
56
+ end
51
57
 
52
58
  text
53
59
  end
@@ -1,30 +1,21 @@
1
1
  require 'pathname'
2
- require 'delegate'
3
-
4
- require 'aruba/file_size'
5
2
 
6
3
  # Aruba
7
4
  module Aruba
8
5
  # Pathname for aruba files and directories
9
6
  #
10
7
  # @private
11
- class ArubaPath < Delegator
8
+ class ArubaPath
12
9
  def initialize(path)
13
- obj = [path.to_s].flatten
14
-
15
- super obj
16
-
17
- @delegate_sd_obj = obj
10
+ @obj = [path.to_s].flatten
18
11
  end
19
12
 
20
- # Get path
21
- def __getobj__
22
- ::Pathname.new(::File.join(*@delegate_sd_obj))
13
+ def to_str
14
+ to_pathname.to_s
23
15
  end
24
16
 
25
- # Set path
26
- def __setobj__(obj)
27
- @delegate_sd_obj = [obj.to_s].flatten
17
+ def to_s
18
+ to_str
28
19
  end
29
20
 
30
21
  # Add directory/file to path
@@ -39,49 +30,19 @@ module Aruba
39
30
  # puts path
40
31
  # # => path/to/dir.d/subdir.d
41
32
  def push(p)
42
- @delegate_sd_obj << p
33
+ @obj << p
43
34
  end
44
35
  alias << push
45
36
 
46
- # Remove last component of path
37
+ # Remove last pushed component of path
47
38
  #
48
39
  # @example
49
- # path = ArubaPath.new 'path/to/dir.d'
40
+ # path = ArubaPath.new 'path/to'
41
+ # path.push 'dir'
50
42
  # path.pop
51
- # puts path
52
- # # => path/to
43
+ # puts path # => path/to
53
44
  def pop
54
- @delegate_sd_obj.pop
55
- end
56
-
57
- # How many parts has the file name
58
- #
59
- # @return [Integer]
60
- # The count of file name parts
61
- #
62
- # @example
63
- #
64
- # path = ArubaPath.new('path/to/file.txt')
65
- # path.depth # => 3
66
- #
67
- def depth
68
- __getobj__.each_filename.to_a.size
69
- end
70
-
71
- # Path ends with string
72
- #
73
- # @param [String] string
74
- # The string to check
75
- def end_with?(string)
76
- to_s.end_with? string
77
- end
78
-
79
- # Path starts with string
80
- #
81
- # @param [String] string
82
- # The string to check
83
- def start_with?(string)
84
- to_s.start_with? string
45
+ @obj.pop
85
46
  end
86
47
 
87
48
  # Return string at index
@@ -91,67 +52,20 @@ module Aruba
91
52
  to_s[index]
92
53
  end
93
54
 
94
- # Report count of blocks allocated on disk
95
- #
96
- # This reports the amount of blocks which are allocated by the path.
97
- #
98
- # @return [Integer]
99
- # The count of blocks on disk
100
- #
101
- # @deprecated
102
- def blocks
103
- min_bytes_used = minimum_disk_space_used
104
- min_bytes_used / Aruba.config.physical_block_size
105
- end
55
+ private
106
56
 
107
- # TODO: Aruba.config.physical_block_size could be allowed to be nil
108
- # (So the unit size can be autodetected)
109
-
110
- # Report minimum disk space used
111
- #
112
- # This estimates the minimum bytes allocated by the path.
113
- #
114
- # E.g. a 1-byte text file on a typical EXT-3 filesystem takes up 4096 bytes
115
- # (could be more if it was truncated or less for sparse files).
116
- #
117
- # Both `File::Stat` and the `stat()` system call will report 8 `blocks`
118
- # (each "usually" represents 512 bytes). So 8 * 512 is exactly 4096 bytes.
119
- #
120
- # (The "magic" 512 bye implied makes the value of "blocks" so confusing).
121
- #
122
- # Currently Aruba allows you to set what's called the `physical_block_size`,
123
- # which is a bit misleading - it's the "512" value. So if you somehow have a
124
- # "filesystem unit size" of 8192 (instead of a typical 4KB), set the
125
- # `physical_block_size` to 1024 (yes, divide by 8: 8192/8 = 1024).
126
- #
127
- # Ideally, Aruba should provide e.g. `Aruba.config.fs_allocation_unit`
128
- # (with 4096 as the default), so you wouldn't have to "divide by 8".
129
- #
130
- # (typical_fs_unit / typical_dev_bsize = 4096 / 512 = 8)
131
- #
132
- #
133
- # @return [Integer]
134
- # Total bytes allocate
135
- #
136
- # TODO: this is recommended over the above "blocks"
137
- def minimum_disk_space_used
138
- # TODO: replace Aruba.config.physical_block_size
139
- # with something like Aruba.config.fs_allocation_unit
140
- dev_bsize = Aruba.config.physical_block_size
141
-
142
- stat = File::Stat.new(to_s)
143
-
144
- blocks = stat.blocks
145
- return (blocks * dev_bsize) if blocks
146
-
147
- typical_fs_unit = 4096
148
- typical_dev_bsize = 512 # google dev_bsize for more info
149
-
150
- block_multiplier = typical_fs_unit / typical_dev_bsize
151
- fs_unit_size = dev_bsize * block_multiplier
152
- fs_units = (stat.size + fs_unit_size - 1) / fs_unit_size
153
- fs_units = 1 if fs_units.zero?
154
- fs_units * fs_unit_size
57
+ # Get path
58
+ def to_pathname
59
+ current_path = @obj.inject do |path, element|
60
+ if element.start_with? '~'
61
+ element
62
+ elsif Aruba.platform.absolute_path? element
63
+ element
64
+ else
65
+ File.join(path, element)
66
+ end
67
+ end
68
+ ::Pathname.new(current_path)
155
69
  end
156
70
  end
157
71
  end