sysadmin 0.1.5 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +33 -0
- data/VERSION +1 -1
- data/doc/ChangeLog +12 -0
- data/doc/README.ja +5 -2
- data/lib/sysadmin.rb +2 -2
- data/lib/sysadmin/array_ext.rb +9 -1
- data/lib/sysadmin/dir_ext.rb +5 -7
- data/lib/sysadmin/version.rb +10 -0
- data/spec/lib/sysadmin/array_ext_spec.rb +79 -13
- data/spec/lib/sysadmin/dir_ext_spec.rb +44 -26
- data/spec/lib/sysadmin/directory_spec.rb +44 -30
- data/spec/lib/sysadmin/file_ext_spec.rb +121 -83
- data/spec/lib/sysadmin/time_ext_spec.rb +14 -9
- data/spec/lib/sysadmin/util_spec.rb +7 -6
- data/spec/lib/sysadmin_spec.rb +5 -7
- data/sysadmin.gemspec +5 -4
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 10b36152122215a87a4edbab6face729b218cd16
|
4
|
+
data.tar.gz: 5865cca7b0751bacbff571528ca0b262523dc446
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1429f30d5cda6c7ca8d668d9cbaa6cd2c6982832187ff5273bae7ba341a281ae3a953a0a4696beff5c36f46caaed5f8f1a1bdc3546088ff35c1ad238171722bc
|
7
|
+
data.tar.gz: 3e29da3a47acd1b5b1d2452107105c3b1cfe3867170c59980fa14bb60512b83ca4fd6fe1bd7520baf77bd034554983ff3863318fcbb931baa28e6f54856c77f7
|
data/README.md
CHANGED
@@ -12,6 +12,39 @@ The collection of libraries for managing the system.
|
|
12
12
|
See doc/README(.ja).
|
13
13
|
|
14
14
|
|
15
|
+
Purpose
|
16
|
+
-------
|
17
|
+
|
18
|
+
**Array**
|
19
|
+
|
20
|
+
Extension for Array class. Array operation to be used well in the System Management.
|
21
|
+
|
22
|
+
|
23
|
+
**Dir**
|
24
|
+
|
25
|
+
Method filelist provides an intelligent directory scanning.
|
26
|
+
|
27
|
+
|
28
|
+
**Sysadmin::Directory**
|
29
|
+
|
30
|
+
Return file list matching regexp.
|
31
|
+
|
32
|
+
|
33
|
+
**File**
|
34
|
+
|
35
|
+
Providing useful file operations. Method zread is open zip and other type files. *line methods provides append, replace, and remove line of file.
|
36
|
+
|
37
|
+
|
38
|
+
**Time**
|
39
|
+
|
40
|
+
Providing strict_parse methods. This new method return nil when specified invalid date.
|
41
|
+
|
42
|
+
|
43
|
+
**Util**
|
44
|
+
|
45
|
+
Other useful methods.
|
46
|
+
|
47
|
+
|
15
48
|
Development
|
16
49
|
-----------
|
17
50
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/doc/ChangeLog
CHANGED
data/doc/README.ja
CHANGED
data/lib/sysadmin.rb
CHANGED
@@ -2,16 +2,16 @@
|
|
2
2
|
# Name:: Sysadmin
|
3
3
|
# Author:: 774 <http://id774.net>
|
4
4
|
# Created:: Mar 23, 2012
|
5
|
-
# Updated::
|
5
|
+
# Updated:: Nov 22, 2013
|
6
6
|
# Copyright:: 774 Copyright (c) 2012
|
7
7
|
# License:: Licensed under the GNU GENERAL PUBLIC LICENSE, Version 3.0.
|
8
8
|
|
9
9
|
module Sysadmin
|
10
|
-
VERSION = "0.1.5"
|
11
10
|
require File.dirname(__FILE__) + "/sysadmin/util"
|
12
11
|
require File.dirname(__FILE__) + "/sysadmin/array_ext"
|
13
12
|
require File.dirname(__FILE__) + "/sysadmin/file_ext"
|
14
13
|
require File.dirname(__FILE__) + "/sysadmin/dir_ext"
|
15
14
|
require File.dirname(__FILE__) + "/sysadmin/directory"
|
16
15
|
require File.dirname(__FILE__) + "/sysadmin/time_ext"
|
16
|
+
require File.dirname(__FILE__) + "/sysadmin/version"
|
17
17
|
end
|
data/lib/sysadmin/array_ext.rb
CHANGED
@@ -1,12 +1,20 @@
|
|
1
1
|
# Name:: Sysadmin::ArrayExtension
|
2
2
|
# Author:: 774 <http://id774.net>
|
3
3
|
# Created:: Aug 20, 2013
|
4
|
-
# Updated::
|
4
|
+
# Updated:: Nov 21, 2013
|
5
5
|
# Copyright:: 774 Copyright (c) 2013
|
6
6
|
# License:: Licensed under the GNU GENERAL PUBLIC LICENSE, Version 3.0.
|
7
7
|
|
8
8
|
class Array
|
9
9
|
|
10
|
+
def sum
|
11
|
+
inject(0){|result, item| result + item.to_i}
|
12
|
+
end
|
13
|
+
|
14
|
+
def sumf
|
15
|
+
inject(0){|result, item| result + item.to_f}
|
16
|
+
end
|
17
|
+
|
10
18
|
def average
|
11
19
|
inject(0.0) { |sum, i| sum += i } / size
|
12
20
|
end
|
data/lib/sysadmin/dir_ext.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# Name:: Sysadmin::DirExtension
|
2
2
|
# Author:: 774 <http://id774.net>
|
3
3
|
# Created:: Jul 17, 2012
|
4
|
-
# Updated::
|
4
|
+
# Updated:: Nov 22, 2013
|
5
5
|
# Copyright:: 774 Copyright (c) 2012
|
6
6
|
# License:: Licensed under the GNU GENERAL PUBLIC LICENSE, Version 3.0.
|
7
7
|
|
@@ -10,14 +10,11 @@ module Sysadmin
|
|
10
10
|
|
11
11
|
def Dir.filelist(dir, sub_directory = false)
|
12
12
|
array = Array.new
|
13
|
+
|
13
14
|
if (FileTest.file?(dir))
|
14
15
|
array << dir
|
15
16
|
else
|
16
|
-
|
17
|
-
dir = dir + "/**/"
|
18
|
-
else
|
19
|
-
dir = dir + "/"
|
20
|
-
end
|
17
|
+
dir = sub_directory ? dir + "/**/" : dir = dir + "/"
|
21
18
|
Dir::glob(dir).each do |d|
|
22
19
|
if (FileTest.directory?(d))
|
23
20
|
Dir::foreach(d) do |f|
|
@@ -28,7 +25,8 @@ module Sysadmin
|
|
28
25
|
end
|
29
26
|
end
|
30
27
|
end
|
31
|
-
|
28
|
+
|
29
|
+
array
|
32
30
|
end
|
33
31
|
|
34
32
|
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# Name:: Sysadmin::Version
|
2
|
+
# Author:: 774 <http://id774.net>
|
3
|
+
# Created:: Nov 22, 2013
|
4
|
+
# Updated:: Nov 22, 2013
|
5
|
+
# Copyright:: 774 Copyright (c) 2013
|
6
|
+
# License:: Licensed under the GNU GENERAL PUBLIC LICENSE, Version 3.0.
|
7
|
+
|
8
|
+
module Sysadmin
|
9
|
+
VERSION = "0.2.0"
|
10
|
+
end
|
@@ -2,25 +2,91 @@
|
|
2
2
|
|
3
3
|
require File.dirname(__FILE__) + '/../../spec_helper'
|
4
4
|
|
5
|
-
describe
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
5
|
+
describe Array do
|
6
|
+
describe '#sum' do
|
7
|
+
context 'with no arguments' do
|
8
|
+
subject { array.sum }
|
9
|
+
|
10
|
+
context 'if all elements are integer' do
|
11
|
+
let(:array) { [1, 2, 3, 4, 5] }
|
12
|
+
it 'should return integer summary of elements' do
|
13
|
+
expect(subject).to eql 15
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
context 'if array contains string' do
|
18
|
+
let(:array) { [1, 2, 3, '4', 5] }
|
19
|
+
it 'should return integer summary of elements' do
|
20
|
+
expect(subject).to eql 15
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context 'if array contains nil' do
|
25
|
+
let(:array) { [1, 2, 3, nil, 5] }
|
26
|
+
it 'should return integer summary of elements' do
|
27
|
+
expect(subject).to eql 11
|
28
|
+
end
|
29
|
+
end
|
10
30
|
end
|
11
31
|
end
|
12
32
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
33
|
+
describe '#sumf' do
|
34
|
+
context 'with no arguments' do
|
35
|
+
subject { array.sumf }
|
36
|
+
|
37
|
+
context 'if all elements are integer' do
|
38
|
+
let(:array) { [1, 2, 3, 4, 5] }
|
39
|
+
it 'should return float summary of elements' do
|
40
|
+
expect(subject).to eql 15.0
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context 'if array contains string' do
|
45
|
+
let(:array) { [1, 2, 3, '4.2', 5] }
|
46
|
+
it 'should return float summary of elements' do
|
47
|
+
expect(subject).to eql 15.2
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
context 'if array contains string' do
|
52
|
+
let(:array) { [1, 2, 3, nil, 5] }
|
53
|
+
it 'should return float summary of elements' do
|
54
|
+
expect(subject).to eql 11.0
|
55
|
+
end
|
56
|
+
end
|
17
57
|
end
|
18
58
|
end
|
19
59
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
60
|
+
describe '#average' do
|
61
|
+
context 'with no arguments' do
|
62
|
+
subject { array.average }
|
63
|
+
|
64
|
+
let(:array) { [8, 9, 7, 6, 5, 4] }
|
65
|
+
it 'should return average of array' do
|
66
|
+
expect(subject).to eql 6.5
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
describe '#variance' do
|
72
|
+
context 'with no arguments' do
|
73
|
+
subject { array.variance }
|
74
|
+
|
75
|
+
let(:array) { [8, 9, 7, 6, 5, 4] }
|
76
|
+
it 'should return variance of array' do
|
77
|
+
expect(subject).to eql 2.9166666666666665
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
describe '#standard_deviation' do
|
83
|
+
context 'with no arguments' do
|
84
|
+
subject { array.standard_deviation }
|
85
|
+
|
86
|
+
let(:array) { [8, 9, 7, 6, 5, 4] }
|
87
|
+
it 'should return standard deviation of array' do
|
88
|
+
expect(subject).to eql 1.707825127659933
|
89
|
+
end
|
24
90
|
end
|
25
91
|
end
|
26
92
|
end
|
@@ -2,42 +2,60 @@
|
|
2
2
|
|
3
3
|
require File.dirname(__FILE__) + '/../../spec_helper'
|
4
4
|
|
5
|
-
describe
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
5
|
+
describe Dir do
|
6
|
+
describe '#filelist' do
|
7
|
+
context 'specity directory name' do
|
8
|
+
subject { Dir.filelist(dir) }
|
9
|
+
|
10
|
+
let(:dir) { File.expand_path("../../test_dir/a", File.dirname(__FILE__)) }
|
11
|
+
it 'should return file list in directories' do
|
12
|
+
expect(subject).to have(2).items
|
11
13
|
end
|
12
|
-
end
|
13
14
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
15
|
+
context 'if subdirectory option is true' do
|
16
|
+
subject { Dir.filelist(dir, sub_directory = true) }
|
17
|
+
|
18
|
+
let(:dir) { File.expand_path("../../test_dir", File.dirname(__FILE__)) }
|
19
|
+
it 'should return file name (not in sub directories)' do
|
20
|
+
expect(subject).to have(9).items
|
21
|
+
end
|
18
22
|
end
|
19
|
-
end
|
20
23
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
24
|
+
context 'if subdirectory option is false' do
|
25
|
+
subject { Dir.filelist(dir, sub_directory = false) }
|
26
|
+
|
27
|
+
let(:dir) { File.expand_path("../../test_dir/a", File.dirname(__FILE__)) }
|
28
|
+
it 'should return file name not including sub directories' do
|
29
|
+
expect(subject).to have(2).items
|
30
|
+
end
|
25
31
|
end
|
26
32
|
end
|
27
33
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
34
|
+
context 'specity file name' do
|
35
|
+
subject { Dir.filelist(file) }
|
36
|
+
|
37
|
+
let(:file) { File.expand_path("../../test_dir/a/d.txt", File.dirname(__FILE__)) }
|
38
|
+
it 'should return the file name' do
|
39
|
+
expect(subject).to have(1).item
|
32
40
|
end
|
33
|
-
end
|
34
41
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
42
|
+
context 'if subdirectory option is true' do
|
43
|
+
subject { Dir.filelist(file, sub_directory = true) }
|
44
|
+
|
45
|
+
let(:file) { File.expand_path("../../test_dir/a/d.txt", File.dirname(__FILE__)) }
|
46
|
+
it 'should return file list including subdirectories' do
|
47
|
+
expect(subject).to have(1).item
|
48
|
+
end
|
39
49
|
end
|
40
|
-
end
|
41
50
|
|
51
|
+
context 'if subdirectory option is true' do
|
52
|
+
subject { Dir.filelist(file, sub_directory = false) }
|
53
|
+
|
54
|
+
let(:file) { File.expand_path("../../test_dir/a/d.txt", File.dirname(__FILE__)) }
|
55
|
+
it 'should return file list not including subdirectories' do
|
56
|
+
expect(subject).to have(1).item
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
42
60
|
end
|
43
61
|
end
|
@@ -2,54 +2,68 @@
|
|
2
2
|
|
3
3
|
require File.dirname(__FILE__) + '/../../spec_helper'
|
4
4
|
|
5
|
-
describe Sysadmin::Directory
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
5
|
+
describe Sysadmin::Directory do
|
6
|
+
describe '#map' do
|
7
|
+
context 'specify directory name' do
|
8
|
+
subject { Sysadmin::Directory.new(dir) }
|
9
|
+
let(:dir) { File.expand_path("../../test_dir", File.dirname(__FILE__)) }
|
10
|
+
|
11
|
+
it 'should return file list in directory' do
|
12
|
+
expect(subject).to have(9).items
|
11
13
|
end
|
12
14
|
end
|
13
15
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
16
|
+
context 'specify directory name' do
|
17
|
+
subject { Sysadmin::Directory.new(dir) }
|
18
|
+
let(:dir) { File.expand_path("../../test_dir/a", File.dirname(__FILE__)) }
|
19
|
+
|
20
|
+
it 'should return file list in directory' do
|
21
|
+
expect(subject).to have(4).items
|
18
22
|
end
|
19
23
|
end
|
20
24
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
+
context 'specify directory name' do
|
26
|
+
subject { Sysadmin::Directory.new(dir) }
|
27
|
+
let(:dir) { File.expand_path("../../test_dir/a/g", File.dirname(__FILE__)) }
|
28
|
+
|
29
|
+
it 'should return file list in directory' do
|
30
|
+
expect(subject).to have(2).items
|
25
31
|
end
|
26
32
|
end
|
27
33
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
34
|
+
context 'specify directory name' do
|
35
|
+
subject { Sysadmin::Directory.new(dir) }
|
36
|
+
let(:dir) { File.expand_path("../../test_dir/b", File.dirname(__FILE__)) }
|
37
|
+
|
38
|
+
it 'should return file list in directory' do
|
39
|
+
expect(subject).to have(2).items
|
32
40
|
end
|
33
41
|
end
|
34
42
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
43
|
+
context 'specify directory name with grep' do
|
44
|
+
subject { Sysadmin::Directory.new(dir).grep(/\.txt/) }
|
45
|
+
let(:dir) { File.expand_path("../../test_dir", File.dirname(__FILE__)) }
|
46
|
+
|
47
|
+
it 'should return file list matching regexp' do
|
48
|
+
expect(subject).to have(9).item
|
39
49
|
end
|
40
50
|
end
|
41
51
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
52
|
+
context 'specify directory name with grep' do
|
53
|
+
subject { Sysadmin::Directory.new(dir).grep(/d\.txt/) }
|
54
|
+
let(:dir) { File.expand_path("../../test_dir", File.dirname(__FILE__)) }
|
55
|
+
|
56
|
+
it 'should return file list matching regexp' do
|
57
|
+
expect(subject).to have(1).item
|
46
58
|
end
|
47
59
|
end
|
48
60
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
61
|
+
context 'specify directory name with grep and take' do
|
62
|
+
subject { Sysadmin::Directory.new(dir).grep(/\.txt/).take(3) }
|
63
|
+
let(:dir) { File.expand_path("../../test_dir", File.dirname(__FILE__)) }
|
64
|
+
|
65
|
+
it 'should return picked up file list matching regexp' do
|
66
|
+
expect(subject).to have(3).items
|
53
67
|
end
|
54
68
|
end
|
55
69
|
|
@@ -4,115 +4,153 @@ require File.dirname(__FILE__) + '/../../spec_helper'
|
|
4
4
|
require 'tempfile'
|
5
5
|
require 'zlib'
|
6
6
|
|
7
|
-
describe
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
File.zread(@uncompressed.path).should == expect
|
16
|
-
@uncompressed.close
|
17
|
-
end
|
18
|
-
end
|
7
|
+
describe File do
|
8
|
+
describe '#zread' do
|
9
|
+
context 'read uncompressed file' do
|
10
|
+
subject {
|
11
|
+
@uncompressed = Tempfile::new("test.txt")
|
12
|
+
File.append_line(:file => @uncompressed.path, :str => try)
|
13
|
+
File.zread(@uncompressed.path)
|
14
|
+
}
|
19
15
|
|
20
|
-
|
21
|
-
|
22
|
-
try = "compressed"
|
23
|
-
expect = "compressed\n"
|
24
|
-
@compressed = Tempfile::new("test2.txt")
|
25
|
-
Zlib::GzipWriter.open(@compressed.path) do |gz|
|
26
|
-
gz.puts try
|
27
|
-
end
|
16
|
+
let(:try) { "uncompressed" }
|
17
|
+
let(:expected) { "uncompressed\n" }
|
28
18
|
|
29
|
-
|
30
|
-
|
19
|
+
it 'should read successful' do
|
20
|
+
expect(subject).to eql expected
|
21
|
+
@uncompressed.close
|
22
|
+
end
|
31
23
|
end
|
32
|
-
end
|
33
24
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
25
|
+
context 'read compressed file' do
|
26
|
+
subject {
|
27
|
+
@compressed = Tempfile::new("test2.txt")
|
28
|
+
Zlib::GzipWriter.open(@compressed.path) do |gz|
|
29
|
+
gz.puts try
|
30
|
+
end
|
31
|
+
File.zread(@compressed.path)
|
32
|
+
}
|
33
|
+
|
34
|
+
let(:try) { "compressed" }
|
35
|
+
let(:expected) { "compressed\n" }
|
39
36
|
|
40
|
-
|
41
|
-
|
37
|
+
it 'should read successful' do
|
38
|
+
expect(subject).to eql expected
|
39
|
+
@compressed.close
|
42
40
|
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe '#append_line' do
|
45
|
+
context 'with arguments file and strings' do
|
43
46
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
+
subject {
|
48
|
+
@testfile = Tempfile::new("test.txt")
|
49
|
+
3.times do
|
50
|
+
File.append_line(:file => @testfile.path, :str => src)
|
47
51
|
end
|
48
52
|
}
|
49
|
-
@testfile.close
|
50
|
-
end
|
51
|
-
end
|
52
53
|
|
53
|
-
|
54
|
-
|
55
|
-
@testfile = Tempfile::new("test.txt")
|
56
|
-
src = 'hoge'
|
57
|
-
try = 'fuga'
|
58
|
-
expect = "fuga\n"
|
54
|
+
let(:src) { 'hoge' }
|
55
|
+
let(:expected) { "hoge\n" }
|
59
56
|
|
60
|
-
|
61
|
-
|
57
|
+
it 'should append strings to last line of file' do
|
58
|
+
subject
|
59
|
+
|
60
|
+
open(@testfile.path) { |file|
|
61
|
+
while line = file.gets
|
62
|
+
expect(line).to eql expected
|
63
|
+
end
|
64
|
+
}
|
65
|
+
@testfile.close
|
62
66
|
end
|
63
|
-
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
describe '#replace_line' do
|
71
|
+
context 'with arguments file and strings' do
|
64
72
|
|
65
|
-
|
66
|
-
|
67
|
-
|
73
|
+
subject {
|
74
|
+
@testfile = Tempfile::new("test.txt")
|
75
|
+
3.times do
|
76
|
+
File.append_line(:file => @testfile.path, :str => src)
|
68
77
|
end
|
78
|
+
File.replace_line(:file => @testfile.path, :src => src, :dst => try)
|
69
79
|
}
|
70
|
-
@testfile.close
|
71
|
-
end
|
72
|
-
end
|
73
80
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
src = 'hoge'
|
78
|
-
replace = 'fuga'
|
79
|
-
erase = 'hoge'
|
80
|
-
expect = "fuga\n"
|
81
|
+
let(:src) { 'hoge' }
|
82
|
+
let(:try) { 'fuga' }
|
83
|
+
let(:expected) { "fuga\n" }
|
81
84
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
85
|
+
it 'should replace line in file' do
|
86
|
+
subject
|
87
|
+
|
88
|
+
open(@testfile.path) { |file|
|
89
|
+
while line = file.gets
|
90
|
+
expect(line).to eql expected
|
91
|
+
end
|
92
|
+
}
|
93
|
+
@testfile.close
|
88
94
|
end
|
89
|
-
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
describe '#remove_line' do
|
99
|
+
context 'with arguments file and strings' do
|
90
100
|
|
91
|
-
|
92
|
-
|
93
|
-
|
101
|
+
subject {
|
102
|
+
@testfile = Tempfile::new("test.txt")
|
103
|
+
3.times do
|
104
|
+
File.append_line(:file => @testfile.path, :str => src)
|
94
105
|
end
|
106
|
+
File.replace_line(:file => @testfile.path, :src => src, :dst => replace)
|
107
|
+
2.times do
|
108
|
+
File.append_line(:file => @testfile.path, :str => src)
|
109
|
+
end
|
110
|
+
File.remove_line(:file => @testfile.path, :str => erase)
|
95
111
|
}
|
96
|
-
|
112
|
+
|
113
|
+
let(:src) { 'hoge' }
|
114
|
+
let(:replace) { 'fuga' }
|
115
|
+
let(:erase) { 'hoge' }
|
116
|
+
let(:expected) { "fuga\n" }
|
117
|
+
|
118
|
+
it 'should remove line from file' do
|
119
|
+
subject
|
120
|
+
|
121
|
+
open(@testfile.path) { |file|
|
122
|
+
while line = file.gets
|
123
|
+
expect(line).to eql expected
|
124
|
+
end
|
125
|
+
}
|
126
|
+
@testfile.close
|
127
|
+
end
|
97
128
|
end
|
98
129
|
end
|
99
130
|
|
100
|
-
|
101
|
-
|
102
|
-
@testfile = Tempfile::new("test.txt")
|
103
|
-
init = 'init'
|
104
|
-
second = 'second'
|
105
|
-
expect = "second\n"
|
131
|
+
describe '#new_line' do
|
132
|
+
context 'with arguments file and strings' do
|
106
133
|
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
while line = file.gets
|
112
|
-
line.should == expect
|
113
|
-
end
|
134
|
+
subject {
|
135
|
+
@testfile = Tempfile::new("test.txt")
|
136
|
+
File.new_line(:file => @testfile.path, :str => init)
|
137
|
+
File.new_line(:file => @testfile.path, :str => second)
|
114
138
|
}
|
115
|
-
|
139
|
+
|
140
|
+
let(:init) { 'init' }
|
141
|
+
let(:second) { 'second' }
|
142
|
+
let(:expect) { "second\n" }
|
143
|
+
|
144
|
+
it 'should create file of string lines' do
|
145
|
+
subject
|
146
|
+
|
147
|
+
open(@testfile.path) { |file|
|
148
|
+
while line = file.gets
|
149
|
+
line.should == expect
|
150
|
+
end
|
151
|
+
}
|
152
|
+
@testfile.close
|
153
|
+
end
|
116
154
|
end
|
117
155
|
end
|
118
156
|
end
|
@@ -2,18 +2,23 @@
|
|
2
2
|
|
3
3
|
require File.dirname(__FILE__) + '/../../spec_helper'
|
4
4
|
|
5
|
-
describe
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
5
|
+
describe Time do
|
6
|
+
describe '#strict_parse' do
|
7
|
+
context 'with valid date' do
|
8
|
+
subject { Time.strict_parse("2012/09/27 11:45:00") }
|
9
|
+
|
10
|
+
let(:expected) { Time.parse("2012/09/27 11:45:00") }
|
11
|
+
|
12
|
+
it 'should be returned valid date' do
|
13
|
+
expect(subject).to eql expected
|
11
14
|
end
|
12
15
|
end
|
13
16
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
+
context 'with invalid date' do
|
18
|
+
subject { Time.strict_parse("hoge") }
|
19
|
+
|
20
|
+
it 'should be returned nil' do
|
21
|
+
expect(subject).to be_nil
|
17
22
|
end
|
18
23
|
end
|
19
24
|
end
|
@@ -3,14 +3,15 @@
|
|
3
3
|
require File.dirname(__FILE__) + '/../../spec_helper'
|
4
4
|
|
5
5
|
describe Sysadmin::Util do
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
describe '#create_multi_dimensional_hash' do
|
7
|
+
context 'with no arguments' do
|
8
|
+
subject {
|
9
9
|
h = Sysadmin::Util.create_multi_dimensional_hash
|
10
10
|
h["a"]["b"]["c"]["d"] = 10
|
11
|
-
|
12
|
-
|
13
|
-
|
11
|
+
}
|
12
|
+
|
13
|
+
it 'should be returned multi dimensional hash' do
|
14
|
+
expect(subject).to eql 10
|
14
15
|
end
|
15
16
|
end
|
16
17
|
end
|
data/spec/lib/sysadmin_spec.rb
CHANGED
@@ -2,12 +2,10 @@
|
|
2
2
|
|
3
3
|
require File.dirname(__FILE__) + '/../spec_helper'
|
4
4
|
|
5
|
-
describe Sysadmin
|
6
|
-
context
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
Sysadmin.const_get(:VERSION).should == expect
|
11
|
-
end
|
5
|
+
describe Sysadmin do
|
6
|
+
context "VERSION" do
|
7
|
+
subject { Sysadmin::VERSION }
|
8
|
+
|
9
|
+
it { expect(subject).to eql "0.2.0" }
|
12
10
|
end
|
13
11
|
end
|
data/sysadmin.gemspec
CHANGED
@@ -2,15 +2,15 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: sysadmin 0.
|
5
|
+
# stub: sysadmin 0.2.0 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "sysadmin"
|
9
|
-
s.version = "0.
|
9
|
+
s.version = "0.2.0"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
12
|
s.authors = ["id774"]
|
13
|
-
s.date = "2013-
|
13
|
+
s.date = "2013-11-22"
|
14
14
|
s.description = "The general-purpose library for system administrations"
|
15
15
|
s.email = "idnanashi@gmail.com"
|
16
16
|
s.extra_rdoc_files = [
|
@@ -35,6 +35,7 @@ Gem::Specification.new do |s|
|
|
35
35
|
"lib/sysadmin/file_ext.rb",
|
36
36
|
"lib/sysadmin/time_ext.rb",
|
37
37
|
"lib/sysadmin/util.rb",
|
38
|
+
"lib/sysadmin/version.rb",
|
38
39
|
"script/.gitkeep",
|
39
40
|
"script/build",
|
40
41
|
"spec/lib/sysadmin/array_ext_spec.rb",
|
@@ -60,7 +61,7 @@ Gem::Specification.new do |s|
|
|
60
61
|
s.homepage = "http://github.com/id774/sysadmin"
|
61
62
|
s.licenses = ["GPL"]
|
62
63
|
s.require_paths = ["lib"]
|
63
|
-
s.rubygems_version = "2.1.
|
64
|
+
s.rubygems_version = "2.1.9"
|
64
65
|
s.summary = "Sysadmin"
|
65
66
|
|
66
67
|
if s.respond_to? :specification_version then
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sysadmin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- id774
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-11-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: cucumber
|
@@ -77,6 +77,7 @@ files:
|
|
77
77
|
- lib/sysadmin/file_ext.rb
|
78
78
|
- lib/sysadmin/time_ext.rb
|
79
79
|
- lib/sysadmin/util.rb
|
80
|
+
- lib/sysadmin/version.rb
|
80
81
|
- script/.gitkeep
|
81
82
|
- script/build
|
82
83
|
- spec/lib/sysadmin/array_ext_spec.rb
|
@@ -118,7 +119,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
118
119
|
version: '0'
|
119
120
|
requirements: []
|
120
121
|
rubyforge_project:
|
121
|
-
rubygems_version: 2.1.
|
122
|
+
rubygems_version: 2.1.9
|
122
123
|
signing_key:
|
123
124
|
specification_version: 4
|
124
125
|
summary: Sysadmin
|