utilitypack 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +4 -0
- data/COPYING +18 -0
- data/README +7 -0
- data/Rakefile +94 -0
- data/examples/7zip.rb +27 -0
- data/examples/rar.rb +26 -0
- data/lib/utility_pack.rb +8 -0
- data/lib/utility_pack/7zip.rb +18 -0
- data/lib/utility_pack/core_ext.rb +4 -0
- data/lib/utility_pack/core_ext/array.rb +36 -0
- data/lib/utility_pack/core_ext/file.rb +27 -0
- data/lib/utility_pack/core_ext/hash.rb +25 -0
- data/lib/utility_pack/core_ext/string.rb +21 -0
- data/lib/utility_pack/datetime.rb +27 -0
- data/lib/utility_pack/ie.rb +19 -0
- data/lib/utility_pack/persistenthash.rb +36 -0
- data/lib/utility_pack/rar.rb +18 -0
- data/lib/utility_pack/version.rb +9 -0
- data/lib/utility_pack/win32.rb +5 -0
- data/lib/utility_pack/win32/core_helpers.rb +11 -0
- data/lib/utility_pack/win32/file_helpers.rb +35 -0
- data/lib/utility_pack/win32/process_helpers.rb +14 -0
- data/lib/utility_pack/win32/shell_helpers.rb +32 -0
- data/test/test_core_extensions_array.rb +21 -0
- data/test/test_core_extensions_file.rb +27 -0
- data/test/test_core_extensions_hash.rb +15 -0
- data/test/test_core_extensions_string.rb +13 -0
- data/test/test_persistenthash.rb +20 -0
- metadata +101 -0
data/CHANGELOG
ADDED
data/COPYING
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
Copyright (c) 2008 Brian Pfeil
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to
|
5
|
+
deal in the Software without restriction, including without limitation the
|
6
|
+
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
7
|
+
sell copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
16
|
+
THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
17
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
18
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/testtask'
|
3
|
+
require 'rake/rdoctask'
|
4
|
+
require 'rake/clean'
|
5
|
+
require 'rake/gempackagetask'
|
6
|
+
|
7
|
+
# get version info from source file
|
8
|
+
$:.unshift(File.join(File.dirname(__FILE__), 'lib'))
|
9
|
+
require 'utility_pack/version'
|
10
|
+
|
11
|
+
windows = (PLATFORM =~ /win32|cygwin/)
|
12
|
+
BAT = windows ? ".bat" : ""
|
13
|
+
SUDO = windows ? "" : "sudo"
|
14
|
+
|
15
|
+
PKG_NAME = "utilitypack"
|
16
|
+
PKG_VERSION = UtilityPack::VERSION::STRING
|
17
|
+
CLEAN.include ['*.gem', 'pkg/', 'doc/rdoc']
|
18
|
+
RDOC_OPTS = ['--quiet', '--title', "Utility Pack",
|
19
|
+
"--opname", "index.html",
|
20
|
+
"--line-numbers",
|
21
|
+
"--main", "README",
|
22
|
+
"--inline-source"]
|
23
|
+
|
24
|
+
# Test Tasks ---------------------------------------------------------
|
25
|
+
|
26
|
+
desc "Run all tests"
|
27
|
+
task :test_all => [:test_units]
|
28
|
+
task :ta => [:test_all]
|
29
|
+
|
30
|
+
task :tu => [:test_units]
|
31
|
+
|
32
|
+
Rake::TestTask.new("test_units") do |t|
|
33
|
+
t.test_files = FileList['test/test*.rb']
|
34
|
+
t.verbose = false
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
desc "Packages up Utility Pack."
|
40
|
+
task :default => [:package]
|
41
|
+
|
42
|
+
desc "creates package"
|
43
|
+
task :package => [:clean]
|
44
|
+
|
45
|
+
desc "creates documentation"
|
46
|
+
task :doc => [:rdoc]
|
47
|
+
|
48
|
+
Rake::RDocTask.new do |rdoc|
|
49
|
+
rdoc.rdoc_dir = 'doc/rdoc'
|
50
|
+
rdoc.options += RDOC_OPTS
|
51
|
+
rdoc.main = "README"
|
52
|
+
rdoc.title = "Utility Pack"
|
53
|
+
rdoc.rdoc_files.add ['README', 'CHANGELOG', 'COPYING', 'lib/**/*.rb']
|
54
|
+
end
|
55
|
+
|
56
|
+
spec =
|
57
|
+
Gem::Specification.new do |s|
|
58
|
+
s.name = PKG_NAME
|
59
|
+
s.version = PKG_VERSION
|
60
|
+
s.platform = Gem::Platform::RUBY
|
61
|
+
s.has_rdoc = true
|
62
|
+
s.extra_rdoc_files = ["README", "CHANGELOG", "COPYING"]
|
63
|
+
s.rdoc_options = RDOC_OPTS
|
64
|
+
s.summary = "Library of useful utilities"
|
65
|
+
s.description = s.summary
|
66
|
+
s.author = "Brian Pfeil"
|
67
|
+
s.email = 'brian.pfeil@gmail.com'
|
68
|
+
s.homepage = 'http://brianpfeil.com'
|
69
|
+
#s.executables = ['desktopsearch']
|
70
|
+
s.required_ruby_version = '>= 1.8.2'
|
71
|
+
s.files = %w(COPYING README Rakefile) +
|
72
|
+
Dir.glob("{bin,doc,test,lib,examples,extras,share,contrib}/**/*") +
|
73
|
+
Dir.glob("ext/**/*.{h,c,rb}") +
|
74
|
+
Dir.glob("examples/**/*.rb") +
|
75
|
+
Dir.glob("tools/*.rb")
|
76
|
+
s.require_path = "lib"
|
77
|
+
s.bindir = "bin"
|
78
|
+
end
|
79
|
+
|
80
|
+
Rake::GemPackageTask.new(spec) do |p|
|
81
|
+
p.need_tar = false
|
82
|
+
p.need_zip = false
|
83
|
+
p.gem_spec = spec
|
84
|
+
end
|
85
|
+
|
86
|
+
desc "installs gem"
|
87
|
+
task :install => [:package] do
|
88
|
+
sh %{gem#{BAT} install pkg/#{PKG_NAME}-#{PKG_VERSION}}
|
89
|
+
end
|
90
|
+
|
91
|
+
desc "uninstalls gem"
|
92
|
+
task :uninstall => [:clean] do
|
93
|
+
sh %{#{SUDO} gem#{BAT} uninstall #{PKG_NAME} -x}
|
94
|
+
end
|
data/examples/7zip.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
require 'utility_pack'
|
3
|
+
|
4
|
+
include FileUtils
|
5
|
+
|
6
|
+
def run archive_path, paths, type
|
7
|
+
puts "Deleting #{archive_path}"
|
8
|
+
rm_f archive_path
|
9
|
+
if File.exists?(archive_path)
|
10
|
+
puts "Failed to delete #{archive_path}. Exiting."
|
11
|
+
exit
|
12
|
+
else
|
13
|
+
puts "Successfully deleted #{archive_path}"
|
14
|
+
end
|
15
|
+
|
16
|
+
UtilityPack::SevenZip.send(type, archive_path, paths)
|
17
|
+
puts "Size of #{archive_path} is #{File.stat(archive_path).size/(1024.0*1024.0)} MB"
|
18
|
+
end
|
19
|
+
|
20
|
+
paths = [["c:\\temp\\ifb"], "C:\\Program Files\\7-Zip"]
|
21
|
+
|
22
|
+
# create regular zip file
|
23
|
+
run "c:\\temp\\a.zip", paths, :zip
|
24
|
+
|
25
|
+
# create self extracting file
|
26
|
+
run "c:\\temp\\a.exe", paths, :sfx
|
27
|
+
|
data/examples/rar.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
require 'utility_pack'
|
3
|
+
|
4
|
+
include FileUtils
|
5
|
+
|
6
|
+
def run archive_path, paths, type
|
7
|
+
puts "Deleting #{archive_path}"
|
8
|
+
rm_f archive_path
|
9
|
+
if File.exists?(archive_path)
|
10
|
+
puts "Failed to delete #{archive_path}. Exiting."
|
11
|
+
exit
|
12
|
+
else
|
13
|
+
puts "Successfully deleted #{archive_path}"
|
14
|
+
end
|
15
|
+
|
16
|
+
UtilityPack::Rar.send(type, archive_path, paths)
|
17
|
+
puts "Size of #{archive_path} is #{File.stat(archive_path).size/(1024.0*1024.0)} MB"
|
18
|
+
end
|
19
|
+
|
20
|
+
paths = [["c:\\temp\\ifb"], "C:\\Program Files\\7-Zip"]
|
21
|
+
|
22
|
+
# create regular zip file
|
23
|
+
run "c:\\temp\\a.rar", paths, :rar
|
24
|
+
|
25
|
+
# create self extracting file
|
26
|
+
run "c:\\temp\\a.exe", paths, :sfx
|
data/lib/utility_pack.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
module UtilityPack
|
2
|
+
# Wrapper around the rar archiving and compression utility
|
3
|
+
module SevenZip
|
4
|
+
include UtilityPack::Win32
|
5
|
+
|
6
|
+
# creates a 7-zip archive for the specified files/directories
|
7
|
+
# archive_path - archive file that'll be created
|
8
|
+
# *paths - files/directories to archive
|
9
|
+
def self.zip archive_path, *paths
|
10
|
+
CoreHelpers.s "7za a -tzip \"#{archive_path}\" " +paths.flatten.collect{|p| "\"#{p}\""}.join(' ')
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.sfx archive_path, *paths
|
14
|
+
CoreHelpers.s "7za a -sfx7z.sfx \"#{archive_path}\" " +paths.flatten.collect{|p| "\"#{p}\""}.join(' ')
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module UtilityPack
|
2
|
+
module CoreExtensions
|
3
|
+
module Array
|
4
|
+
|
5
|
+
# returns a random element from the array
|
6
|
+
# if count is specified, a array of unique random elements is returned
|
7
|
+
def random(count = 1)
|
8
|
+
|
9
|
+
raise "Invalid argument (count must be >1)" if count < 1
|
10
|
+
|
11
|
+
if count == 1
|
12
|
+
self[rand(self.size)]
|
13
|
+
else
|
14
|
+
raise "Invalid argument. The size of the array is #{self.size} and \
|
15
|
+
you are requesting #{count} random elements" if count > self.size
|
16
|
+
|
17
|
+
r = []
|
18
|
+
while r.size != count
|
19
|
+
tmp = self[rand(self.size)]
|
20
|
+
r << tmp unless r.include?(tmp)
|
21
|
+
end
|
22
|
+
|
23
|
+
if count == 1
|
24
|
+
r = r[0]
|
25
|
+
end
|
26
|
+
r
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
class Array #:nodoc:
|
35
|
+
include UtilityPack::CoreExtensions::Array
|
36
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module UtilityPack
|
2
|
+
module CoreExtensions
|
3
|
+
module File
|
4
|
+
|
5
|
+
module InstanceMethods
|
6
|
+
end
|
7
|
+
|
8
|
+
module ClassMethods
|
9
|
+
|
10
|
+
def read_file(path)
|
11
|
+
::File.open(path, 'r') {|f| f.read }
|
12
|
+
end
|
13
|
+
|
14
|
+
def write_file(path, s)
|
15
|
+
::File.open(path, 'w') {|f| f.write(s) }
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
class File #:nodoc:
|
25
|
+
include UtilityPack::CoreExtensions::File::InstanceMethods
|
26
|
+
extend UtilityPack::CoreExtensions::File::ClassMethods
|
27
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module UtilityPack
|
2
|
+
module CoreExtensions
|
3
|
+
module Hash
|
4
|
+
|
5
|
+
module InstanceMethods
|
6
|
+
end
|
7
|
+
|
8
|
+
module ClassMethods
|
9
|
+
|
10
|
+
def transform_keys_to_symbols(value)
|
11
|
+
return value if not value.is_a?(::Hash)
|
12
|
+
hash = value.inject({}){|memo,(k,v)| memo[k.to_sym] = self.transform_keys_to_symbols(v); memo}
|
13
|
+
return hash
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class Hash #:nodoc:
|
23
|
+
include UtilityPack::CoreExtensions::Hash::InstanceMethods
|
24
|
+
extend UtilityPack::CoreExtensions::Hash::ClassMethods
|
25
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module UtilityPack
|
2
|
+
module CoreExtensions
|
3
|
+
module String
|
4
|
+
|
5
|
+
# returns a new string instance populated with the provided variable values.
|
6
|
+
# template variables are of the form :<variable name>. e.g. :name
|
7
|
+
def fill(values = {})
|
8
|
+
s = self.clone
|
9
|
+
values.each do |key, value|
|
10
|
+
s.gsub!(":#{key}", value.to_s) if value.respond_to? :to_s
|
11
|
+
end
|
12
|
+
s
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
class String #:nodoc:
|
20
|
+
include UtilityPack::CoreExtensions::String
|
21
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module UtilityPack
|
2
|
+
module DateTimeHelpers
|
3
|
+
|
4
|
+
class HourMinSec < Time
|
5
|
+
|
6
|
+
def <=>(other)
|
7
|
+
# only compare based on hour, minutes, and seconds (leave date portion off)
|
8
|
+
self_seconds = (self.hour * (60 * 60)) + (self.min * 60) + self.sec
|
9
|
+
other_seconds = (other.hour * (60 * 60)) + (other.min * 60) + other.sec
|
10
|
+
|
11
|
+
if self_seconds < other_seconds
|
12
|
+
return -1
|
13
|
+
elsif self_seconds == other_seconds
|
14
|
+
return 0
|
15
|
+
else
|
16
|
+
return 1
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.timestamp_for_filename
|
23
|
+
Time.now.strftime("%Y-%m-%d_%H.%M.%S")
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
|
3
|
+
module UtilityPack
|
4
|
+
module InternetExplorerHelpers
|
5
|
+
include UtilityPack::Win32
|
6
|
+
|
7
|
+
CACHE_DIRECTORIES = [
|
8
|
+
"c:/windows/Temporary Internet Files",
|
9
|
+
"C:/Documents and Settings/#{ENV['USERNAME']}/Local Settings/Temporary Internet Files"
|
10
|
+
]
|
11
|
+
|
12
|
+
def self.clear_cache
|
13
|
+
CACHE_DIRECTORIES.each do |dir|
|
14
|
+
FileHelpers.delete Dir["#{dir}/**/*"] if File.exists?(dir)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'json/pure'
|
3
|
+
require 'utility_pack/core_ext/file'
|
4
|
+
|
5
|
+
module UtilityPack
|
6
|
+
|
7
|
+
class PersistentHash
|
8
|
+
def initialize path
|
9
|
+
@path = path
|
10
|
+
end
|
11
|
+
|
12
|
+
def json_parse_file(path)
|
13
|
+
JSON.parse(File.read_file(path))
|
14
|
+
end
|
15
|
+
|
16
|
+
def load
|
17
|
+
File.exists?(@path) ? json_parse_file(@path) : {}
|
18
|
+
end
|
19
|
+
|
20
|
+
def save h
|
21
|
+
File.write_file @path, h.to_json
|
22
|
+
end
|
23
|
+
|
24
|
+
def [](key)
|
25
|
+
load[key]
|
26
|
+
end
|
27
|
+
|
28
|
+
def []=(key, value)
|
29
|
+
h = load
|
30
|
+
h[key] = value
|
31
|
+
save(h)
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module UtilityPack
|
2
|
+
# Wrapper around the rar archiving and compression utility
|
3
|
+
module Rar
|
4
|
+
include UtilityPack::Win32
|
5
|
+
|
6
|
+
# creates a rar archive for the specified files/directories
|
7
|
+
# archive_path - archive file that'll be created
|
8
|
+
# *paths - files/directories to archive
|
9
|
+
def self.rar archive_path, *paths
|
10
|
+
CoreHelpers.s "rar a -m5 \"#{archive_path}\" " +paths.flatten.collect{|p| "\"#{p}\""}.join(' ')
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.sfx archive_path, *paths
|
14
|
+
CoreHelpers.s "rar a -sfx \"#{archive_path}\" " +paths.flatten.collect{|p| "\"#{p}\""}.join(' ')
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
|
3
|
+
module UtilityPack
|
4
|
+
module Win32
|
5
|
+
module FileHelpers
|
6
|
+
|
7
|
+
MAX_DELETE_FILE_RETRIES = 20
|
8
|
+
|
9
|
+
def delete_file path
|
10
|
+
count = 0
|
11
|
+
while File.exist?(path) && count < MAX_DELETE_FILE_RETRIES do
|
12
|
+
puts "Deleting file #{path}"
|
13
|
+
rm_f path
|
14
|
+
count = count + 1
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def delete_directory path
|
19
|
+
puts "Deleting directory #{path}"
|
20
|
+
rm_rf path if File.directory?(path)
|
21
|
+
end
|
22
|
+
|
23
|
+
def delete(*args)
|
24
|
+
args.flatten.each do |path|
|
25
|
+
delete_file path unless File.directory?(path)
|
26
|
+
delete_directory path if File.directory?(path)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
# add all instance methods as singleton methods also
|
31
|
+
self.extend(self)
|
32
|
+
include FileUtils
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module UtilityPack
|
2
|
+
module Win32
|
3
|
+
module ShellHelpers
|
4
|
+
include UtilityPack::Win32::CoreHelpers
|
5
|
+
|
6
|
+
def cmd_then_exit(cmd, *options)
|
7
|
+
options << "/c"
|
8
|
+
s "cmd #{options.join(' ')} #{cmd}"
|
9
|
+
end
|
10
|
+
|
11
|
+
def cmd_then_remain(cmd, *options)
|
12
|
+
options << "/k"
|
13
|
+
s "cmd #{options.join(' ')} #{cmd}"
|
14
|
+
end
|
15
|
+
|
16
|
+
def start_async(cmd, *options)
|
17
|
+
s "cmd /c start \"\" #{options.join(' ')} #{cmd}"
|
18
|
+
end
|
19
|
+
|
20
|
+
def start_and_wait(cmd, *options)
|
21
|
+
options << "/wait"
|
22
|
+
start_async(cmd, options)
|
23
|
+
end
|
24
|
+
|
25
|
+
def cmd_prompt_here(*options)
|
26
|
+
directory_path = ENV['dir'] || ''
|
27
|
+
cmd_then_remain "(cd /d #{directory_path} & cls)", options
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
$:.unshift File.join(File.dirname(__FILE__),'..','lib')
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
require 'utility_pack/core_ext/array'
|
5
|
+
|
6
|
+
class TestCoreExtensionsArray < Test::Unit::TestCase
|
7
|
+
|
8
|
+
def test_random
|
9
|
+
# functional
|
10
|
+
assert([1].random == 1)
|
11
|
+
assert([].random == nil)
|
12
|
+
assert([1].random(1) == 1)
|
13
|
+
assert([1,2,3].random(3).sort == [1,2,3])
|
14
|
+
|
15
|
+
# bounds checking
|
16
|
+
assert_raise(RuntimeError) { [1].random(0) }
|
17
|
+
assert_raise(RuntimeError) { [1].random(-1) }
|
18
|
+
assert_raise(RuntimeError) { [1].random(2) }
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
$:.unshift File.join(File.dirname(__FILE__),'..','lib')
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
require 'utility_pack/core_ext/file'
|
5
|
+
|
6
|
+
require 'tempfile'
|
7
|
+
|
8
|
+
|
9
|
+
class TestCoreExtensionsFile < Test::Unit::TestCase
|
10
|
+
|
11
|
+
def test_write_file
|
12
|
+
s = "hello world"
|
13
|
+
file = Tempfile.new('test_write_file')
|
14
|
+
File.write_file(file.path, s)
|
15
|
+
assert_equal s, File.open(file.path) {|f| f.read}
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
def test_read_file
|
20
|
+
s = "hello world"
|
21
|
+
file = Tempfile.new('test_read_file')
|
22
|
+
file.write(s)
|
23
|
+
file.close
|
24
|
+
assert_equal s, File.read_file(file.path)
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
$:.unshift File.join(File.dirname(__FILE__),'..','lib')
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
require 'utility_pack/core_ext/hash'
|
5
|
+
|
6
|
+
class TestCoreExtensionsHash < Test::Unit::TestCase
|
7
|
+
|
8
|
+
def test_transform_keys_to_symbols
|
9
|
+
h1 = {'name' => 'brian', 'age' => 33, 'son' => {'name', 'wyatt'}}
|
10
|
+
h2 = Hash.transform_keys_to_symbols(h1)
|
11
|
+
assert_equal h1['name'], h2[:name]
|
12
|
+
assert_equal 'wyatt', h2[:son][:name]
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
$:.unshift File.join(File.dirname(__FILE__),'..','lib')
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
require 'utility_pack/core_ext/string'
|
5
|
+
|
6
|
+
class TestCoreExtensionsString < Test::Unit::TestCase
|
7
|
+
|
8
|
+
def test_fill
|
9
|
+
assert_equal "hello world", "hello :name".fill(:name => 'world')
|
10
|
+
assert_equal "1 2 3 3 2 1", ":one 2 3 3 2 :one".fill(:one => '1')
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
$:.unshift File.join(File.dirname(__FILE__),'..','lib')
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
require 'utility_pack/persistenthash'
|
5
|
+
|
6
|
+
class TestPersistentHash < Test::Unit::TestCase
|
7
|
+
include UtilityPack
|
8
|
+
|
9
|
+
def test_save
|
10
|
+
file = Tempfile.new('test_save')
|
11
|
+
path = file.path
|
12
|
+
file.close
|
13
|
+
file.unlink
|
14
|
+
ph = PersistentHash.new(path)
|
15
|
+
value = 'brian'
|
16
|
+
ph[:name] = {:value => value}
|
17
|
+
assert_equal ph['name']['value'], value
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
metadata
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: utilitypack
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 5
|
8
|
+
- 1
|
9
|
+
version: 0.5.1
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Brian Pfeil
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2011-11-06 01:00:00 -04:00
|
18
|
+
default_executable:
|
19
|
+
dependencies: []
|
20
|
+
|
21
|
+
description: Library of useful utilities
|
22
|
+
email: brian.pfeil@gmail.com
|
23
|
+
executables: []
|
24
|
+
|
25
|
+
extensions: []
|
26
|
+
|
27
|
+
extra_rdoc_files:
|
28
|
+
- README
|
29
|
+
- CHANGELOG
|
30
|
+
- COPYING
|
31
|
+
files:
|
32
|
+
- COPYING
|
33
|
+
- README
|
34
|
+
- Rakefile
|
35
|
+
- test/test_core_extensions_array.rb
|
36
|
+
- test/test_core_extensions_file.rb
|
37
|
+
- test/test_core_extensions_hash.rb
|
38
|
+
- test/test_core_extensions_string.rb
|
39
|
+
- test/test_persistenthash.rb
|
40
|
+
- lib/utility_pack/7zip.rb
|
41
|
+
- lib/utility_pack/core_ext/array.rb
|
42
|
+
- lib/utility_pack/core_ext/file.rb
|
43
|
+
- lib/utility_pack/core_ext/hash.rb
|
44
|
+
- lib/utility_pack/core_ext/string.rb
|
45
|
+
- lib/utility_pack/core_ext.rb
|
46
|
+
- lib/utility_pack/datetime.rb
|
47
|
+
- lib/utility_pack/ie.rb
|
48
|
+
- lib/utility_pack/persistenthash.rb
|
49
|
+
- lib/utility_pack/rar.rb
|
50
|
+
- lib/utility_pack/version.rb
|
51
|
+
- lib/utility_pack/win32/core_helpers.rb
|
52
|
+
- lib/utility_pack/win32/file_helpers.rb
|
53
|
+
- lib/utility_pack/win32/process_helpers.rb
|
54
|
+
- lib/utility_pack/win32/shell_helpers.rb
|
55
|
+
- lib/utility_pack/win32.rb
|
56
|
+
- lib/utility_pack.rb
|
57
|
+
- examples/7zip.rb
|
58
|
+
- examples/rar.rb
|
59
|
+
- CHANGELOG
|
60
|
+
has_rdoc: true
|
61
|
+
homepage: http://brianpfeil.com
|
62
|
+
licenses: []
|
63
|
+
|
64
|
+
post_install_message:
|
65
|
+
rdoc_options:
|
66
|
+
- --quiet
|
67
|
+
- --title
|
68
|
+
- Utility Pack
|
69
|
+
- --opname
|
70
|
+
- index.html
|
71
|
+
- --line-numbers
|
72
|
+
- --main
|
73
|
+
- README
|
74
|
+
- --inline-source
|
75
|
+
require_paths:
|
76
|
+
- lib
|
77
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
segments:
|
82
|
+
- 1
|
83
|
+
- 8
|
84
|
+
- 2
|
85
|
+
version: 1.8.2
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
segments:
|
91
|
+
- 0
|
92
|
+
version: "0"
|
93
|
+
requirements: []
|
94
|
+
|
95
|
+
rubyforge_project:
|
96
|
+
rubygems_version: 1.3.6
|
97
|
+
signing_key:
|
98
|
+
specification_version: 3
|
99
|
+
summary: Library of useful utilities
|
100
|
+
test_files: []
|
101
|
+
|