bovem 2.2.2 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. data/Gemfile +6 -6
  2. data/README.md +1 -0
  3. data/bovem.gemspec +1 -1
  4. data/doc/Bovem.html +5 -5
  5. data/doc/Bovem/Configuration.html +21 -157
  6. data/doc/Bovem/Console.html +39 -39
  7. data/doc/Bovem/ConsoleMethods.html +5 -5
  8. data/doc/Bovem/ConsoleMethods/Interactions.html +21 -21
  9. data/doc/Bovem/ConsoleMethods/Interactions/ClassMethods.html +9 -9
  10. data/doc/Bovem/ConsoleMethods/Logging.html +71 -73
  11. data/doc/Bovem/ConsoleMethods/Logging/ClassMethods.html +9 -9
  12. data/doc/Bovem/ConsoleMethods/Output.html +20 -28
  13. data/doc/Bovem/ConsoleMethods/StyleHandling.html +5 -5
  14. data/doc/Bovem/ConsoleMethods/StyleHandling/ClassMethods.html +7 -7
  15. data/doc/Bovem/Errors.html +5 -5
  16. data/doc/Bovem/Errors/InvalidConfiguration.html +5 -5
  17. data/doc/Bovem/Errors/InvalidLogger.html +5 -5
  18. data/doc/Bovem/Logger.html +126 -69
  19. data/doc/Bovem/Shell.html +16 -16
  20. data/doc/Bovem/ShellMethods.html +5 -5
  21. data/doc/Bovem/ShellMethods/Directories.html +10 -12
  22. data/doc/Bovem/ShellMethods/Execute.html +7 -7
  23. data/doc/Bovem/ShellMethods/General.html +7 -7
  24. data/doc/Bovem/ShellMethods/Read.html +7 -7
  25. data/doc/Bovem/ShellMethods/Write.html +7 -7
  26. data/doc/Bovem/Version.html +7 -7
  27. data/doc/_index.html +6 -6
  28. data/doc/class_list.html +3 -2
  29. data/doc/file.README.html +7 -6
  30. data/doc/file_list.html +2 -1
  31. data/doc/frames.html +1 -1
  32. data/doc/index.html +7 -6
  33. data/doc/js/full_list.js +7 -2
  34. data/doc/method_list.html +72 -183
  35. data/doc/top-level-namespace.html +5 -5
  36. data/lib/bovem.rb +1 -1
  37. data/lib/bovem/configuration.rb +11 -33
  38. data/lib/bovem/console.rb +34 -39
  39. data/lib/bovem/logger.rb +6 -9
  40. data/lib/bovem/shell.rb +25 -26
  41. data/lib/bovem/version.rb +2 -2
  42. data/spec/bovem/configuration_spec.rb +7 -22
  43. data/spec/bovem/console_spec.rb +1 -1
  44. data/spec/bovem/shell_spec.rb +9 -10
  45. data/spec/coverage_helper.rb +3 -0
  46. metadata +5 -5
@@ -6,13 +6,13 @@
6
6
  <title>
7
7
  Top Level Namespace
8
8
 
9
- &mdash; Documentation by YARD 0.8.5.2
9
+ &mdash; Documentation by YARD 0.8.6.2
10
10
 
11
11
  </title>
12
12
 
13
- <link rel="stylesheet" href="css/style.css" type="text/css" media="screen" charset="utf-8" />
13
+ <link rel="stylesheet" href="css/style.css" type="text/css" charset="utf-8" />
14
14
 
15
- <link rel="stylesheet" href="css/common.css" type="text/css" media="screen" charset="utf-8" />
15
+ <link rel="stylesheet" href="css/common.css" type="text/css" charset="utf-8" />
16
16
 
17
17
  <script type="text/javascript" charset="utf-8">
18
18
  hasFrames = window.top.frames.main ? true : false;
@@ -103,9 +103,9 @@
103
103
  </div>
104
104
 
105
105
  <div id="footer">
106
- Generated on Sat Apr 13 12:04:07 2013 by
106
+ Generated on Sun Jul 14 14:51:50 2013 by
107
107
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
108
- 0.8.5.2 (ruby-1.9.3).
108
+ 0.8.6.2 (ruby-1.9.3).
109
109
  </div>
110
110
 
111
111
  </body>
@@ -10,7 +10,7 @@ require "find"
10
10
  require "fileutils"
11
11
  require "lazier"
12
12
 
13
- Lazier.load!(:object)
13
+ Lazier.load!(:object, :boolean, :math)
14
14
 
15
15
  require "bovem/version" if !defined?(Bovem::Version)
16
16
  require "bovem/errors"
@@ -18,9 +18,7 @@ module Bovem
18
18
  # # Configuration file
19
19
  # config.property = "VALUE"
20
20
  # ```
21
- class Configuration
22
- include Lazier::I18n
23
-
21
+ class Configuration < Lazier::Configuration
24
22
  # Creates a new configuration.
25
23
  #
26
24
  # A configuration file is a plain Ruby file with a top-level {Configuration config} object.
@@ -30,8 +28,10 @@ module Bovem
30
28
  # @param logger [Logger] The logger to use for notifications.
31
29
  # @see #parse
32
30
  def initialize(file = nil, overrides = {}, logger = nil)
33
- self.i18n_setup(:bovem, ::File.absolute_path(::Pathname.new(::File.dirname(__FILE__)).to_s + "/../../locales/"))
34
- self.parse(file, overrides, logger)
31
+ super()
32
+
33
+ i18n_setup(:bovem, ::File.absolute_path(::Pathname.new(::File.dirname(__FILE__)).to_s + "/../../locales/"))
34
+ parse(file, overrides, logger)
35
35
  end
36
36
 
37
37
  # Parses a configuration file.
@@ -54,36 +54,16 @@ module Bovem
54
54
  if File.readable?(file) then
55
55
  read_configuration_file(file, logger)
56
56
  else
57
- raise Bovem::Errors::InvalidConfiguration.new(self.i18n.configuration.not_found(file))
57
+ raise Bovem::Errors::InvalidConfiguration.new(i18n.configuration.not_found(file))
58
58
  end
59
59
  end
60
60
 
61
61
  # Apply overrides
62
- if overrides.is_a?(::Hash) then
63
- overrides.each_pair do |k, v|
64
- self.send("#{k}=", v) if self.respond_to?("#{k}=")
65
- end
66
- end
62
+ overrides.each_pair { |k, v| send("#{k}=", v) if self.respond_to?("#{k}=") } if overrides.is_a?(::Hash)
67
63
 
68
64
  self
69
65
  end
70
66
 
71
- # Defines a new property for the configuration.
72
- #
73
- # @param name [Symbol] The name of the property.
74
- # @param options [Hash] A set of options for the property. Currently, only `:default` (which holds the default value) is supported.
75
- def self.property(name, options = {})
76
- options = {} if !options.is_a?(::Hash)
77
-
78
- define_method(name.to_s) do
79
- self.instance_variable_get("@#{name}") || options[:default]
80
- end
81
-
82
- define_method("#{name}=") do |value|
83
- self.instance_variable_set("@#{name}", value)
84
- end
85
- end
86
-
87
67
  private
88
68
  # Reads a configuration file.
89
69
  #
@@ -92,11 +72,11 @@ module Bovem
92
72
  def read_configuration_file(file, logger)
93
73
  begin
94
74
  # Open the file
95
- path = file =~ /^#{File::SEPARATOR}/ ? file : ::Pathname.new(file).realpath.to_s
96
- logger.info(self.i18n.configuration.using(path)) if logger
75
+ path = file =~ /^#{File::SEPARATOR}/ ? file : ::Pathname.new(file).realpath
76
+ logger.info(i18n.configuration.using(path)) if logger
97
77
  eval_file(path)
98
78
  rescue Exception
99
- raise Bovem::Errors::InvalidConfiguration.new(self.i18n.configuration.invalid(file))
79
+ raise Bovem::Errors::InvalidConfiguration.new(i18n.configuration.invalid(file))
100
80
  end
101
81
  end
102
82
 
@@ -104,9 +84,7 @@ module Bovem
104
84
  #
105
85
  # @param path [String] The file to read.
106
86
  def eval_file(path)
107
- self.tap do |config|
108
- eval(::File.read(path))
109
- end
87
+ tap { |config| eval(::File.read(path)) }
110
88
  end
111
89
  end
112
90
  end
@@ -44,7 +44,7 @@ module Bovem
44
44
  # @param styles [String] The styles to parse.
45
45
  # @return [String] A string with ANSI color codes.
46
46
  def parse_styles(styles)
47
- styles.split(/\s*[\s,-]\s*/).collect { |s| self.parse_style(s) }.join("")
47
+ styles.split(/\s*[\s,-]\s*/).collect { |s| parse_style(s) }.join("")
48
48
  end
49
49
 
50
50
  #
@@ -82,7 +82,7 @@ module Bovem
82
82
  stack.pop
83
83
  plain || stack.blank? ? "" : ::Bovem::Console.parse_styles(stack.last)
84
84
  else
85
- styles = $3
85
+ styles = $3.ensure_string
86
86
  replacement = plain ? "" : ::Bovem::Console.parse_styles(styles)
87
87
 
88
88
  if replacement.length > 0 then
@@ -133,9 +133,9 @@ module Bovem
133
133
  # @return [Fixnum] The new indentation width.
134
134
  def with_indentation(width = 3, is_absolute = false)
135
135
  old = @indentation
136
- self.set_indentation(width, is_absolute)
136
+ set_indentation(width, is_absolute)
137
137
  yield
138
- self.set_indentation(old, true)
138
+ set_indentation(old, true)
139
139
 
140
140
  @indentation
141
141
  end
@@ -149,7 +149,7 @@ module Bovem
149
149
  if width.to_integer <= 0 then
150
150
  message
151
151
  else
152
- width = (width == true || width.to_integer < 0 ? self.line_width : width.to_integer)
152
+ width = (width == true || width.to_integer < 0 ? line_width : width.to_integer)
153
153
 
154
154
  message.split("\n").collect { |line|
155
155
  line.length > width ? line.gsub(/(.{1,#{width}})(\s+|$)/, "\\1\n").strip : line
@@ -191,11 +191,11 @@ module Bovem
191
191
  def format(message, suffix = "\n", indent = true, wrap = true, plain = false)
192
192
  rv = message
193
193
 
194
- rv = self.replace_markers(rv, plain) # Replace markers
194
+ rv = replace_markers(rv, plain) # Replace markers
195
195
 
196
196
  # Compute the real width available for the screen, if we both indent and wrap
197
197
  if wrap.is_a?(TrueClass) then
198
- wrap = self.line_width
198
+ wrap = line_width
199
199
 
200
200
  if indent.is_a?(TrueClass) then
201
201
  wrap -= @indentation
@@ -205,9 +205,7 @@ module Bovem
205
205
  end
206
206
  end
207
207
 
208
- rv = self.wrap(rv, wrap) # Wrap
209
- rv = self.indent(rv, indent) # Indent
210
-
208
+ rv = indent(wrap(rv, wrap), indent) # Wrap & Indent
211
209
  rv += suffix.ensure_string if suffix # Add the suffix
212
210
  rv
213
211
  end
@@ -220,17 +218,15 @@ module Bovem
220
218
  # @param plain [Boolean] If ignore color markers into the message.
221
219
  # @return [String] The formatted message.
222
220
  def format_right(message, width = true, go_up = true, plain = false)
223
- message = self.replace_markers(message, plain)
224
-
225
- rv = go_up ? "\e[A" : ""
221
+ message = replace_markers(message, plain)
226
222
 
227
- width = (width == true || width.to_integer < 1 ? self.line_width : width.to_integer)
223
+ width = (width == true || width.to_integer < 1 ? line_width : to_integer)
228
224
 
229
225
  # Get padding
230
226
  padding = width - message.to_s.gsub(/(\e\[[0-9]*[a-z]?)|(\\n)/i, "").length
231
227
 
232
228
  # Return
233
- rv + "\e[0G\e[#{padding}C" + message
229
+ "#{go_up ? "\e[A" : ""}\e[0G\e[#{padding}C#{message}"
234
230
  end
235
231
  end
236
232
 
@@ -259,7 +255,7 @@ module Bovem
259
255
  #
260
256
  # @see #format
261
257
  def write(message, suffix = "\n", indent = true, wrap = false, plain = false, print = true)
262
- rv = self.format(message, suffix, indent, wrap, plain)
258
+ rv = format(message, suffix, indent, wrap, plain)
263
259
  Kernel.puts(rv) if print
264
260
  rv
265
261
  end
@@ -276,7 +272,7 @@ module Bovem
276
272
  #
277
273
  # @see #format
278
274
  def write_banner_aligned(message, suffix = "\n", indent = true, wrap = false, plain = false, print = true)
279
- self.write((" " * (::Bovem::Console.min_banner_length + 3)) + message.ensure_string, suffix, indent, wrap, plain, print)
275
+ write((" " * (::Bovem::Console.min_banner_length + 3)) + message.ensure_string, suffix, indent, wrap, plain, print)
280
276
  end
281
277
 
282
278
  # Writes a status to the output. Valid values are `:ok`, `:pass`, `:fail`, `:warn`.
@@ -299,12 +295,12 @@ module Bovem
299
295
  rv = statuses[status]
300
296
 
301
297
  if print then
302
- banner = self.get_banner(rv[:label], rv[:color])
298
+ banner = get_banner(rv[:label], rv[:color])
303
299
 
304
300
  if right then
305
- Kernel.puts self.format_right(banner + " ", true, go_up, plain)
301
+ Kernel.puts(format_right(banner + " ", true, go_up, plain))
306
302
  else
307
- Kernel.puts self.format(banner + " ", "\n", true, true, plain)
303
+ Kernel.puts(format(banner + " ", "\n", true, true, plain))
308
304
  end
309
305
  end
310
306
 
@@ -340,9 +336,9 @@ module Bovem
340
336
  #
341
337
  # @see #format
342
338
  def begin(message, suffix = "\n", indent = true, wrap = false, plain = false, indented_banner = false, full_colored = false, print = true)
343
- banner = self.get_banner("*", "bright green", full_colored)
344
- message = self.indent(message, indented_banner ? 0 : indent)
345
- self.write(banner + " " + message, suffix, indented_banner ? indent : 0, wrap, plain, print)
339
+ banner = get_banner("*", "bright green", full_colored)
340
+ message = indent(message, indented_banner ? 0 : indent)
341
+ write(banner + " " + message, suffix, indented_banner ? indent : 0, wrap, plain, print)
346
342
  end
347
343
 
348
344
  # Writes a message prepending a red banner and then quits the application.
@@ -359,7 +355,7 @@ module Bovem
359
355
  #
360
356
  # @see #format
361
357
  def fatal(message, suffix = "\n", indent = true, wrap = false, plain = false, indented_banner = false, full_colored = false, return_code = -1, print = true)
362
- self.error(message, suffix, indent, wrap, plain, indented_banner, full_colored, print)
358
+ error(message, suffix, indent, wrap, plain, indented_banner, full_colored, print)
363
359
  Kernel.exit(return_code.to_integer(-1))
364
360
  end
365
361
 
@@ -379,9 +375,9 @@ module Bovem
379
375
  def info(message, suffix = "\n", indent = true, wrap = false, plain = false, indented_banner = false, full_colored = false, print = true, *banner)
380
376
  banner = banner.ensure_array.flatten
381
377
  banner = ["I", "bright cyan"] if banner.blank?
382
- banner = self.get_banner(banner[0], banner[1], full_colored)
383
- message = self.indent(message, indented_banner ? 0 : indent)
384
- self.write(banner + " " + message, suffix, indented_banner ? indent : 0, wrap, plain, print)
378
+ banner = get_banner(banner[0], banner[1], full_colored)
379
+ message = indent(message, indented_banner ? 0 : indent)
380
+ write(banner + " " + message, suffix, indented_banner ? indent : 0, wrap, plain, print)
385
381
  end
386
382
 
387
383
  # Writes a message prepending a magenta banner.
@@ -397,7 +393,7 @@ module Bovem
397
393
  #
398
394
  # @see #format
399
395
  def debug(message, suffix = "\n", indent = true, wrap = false, plain = false, indented_banner = false, full_colored = false, print = true)
400
- self.info(message, suffix, indent, wrap, plain, indented_banner, full_colored, print, ["D", "bright magenta"])
396
+ info(message, suffix, indent, wrap, plain, indented_banner, full_colored, print, ["D", "bright magenta"])
401
397
  end
402
398
 
403
399
  # Writes a message prepending a yellow banner.
@@ -413,8 +409,7 @@ module Bovem
413
409
  #
414
410
  # @see #format
415
411
  def warn(message, suffix = "\n", indent = true, wrap = false, plain = false, indented_banner = false, full_colored = false, print = true)
416
- warn_banner = ["W", "bright yellow"]
417
- self.info(message, suffix, indent, wrap, plain, indented_banner, full_colored, print, warn_banner)
412
+ info(message, suffix, indent, wrap, plain, indented_banner, full_colored, print, ["W", "bright yellow"])
418
413
  end
419
414
 
420
415
  # Writes a message prepending a red banner.
@@ -430,7 +425,7 @@ module Bovem
430
425
  #
431
426
  # @see #format
432
427
  def error(message, suffix = "\n", indent = true, wrap = false, plain = false, indented_banner = false, full_colored = false, print = true)
433
- self.info(message, suffix, indent, wrap, plain, indented_banner, full_colored, print, "E", "bright red")
428
+ info(message, suffix, indent, wrap, plain, indented_banner, full_colored, print, ["E", "bright red"])
434
429
  end
435
430
  end
436
431
 
@@ -466,7 +461,7 @@ module Bovem
466
461
  handle_reply(reply)
467
462
  end
468
463
  end
469
- rescue Interrupt => _
464
+ rescue Interrupt
470
465
  default_value
471
466
  end
472
467
  end
@@ -487,7 +482,7 @@ module Bovem
487
482
  status = nil
488
483
 
489
484
  self.begin(message, suffix, indent, wrap, plain, indented_banner, full_colored) if message.present?
490
- self.with_indentation(block_indentation, block_indentation_absolute) do
485
+ with_indentation(block_indentation, block_indentation_absolute) do
491
486
  rv = block_given? ? yield.ensure_array : [:ok] # Execute block
492
487
  exit_task(message, rv, plain) # Handle task exit
493
488
  status = rv[0] # Return value
@@ -505,10 +500,10 @@ module Bovem
505
500
  # @param plain [Boolean] If ignore color markers into the message.
506
501
  def exit_task(message, rv, plain)
507
502
  if rv[0] == :fatal then
508
- self.status(:fail, plain)
503
+ status(:fail, plain)
509
504
  exit(rv.length > 1 ? rv[1].to_integer : -1)
510
505
  else
511
- self.status(rv[0], plain) if message.present?
506
+ status(rv[0], plain) if message.present?
512
507
  end
513
508
  end
514
509
 
@@ -518,7 +513,7 @@ module Bovem
518
513
  # @return [String|nil] The prompt to use or `nil`, if no message must be prompted.
519
514
  def sanitize_prompt(prompt)
520
515
  if prompt.present?
521
- (prompt.is_a?(TrueClass) ? self.i18n.console.prompt : prompt).gsub(/:?\s*$/, "") + ": "
516
+ (prompt.is_a?(TrueClass) ? i18n.console.prompt : prompt).gsub(/:?\s*$/, "") + ": "
522
517
  else
523
518
  nil
524
519
  end
@@ -540,7 +535,7 @@ module Bovem
540
535
  # @return [Object] The read value.
541
536
  def read_input_value(prompt, echo, default_value = nil)
542
537
  if prompt then
543
- Kernel.print self.format(prompt, false, false)
538
+ Kernel.print(format(prompt, false, false))
544
539
  $stdout.flush
545
540
  end
546
541
 
@@ -573,7 +568,7 @@ module Bovem
573
568
  if reply then
574
569
  throw(:reply, reply)
575
570
  else
576
- self.write(self.i18n.console.unknown_reply, false, false)
571
+ write(i18n.console.unknown_reply, false, false)
577
572
  end
578
573
  end
579
574
  end
@@ -606,7 +601,7 @@ module Bovem
606
601
  def initialize
607
602
  @indentation = 0
608
603
  @indentation_string = " "
609
- self.i18n_setup(:bovem, ::File.absolute_path(::Pathname.new(::File.dirname(__FILE__)).to_s + "/../../locales/"))
604
+ i18n_setup(:bovem, ::File.absolute_path(::Pathname.new(::File.dirname(__FILE__)).to_s + "/../../locales/"))
610
605
  end
611
606
 
612
607
  # Get the width of the terminal.
@@ -37,17 +37,14 @@ module Bovem
37
37
  # @param formatter [Proc] The formatter to use for logging.
38
38
  # @return [Logger] The new logger.
39
39
  def self.create(file = nil, level = Logger::INFO, formatter = nil)
40
- file ||= self.default_file
41
-
42
40
  begin
43
- rv = self.new(self.get_real_file(file))
41
+ rv = new(get_real_file(file || default_file))
42
+ rv.level = level.to_integer
43
+ rv.formatter = formatter || default_formatter
44
+ rv
44
45
  rescue
45
46
  raise Bovem::Errors::InvalidLogger
46
47
  end
47
-
48
- rv.level = level.to_i
49
- rv.formatter = formatter || self.default_formatter
50
- rv
51
48
  end
52
49
 
53
50
  # Translates a file to standard input or standard output in some special cases.
@@ -81,14 +78,14 @@ module Bovem
81
78
  else :white
82
79
  end
83
80
 
84
- header = ::Bovem::Console.replace_markers("{mark=bright-#{color}}[%s T+%0.5f] %s:{/mark}" %[datetime.strftime("%Y/%b/%d %H:%M:%S"), [datetime.to_f - self.start_time.to_f, 0].max, severity.rjust(5)])
81
+ header = ::Bovem::Console.replace_markers("{mark=bright-#{color}}[%s T+%0.5f] %s:{/mark}" %[datetime.strftime("%Y/%b/%d %H:%M:%S"), [datetime.to_f - start_time.to_f, 0].max, severity.rjust(5)])
85
82
  "%s %s\n" % [header, msg]
86
83
  }
87
84
  end
88
85
 
89
86
  # The log time of the first logger. This allows to show a `T+0.1234` information into the log.
90
87
  # @return [Time] The log time of the first logger.
91
- def self.start_time
88
+ def start_time
92
89
  @start_time ||= ::Time.now
93
90
  end
94
91
  end
@@ -34,7 +34,7 @@ module Bovem
34
34
  # @param fatal [Boolean] If quit in case of fatal errors.
35
35
  # @return [Array] Variables for error handling
36
36
  def setup_error_handling(entries, fatal)
37
- [fatal ? :fatal : :error, self.i18n.shell, entries.length == 1 ? entries[0] : entries]
37
+ [fatal ? :fatal : :error, i18n.shell, entries.length == 1 ? entries[0] : entries]
38
38
  end
39
39
 
40
40
  # Shows errors when a directory creation failed.
@@ -43,7 +43,7 @@ module Bovem
43
43
  # @param entries [Array] The list of entries which failed.
44
44
  # @param fatal [Boolean] If quit in case of fatal errors.
45
45
  def show_general_failure(e, general_error, entries, fatal)
46
- locale = self.i18n.shell
46
+ locale = i18n.shell
47
47
 
48
48
  @console.error(locale.send(general_error))
49
49
  @console.with_indentation(11) do
@@ -65,7 +65,7 @@ module Bovem
65
65
  def check(path, tests)
66
66
  path = path.ensure_string
67
67
 
68
- tests.ensure_array.all? {|test|
68
+ tests.ensure_array.all? { |test|
69
69
  # Adjust test name
70
70
  test = test.ensure_string.strip
71
71
 
@@ -101,7 +101,7 @@ module Bovem
101
101
  patterns = normalize_patterns(patterns, by_extension, case_sensitive)
102
102
 
103
103
  directories.each do |directory|
104
- if self.check(directory, [:directory, :readable, :executable]) then
104
+ if check(directory, [:directory, :readable, :executable]) then
105
105
  Find.find(directory) do |entry|
106
106
  found = patterns.blank? ? true : match_pattern(entry, patterns, by_extension, &block)
107
107
 
@@ -161,7 +161,7 @@ module Bovem
161
161
  # @param fatal [Boolean] If quit in case of fatal errors.
162
162
  # @return [Boolean] `true` if operation succeeded, `false` otherwise.
163
163
  def copy(src, dst, run = true, show_errors = false, fatal = true)
164
- self.copy_or_move(src, dst, :copy, run, show_errors, fatal)
164
+ copy_or_move(src, dst, :copy, run, show_errors, fatal)
165
165
  end
166
166
 
167
167
  # Moves a set of files or directory to another location.
@@ -173,7 +173,7 @@ module Bovem
173
173
  # @param fatal [Boolean] If quit in case of fatal errors.
174
174
  # @return [Boolean] `true` if operation succeeded, `false` otherwise.
175
175
  def move(src, dst, run = true, show_errors = false, fatal = true)
176
- self.copy_or_move(src, dst, :move, run, show_errors, fatal)
176
+ copy_or_move(src, dst, :move, run, show_errors, fatal)
177
177
  end
178
178
 
179
179
  # Copies or moves a set of files or directory to another location.
@@ -215,7 +215,7 @@ module Bovem
215
215
  single = !src.is_a?(Array)
216
216
  src = single ? File.expand_path(src) : src.collect {|s| File.expand_path(s) }
217
217
 
218
- [operation, self.i18n.shell.send(operation), single, src, File.expand_path(dst.ensure_string)]
218
+ [operation, i18n.shell.send(operation), single, src, File.expand_path(dst.ensure_string)]
219
219
  end
220
220
 
221
221
  # Shows which copy or move operation are going to executed.
@@ -225,7 +225,7 @@ module Bovem
225
225
  # @param src [String|Array] The entries to copy or move. If is an Array, `dst` is assumed to be a directory.
226
226
  # @param dst [String] The destination. **Any existing entries will be overwritten.** Any required directory will be created.
227
227
  def dry_run_copy_or_move(single, operation, src, dst)
228
- locale = self.i18n.shell
228
+ locale = i18n.shell
229
229
 
230
230
  if single then
231
231
  @console.warn(locale.copy_move_single_dry(operation))
@@ -251,14 +251,14 @@ module Bovem
251
251
  # @return [String] The prepared destination.
252
252
  def prepare_destination(single, src, dst, operation, show_errors, fatal)
253
253
  dst_dir = single ? File.dirname(dst) : dst
254
- has_dir = self.check(dst_dir, :dir)
254
+ has_dir = check(dst_dir, :dir)
255
255
 
256
256
  # Create directory
257
- has_dir = self.create_directories(dst_dir, 0755, true, show_errors, fatal) if !has_dir
257
+ has_dir = create_directories(dst_dir, 0755, true, show_errors, fatal) if !has_dir
258
258
  throw(:rv, false) if !has_dir
259
259
 
260
- if single && self.check(dst, :dir) then
261
- @console.send(fatal ? :fatal : :error, self.i18n.shell.copy_move_single_to_directory(operation, src, dst))
260
+ if single && check(dst, :dir) then
261
+ @console.send(fatal ? :fatal : :error, i18n.shell.copy_move_single_to_directory(operation, src, dst))
262
262
  throw(:rv, false)
263
263
  end
264
264
 
@@ -273,8 +273,8 @@ module Bovem
273
273
  def check_sources(src, operation, fatal)
274
274
  # Check that every file is existing
275
275
  src.ensure_array.each do |s|
276
- if !self.check(s, :exists) then
277
- @console.send(fatal ? :fatal : :error, self.i18n.shell.copy_move_src_not_found(operation, s))
276
+ if !check(s, :exists) then
277
+ @console.send(fatal ? :fatal : :error, i18n.shell.copy_move_src_not_found(operation, s))
278
278
  throw(:rv, false)
279
279
  end
280
280
  end
@@ -291,7 +291,7 @@ module Bovem
291
291
  # @param show_errors [Boolean] If show errors.
292
292
  # @param fatal [Boolean] If quit in case of fatal errors.
293
293
  def execute_copy_or_move(src, dst, dst_dir, single, operation, operation_s, show_errors, fatal)
294
- locale = self.i18n.shell
294
+ locale = i18n.shell
295
295
 
296
296
  begin
297
297
  FileUtils.send(operation == :move ? :mv : :cp_r, src, dst, {noop: false, verbose: false})
@@ -349,7 +349,7 @@ module Bovem
349
349
  def run(command, message = nil, run = true, show_exit = true, show_output = false, show_command = false, fatal = true)
350
350
  rv = {status: 0, output: ""}
351
351
  command = command.ensure_string
352
- locale = self.i18n.shell
352
+ locale = i18n.shell
353
353
 
354
354
  # Show the command
355
355
  @console.begin(message) if message.present?
@@ -376,7 +376,7 @@ module Bovem
376
376
  # @return [Boolean] `true` if operation succeeded, `false` otherwise.
377
377
  def delete(files, run = true, show_errors = false, fatal = true)
378
378
  rv = true
379
- locale = self.i18n.shell
379
+ locale = i18n.shell
380
380
  files = files.ensure_array.compact.collect {|f| File.expand_path(f.ensure_string) }
381
381
 
382
382
  if !run then
@@ -410,7 +410,7 @@ module Bovem
410
410
  def execute_command(command, show_command, show_output)
411
411
  output = ""
412
412
 
413
- @console.info(self.i18n.shell.run(command)) if show_command
413
+ @console.info(i18n.shell.run(command)) if show_command
414
414
  status = ::Open4::popen4(command + " 2>&1") { |_, _, stdout, _|
415
415
  stdout.each_line do |line|
416
416
  output << line
@@ -431,8 +431,7 @@ module Bovem
431
431
  # @param show_messages [Boolean] Show informative messages about working directory changes.
432
432
  # @return [Boolean] `true` if the directory was valid and the code executed, `false` otherwise.
433
433
  def within_directory(directory, restore = true, show_messages = false)
434
- rv = false
435
- locale = self.i18n.shell
434
+ locale = i18n.shell
436
435
 
437
436
  directory = File.expand_path(directory.ensure_string)
438
437
  original = Dir.pwd
@@ -479,7 +478,7 @@ module Bovem
479
478
  # @return [Boolean] `true` if operation succeeded, `false` otherwise.
480
479
  def enter_directory(directory, show_message, message)
481
480
  begin
482
- raise ArgumentError if !self.check(directory, [:directory, :executable])
481
+ raise ArgumentError if !check(directory, [:directory, :executable])
483
482
  @console.info(message) if show_message
484
483
  Dir.chdir(directory)
485
484
  true
@@ -491,7 +490,7 @@ module Bovem
491
490
  # Show which directory are going to be created.
492
491
  # @param directories [Array] The list of directories to create.
493
492
  def dry_run_directory_creation(directories)
494
- @console.warn(self.i18n.shell.mkdir_dry)
493
+ @console.warn(i18n.shell.mkdir_dry)
495
494
  @console.with_indentation(11) do
496
495
  directories.each do |directory| @console.write(directory) end
497
496
  end
@@ -507,12 +506,12 @@ module Bovem
507
506
  # @return [Boolean] `true` if operation succeeded, `false` otherwise.
508
507
  def try_create_directory(directory, mode, fatal, directories, show_errors)
509
508
  rv = false
510
- locale = self.i18n.shell
509
+ locale = i18n.shell
511
510
 
512
511
  # Perform tests
513
- if self.check(directory, :directory) then
512
+ if check(directory, :directory) then
514
513
  @console.send(fatal ? :fatal : :error, locale.mkdir_existing(directory))
515
- elsif self.check(directory, :exist) then
514
+ elsif check(directory, :exist) then
516
515
  @console.send(fatal ? :fatal : :error, locale.mkdir_file(directory))
517
516
  else
518
517
  rv = create_directory(directory, mode, fatal, directories, show_errors)
@@ -568,7 +567,7 @@ module Bovem
568
567
  # Initializes a new Shell.
569
568
  def initialize
570
569
  @console = ::Bovem::Console.instance
571
- self.i18n_setup(:bovem, ::File.absolute_path(::Pathname.new(::File.dirname(__FILE__)).to_s + "/../../locales/"))
570
+ i18n_setup(:bovem, ::File.absolute_path(::Pathname.new(::File.dirname(__FILE__)).to_s + "/../../locales/"))
572
571
  end
573
572
  end
574
573
  end