cowtech-lib 1.9.1 → 1.9.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/cowtech-lib.gemspec +1 -1
- data/lib/cowtech-lib/console.rb +4 -4
- data/lib/cowtech-lib/script.rb +2 -2
- data/lib/cowtech-lib/shell.rb +7 -7
- data/lib/cowtech-lib/version.rb +1 -1
- metadata +2 -1
data/cowtech-lib.gemspec
CHANGED
data/lib/cowtech-lib/console.rb
CHANGED
@@ -27,9 +27,9 @@
|
|
27
27
|
|
28
28
|
require "rexml/document"
|
29
29
|
|
30
|
-
class
|
31
|
-
def
|
32
|
-
[self]
|
30
|
+
class Object
|
31
|
+
def force_array
|
32
|
+
self.is_a?(Array) ? self : [self]
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
@@ -285,7 +285,7 @@ module Cowtech
|
|
285
285
|
msg += " " unless msg =~ / ^/
|
286
286
|
|
287
287
|
# Turn choices into regular expressions
|
288
|
-
regexps = (args[:valids] || []).
|
288
|
+
regexps = (args[:valids] || []).force_array.collect do |valid|
|
289
289
|
unless valid.is_a?(Regexp) then
|
290
290
|
valid = Regexp.new((valid !~ /^\^/ ? "^" : "") + valid + (valid !~ /\$$/ ? "$" : ""), Regexp::EXTENDED + (args[:case_sensitive] ? Regexp::IGNORECASE : 0), "U")
|
291
291
|
else
|
data/lib/cowtech-lib/script.rb
CHANGED
@@ -82,7 +82,7 @@ module Cowtech
|
|
82
82
|
# * <em>dots</em>: If show dots after message
|
83
83
|
def task(args)
|
84
84
|
if args.fetch(:show_msg, true) then
|
85
|
-
@console.write(:begin => args[:msg], :dots => args[:dots])
|
85
|
+
@console.write(:begin => args[:msg], :dots => args[:dots])
|
86
86
|
@console.indent_set(3)
|
87
87
|
end
|
88
88
|
|
@@ -93,7 +93,7 @@ module Cowtech
|
|
93
93
|
|
94
94
|
# Show the result
|
95
95
|
if args.fetch(:show_result, true) then
|
96
|
-
@console.status(:status => rv[0], :fatal => false)
|
96
|
+
@console.status(:status => rv[0], :fatal => false)
|
97
97
|
@console.indent_set(-3)
|
98
98
|
end
|
99
99
|
|
data/lib/cowtech-lib/shell.rb
CHANGED
@@ -105,7 +105,7 @@ module Cowtech
|
|
105
105
|
# Returns: <em>true</em> if any of tests had success, <em>false</em> otherwise
|
106
106
|
def file_check?(args)
|
107
107
|
rv = false
|
108
|
-
tests = (args[:tests] || [:exists]).
|
108
|
+
tests = (args[:tests] || [:exists]).force_array
|
109
109
|
|
110
110
|
if args[:file] then
|
111
111
|
rv = true
|
@@ -127,7 +127,7 @@ module Cowtech
|
|
127
127
|
# Returns: <em>true</em> if operation had success, <em>false</em> otherwise.
|
128
128
|
def delete_files!(args)
|
129
129
|
rv = true
|
130
|
-
files = args[:files].
|
130
|
+
files = args[:files].force_array
|
131
131
|
|
132
132
|
begin
|
133
133
|
FileUtils.rm_r(files, {:noop => @console.skip_commands, :verbose => @console.skip_commands, :secure => true})
|
@@ -169,7 +169,7 @@ module Cowtech
|
|
169
169
|
# Returns: <em>true</em> if operation had success, <em>false</em> otherwise.
|
170
170
|
def create_directories(args)
|
171
171
|
rv = true
|
172
|
-
files = args[:files].
|
172
|
+
files = args[:files].force_array
|
173
173
|
|
174
174
|
files.each do |file|
|
175
175
|
if self.file_check?(:files => file, :tests => :exists) then
|
@@ -229,7 +229,7 @@ module Cowtech
|
|
229
229
|
|
230
230
|
# If we are copy or moving to a directory
|
231
231
|
if args[:destination_is_directory] then
|
232
|
-
files = (args[:files] || []).
|
232
|
+
files = (args[:files] || []).force_array
|
233
233
|
dest = args[:dest]
|
234
234
|
dest += "/" if self.file_check?(dest, :directory) and dest !~ /\/$/
|
235
235
|
|
@@ -325,8 +325,8 @@ module Cowtech
|
|
325
325
|
# TODO: E se patterns è vuoto?
|
326
326
|
rv = []
|
327
327
|
|
328
|
-
paths = args[:paths].
|
329
|
-
string_patterns = args[:patterns].
|
328
|
+
paths = args[:paths].force_array
|
329
|
+
string_patterns = args[:patterns].force_array
|
330
330
|
|
331
331
|
if paths.length > 0 then
|
332
332
|
# Convert patterns to regexp
|
@@ -362,7 +362,7 @@ module Cowtech
|
|
362
362
|
#
|
363
363
|
# Returns: List of found files.
|
364
364
|
def find_by_extension(args)
|
365
|
-
args[:patterns] = (args[:extensions] || "").
|
365
|
+
args[:patterns] = (args[:extensions] || "").force_array.collect do |extension|
|
366
366
|
Regexp.new(extension + "$", Regexp::IGNORECASE)
|
367
367
|
end
|
368
368
|
|
data/lib/cowtech-lib/version.rb
CHANGED