sysadmin 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.2
1
+ 0.1.3
data/doc/ChangeLog CHANGED
@@ -1,3 +1,16 @@
1
+ === 0.1.3 / 2012-10-25
2
+
3
+ * Add Class
4
+
5
+ * Sysadmin::Util
6
+
7
+ * Pseudo-Keyword Arguments
8
+
9
+ * Sysadmin::FileExtensn
10
+
11
+ * Uncontaminated loadpath
12
+
13
+
1
14
  === 0.1.2 / 2012-09-27
2
15
 
3
16
  * Add Methods
data/doc/README CHANGED
@@ -39,6 +39,10 @@ Module
39
39
  Class
40
40
  =====
41
41
 
42
+ - Sysadmin::Util
43
+
44
+ General methods.
45
+
42
46
  - Sysadmin::Directory
43
47
 
44
48
  Enumerable Dir class.
@@ -48,6 +52,11 @@ Class
48
52
  Method
49
53
  ======
50
54
 
55
+
56
+ * Sysadmin::Util.create_multi_dimensional_hash
57
+
58
+ Return new Multi Dimensional Hash object.
59
+
51
60
  * File.zread (file)
52
61
 
53
62
  Referred by Sysadmin::FileHandler.
data/doc/README.ja CHANGED
@@ -39,6 +39,10 @@ $ gem install sysadmin
39
39
  クラス
40
40
  ======
41
41
 
42
+ - Sysadmin::Util
43
+
44
+ 汎用的なメソッド
45
+
42
46
  - Sysadmin::Directory
43
47
 
44
48
  Enumerable な Dir クラス
@@ -48,6 +52,10 @@ $ gem install sysadmin
48
52
  メソッド
49
53
  ========
50
54
 
55
+ * Sysadmin::Util.create_multi_dimensional_hash
56
+
57
+ 多次元ハッシュを生成して返す
58
+
51
59
  * File.zread(file)
52
60
 
53
61
  Sysadmin::FileHandler を呼ぶと追加される
data/lib/sysadmin.rb CHANGED
@@ -2,20 +2,15 @@
2
2
  # Name:: Sysadmin
3
3
  # Author:: 774 <http://id774.net>
4
4
  # Created:: Mar 23, 2012
5
- # Updated:: Sep 6, 2012
5
+ # Updated:: Sep 27, 2012
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.2"
11
- USER_DIR = "/."
12
- ROOT_DIR = File.expand_path("..", File.dirname(__FILE__))
13
- $:.unshift ROOT_DIR
14
- $:.unshift ROOT_DIR + '/lib'
15
- $:.unshift ROOT_DIR + '/lib/sysadmin'
16
-
17
- require 'file_ext'
18
- require 'dir_ext'
19
- require 'directory'
20
- require 'time_ext'
10
+ VERSION = "0.1.3"
11
+ require File.dirname(__FILE__) + "/sysadmin/util"
12
+ require File.dirname(__FILE__) + "/sysadmin/file_ext"
13
+ require File.dirname(__FILE__) + "/sysadmin/dir_ext"
14
+ require File.dirname(__FILE__) + "/sysadmin/directory"
15
+ require File.dirname(__FILE__) + "/sysadmin/time_ext"
21
16
  end
@@ -25,30 +25,30 @@ module Sysadmin
25
25
  end
26
26
  end
27
27
 
28
- def File.append_line(file, str)
29
- if File.exist?(file)
30
- f = open(file, 'a')
28
+ def File.append_line(params)
29
+ if File.exist?(params[:file])
30
+ f = open(params[:file], 'a')
31
31
  else
32
- f = open(file, 'w')
32
+ f = open(params[:file], 'w')
33
33
  end
34
- f << str
34
+ f << params[:str]
35
35
  f << "\n"
36
36
  f.close
37
37
  end
38
38
 
39
- def File.new_line(file, str)
40
- f = open(file, 'w')
41
- f << str
39
+ def File.new_line(params)
40
+ f = open(params[:file], 'w')
41
+ f << params[:str]
42
42
  f << "\n"
43
43
  f.close
44
44
  end
45
45
 
46
- def File.replace_line(file, src, out)
47
- open(file, "r+") { |f|
46
+ def File.replace_line(params)
47
+ open(params[:file], "r+") { |f|
48
48
  f.rewind
49
49
  body = f.read
50
- body = body.gsub(src) { |tmp|
51
- out
50
+ body = body.gsub(params[:src]) { |tmp|
51
+ params[:dst]
52
52
  }
53
53
  f.rewind
54
54
  f.puts body
@@ -56,12 +56,12 @@ module Sysadmin
56
56
  }
57
57
  end
58
58
 
59
- def File.remove_line(file, str)
59
+ def File.remove_line(params)
60
60
  out = ""
61
- IO.foreach(file) { |line|
62
- out << line unless line.include?(str)
61
+ IO.foreach(params[:file]) { |line|
62
+ out << line unless line.include?(params[:str])
63
63
  }
64
- open(file, "w") { |f|
64
+ open(params[:file], "w") { |f|
65
65
  f.write out
66
66
  }
67
67
  end
@@ -5,7 +5,7 @@
5
5
  # Copyright:: 774 Copyright (c) 2012
6
6
  # License:: Licensed under the GNU GENERAL PUBLIC LICENSE, Version 3.0.
7
7
 
8
- require "time"
8
+ require 'time'
9
9
 
10
10
  module Sysadmin
11
11
  module TimeExtension
@@ -0,0 +1,16 @@
1
+ # Name:: Sysadmin::Util
2
+ # Author:: 774 <http://id774.net>
3
+ # Created:: Oct 25, 2012
4
+ # Updated:: Jul 25, 2012
5
+ # Copyright:: 774 Copyright (c) 2012
6
+ # License:: Licensed under the GNU GENERAL PUBLIC LICENSE, Version 3.0.
7
+
8
+ module Sysadmin
9
+ class Util
10
+ class << self
11
+ def create_multi_dimensional_hash
12
+ Hash.new{ |h,k| h[k] = Hash.new(&h.default_proc) }
13
+ end
14
+ end
15
+ end
16
+ end
@@ -6,14 +6,14 @@ describe Sysadmin::DirExtension, 'Dir クラス拡張' do
6
6
  context 'で filelist メソッドを呼ぶ場合' do
7
7
  describe 'ディレクトリ名を指定すると' do
8
8
  it "ディレクトリ内のファイル一覧が返却される" do
9
- test_dir = File.expand_path("../../test_dir", File.dirname(__FILE__))
9
+ test_dir = File.expand_path("../../test_dir/a", File.dirname(__FILE__))
10
10
  Dir.filelist(test_dir).should have(2).items
11
11
  end
12
12
  end
13
13
 
14
14
  describe 'ファイル名を指定すると' do
15
15
  it "ファイル名が返却される" do
16
- test_dir = File.expand_path("../../test_dir/file2", File.dirname(__FILE__))
16
+ test_dir = File.expand_path("../../test_dir/a/d.txt", File.dirname(__FILE__))
17
17
  Dir.filelist(test_dir).should have(1).items
18
18
  end
19
19
  end
@@ -21,20 +21,20 @@ describe Sysadmin::DirExtension, 'Dir クラス拡張' do
21
21
  describe 'サブディレクトリを true にしてディレクトリを指定すると' do
22
22
  it "サブディレクトリ内のファイルも返却される" do
23
23
  test_dir = File.expand_path("../../test_dir", File.dirname(__FILE__))
24
- Dir.filelist(test_dir, sub_directory = true).should have(6).items
24
+ Dir.filelist(test_dir, sub_directory = true).should have(9).items
25
25
  end
26
26
  end
27
27
 
28
28
  describe 'サブディレクトリを false にしてディレクトリを指定すると' do
29
29
  it "ディレクトリ内のファイル一覧が返却される (サブディレクトリは見ない)" do
30
- test_dir = File.expand_path("../../test_dir", File.dirname(__FILE__))
30
+ test_dir = File.expand_path("../../test_dir/a", File.dirname(__FILE__))
31
31
  Dir.filelist(test_dir, sub_directory = false).should have(2).items
32
32
  end
33
33
  end
34
34
 
35
35
  describe 'サブディレクトリを true にしてファイル名を指定しても' do
36
36
  it "ファイル名が返却される (サブディレクトリは見ない)" do
37
- test_dir = File.expand_path("../../test_dir/file2", File.dirname(__FILE__))
37
+ test_dir = File.expand_path("../../test_dir/a/d.txt", File.dirname(__FILE__))
38
38
  Dir.filelist(test_dir).should have(1).items
39
39
  end
40
40
  end
@@ -7,49 +7,49 @@ describe Sysadmin::Directory, 'Directory クラス' do
7
7
  describe 'ディレクトリ名を指定すると' do
8
8
  it "ディレクトリ内のファイル一覧が返却される" do
9
9
  test_dir = File.expand_path("../../test_dir", File.dirname(__FILE__))
10
- Sysadmin::Directory.new(test_dir).map{|f|f}.should have(7).items
10
+ Sysadmin::Directory.new(test_dir).map{|f|f}.should have(9).items
11
11
  end
12
12
  end
13
13
 
14
14
  describe 'ディレクトリ名を指定すると' do
15
15
  it "ディレクトリ内のファイル一覧が返却される" do
16
- test_dir = File.expand_path("../../test_dir/dir2", File.dirname(__FILE__))
17
- Sysadmin::Directory.new(test_dir).map{|f|f}.should have(2).items
16
+ test_dir = File.expand_path("../../test_dir/a", File.dirname(__FILE__))
17
+ Sysadmin::Directory.new(test_dir).map{|f|f}.should have(4).items
18
18
  end
19
19
  end
20
20
 
21
21
  describe 'ディレクトリ名を指定すると' do
22
22
  it "ディレクトリ内のファイル一覧が返却される" do
23
- test_dir = File.expand_path("../../test_dir/dir3", File.dirname(__FILE__))
24
- Sysadmin::Directory.new(test_dir).map{|f|f}.should have(1).item
23
+ test_dir = File.expand_path("../../test_dir/a/g", File.dirname(__FILE__))
24
+ Sysadmin::Directory.new(test_dir).map{|f|f}.should have(2).item
25
25
  end
26
26
  end
27
27
 
28
28
  describe 'ディレクトリ名を指定すると' do
29
29
  it "ディレクトリ内のファイル一覧が返却される" do
30
- test_dir = File.expand_path("../../test_dir/dir6", File.dirname(__FILE__))
31
- Sysadmin::Directory.new(test_dir).map{|f|f}.should have(1).item
30
+ test_dir = File.expand_path("../../test_dir/b", File.dirname(__FILE__))
31
+ Sysadmin::Directory.new(test_dir).map{|f|f}.should have(2).item
32
32
  end
33
33
  end
34
34
 
35
35
  describe 'ディレクトリ名を指定し grep すると' do
36
36
  it "ディレクトリ内の grep に適合したファイル一覧が返却される" do
37
37
  test_dir = File.expand_path("../../test_dir", File.dirname(__FILE__))
38
- Sysadmin::Directory.new(test_dir).grep(/\.file7$/).should have(1).item
38
+ Sysadmin::Directory.new(test_dir).grep(/\.txt/).should have(9).item
39
39
  end
40
40
  end
41
41
 
42
42
  describe 'ディレクトリ名を指定し grep すると' do
43
43
  it "ディレクトリ内の grep に適合したファイル一覧が返却される" do
44
44
  test_dir = File.expand_path("../../test_dir", File.dirname(__FILE__))
45
- Sysadmin::Directory.new(test_dir).grep(/\.file/).should have(3).items
45
+ Sysadmin::Directory.new(test_dir).grep(/d\.txt/).should have(1).items
46
46
  end
47
47
  end
48
48
 
49
49
  describe 'ディレクトリ名を指定し grep して take すると' do
50
50
  it "ディレクトリ内の grep に適合し take した数だけファイル一覧が返却される" do
51
51
  test_dir = File.expand_path("../../test_dir", File.dirname(__FILE__))
52
- Sysadmin::Directory.new(test_dir).grep(/\.file/).take(2).should have(2).items
52
+ Sysadmin::Directory.new(test_dir).grep(/\.txt/).take(3).should have(3).items
53
53
  end
54
54
  end
55
55
 
@@ -10,7 +10,7 @@ describe Sysadmin::FileExtension, 'File クラス拡張' do
10
10
  try = "uncompressed"
11
11
  expect = "uncompressed\n"
12
12
  @uncompressed = Tempfile::new("test.txt")
13
- File.append_line(@uncompressed.path, try)
13
+ File.append_line(:file => @uncompressed.path, :str => try)
14
14
 
15
15
  File.zread(@uncompressed.path).should == expect
16
16
  @uncompressed.close
@@ -38,7 +38,7 @@ describe Sysadmin::FileExtension, 'File クラス拡張' do
38
38
  expect = "hoge\n"
39
39
 
40
40
  3.times do
41
- File.append_line(@testfile.path, src)
41
+ File.append_line(:file => @testfile.path, :str => src)
42
42
  end
43
43
 
44
44
  open(@testfile.path) { |file|
@@ -58,9 +58,9 @@ describe Sysadmin::FileExtension, 'File クラス拡張' do
58
58
  expect = "fuga\n"
59
59
 
60
60
  3.times do
61
- File.append_line(@testfile.path, src)
61
+ File.append_line(:file => @testfile.path, :str => src)
62
62
  end
63
- File.replace_line(@testfile.path, src, try)
63
+ File.replace_line(:file => @testfile.path, :src => src, :dst => try)
64
64
 
65
65
  open(@testfile.path) { |file|
66
66
  while line = file.gets
@@ -80,13 +80,13 @@ describe Sysadmin::FileExtension, 'File クラス拡張' do
80
80
  expect = "fuga\n"
81
81
 
82
82
  3.times do
83
- File.append_line(@testfile.path, src)
83
+ File.append_line(:file => @testfile.path, :str => src)
84
84
  end
85
- File.replace_line(@testfile.path, src, replace)
85
+ File.replace_line(:file => @testfile.path, :src => src, :dst => replace)
86
86
  2.times do
87
- File.append_line(@testfile.path, src)
87
+ File.append_line(:file => @testfile.path, :str => src)
88
88
  end
89
- File.remove_line(@testfile.path, erase)
89
+ File.remove_line(:file => @testfile.path, :str => erase)
90
90
 
91
91
  open(@testfile.path) { |file|
92
92
  while line = file.gets
@@ -104,8 +104,8 @@ describe Sysadmin::FileExtension, 'File クラス拡張' do
104
104
  second = 'second'
105
105
  expect = "second\n"
106
106
 
107
- File.new_line(@testfile.path, init)
108
- File.new_line(@testfile.path, second)
107
+ File.new_line(:file => @testfile.path, :str => init)
108
+ File.new_line(:file => @testfile.path, :str => second)
109
109
 
110
110
  open(@testfile.path) { |file|
111
111
  while line = file.gets
@@ -0,0 +1,17 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require File.dirname(__FILE__) + '/../../spec_helper'
4
+
5
+ describe Sysadmin::Util do
6
+ context 'で multi_dimensional_hash メソッドを呼ぶ場合' do
7
+ describe '引数を付けずに呼ぶと' do
8
+ it "多次元ハッシュが返る" do
9
+ h = Sysadmin::Util.create_multi_dimensional_hash
10
+ h["a"]["b"]["c"]["d"] = 10
11
+ h["a"]["b"]["c"]["e"] = 15
12
+ h["a"]["b"]["c"]["d"].should == 10
13
+ h["a"]["b"]["c"]["e"].should == 15
14
+ end
15
+ end
16
+ end
17
+ end
@@ -5,7 +5,7 @@ require File.dirname(__FILE__) + '/../spec_helper'
5
5
  describe Sysadmin, 'sysadmin' do
6
6
  context 'のバージョンを参照した場合' do
7
7
  it "バージョンが正しく表示される" do
8
- expect = '0.1.2'
8
+ expect = '0.1.3'
9
9
  Sysadmin.const_get(:VERSION).should be_true
10
10
  Sysadmin.const_get(:VERSION).should == expect
11
11
  end
@@ -0,0 +1 @@
1
+ d
@@ -0,0 +1 @@
1
+ h
@@ -0,0 +1 @@
1
+ n
@@ -0,0 +1 @@
1
+ o
@@ -0,0 +1 @@
1
+ e
@@ -0,0 +1 @@
1
+ j
@@ -0,0 +1 @@
1
+ f
@@ -0,0 +1 @@
1
+ l
@@ -0,0 +1 @@
1
+ p
data/sysadmin.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "sysadmin"
8
- s.version = "0.1.2"
8
+ s.version = "0.1.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["id774"]
12
- s.date = "2012-09-27"
12
+ s.date = "2012-10-25"
13
13
  s.description = "System Administration General Library"
14
14
  s.email = "idnanashi@gmail.com"
15
15
  s.extra_rdoc_files = [
@@ -32,21 +32,25 @@ Gem::Specification.new do |s|
32
32
  "lib/sysadmin/directory.rb",
33
33
  "lib/sysadmin/file_ext.rb",
34
34
  "lib/sysadmin/time_ext.rb",
35
+ "lib/sysadmin/util.rb",
35
36
  "script/.gitkeep",
36
37
  "script/build",
37
38
  "spec/lib/sysadmin/dir_ext_spec.rb",
38
39
  "spec/lib/sysadmin/directory_spec.rb",
39
40
  "spec/lib/sysadmin/file_ext_spec.rb",
40
41
  "spec/lib/sysadmin/time_ext_spec.rb",
42
+ "spec/lib/sysadmin/util_spec.rb",
41
43
  "spec/lib/sysadmin_spec.rb",
42
44
  "spec/spec_helper.rb",
43
- "spec/test_dir/.dir1/.file6",
44
- "spec/test_dir/.file1",
45
- "spec/test_dir/dir2/dir4/file4",
46
- "spec/test_dir/dir2/file3",
47
- "spec/test_dir/dir3/file5",
48
- "spec/test_dir/dir6/dir7/.file7",
49
- "spec/test_dir/file2",
45
+ "spec/test_dir/a/d.txt",
46
+ "spec/test_dir/a/g/h.txt",
47
+ "spec/test_dir/a/g/m/n.txt",
48
+ "spec/test_dir/a/o.txt",
49
+ "spec/test_dir/b/e.txt",
50
+ "spec/test_dir/b/i/j.txt",
51
+ "spec/test_dir/c/f.txt",
52
+ "spec/test_dir/c/k/l.txt",
53
+ "spec/test_dir/p.txt",
50
54
  "sysadmin.gemspec",
51
55
  "vendor/.gitkeep"
52
56
  ]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sysadmin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-09-27 00:00:00.000000000 Z
12
+ date: 2012-10-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: cucumber
@@ -82,21 +82,25 @@ files:
82
82
  - lib/sysadmin/directory.rb
83
83
  - lib/sysadmin/file_ext.rb
84
84
  - lib/sysadmin/time_ext.rb
85
+ - lib/sysadmin/util.rb
85
86
  - script/.gitkeep
86
87
  - script/build
87
88
  - spec/lib/sysadmin/dir_ext_spec.rb
88
89
  - spec/lib/sysadmin/directory_spec.rb
89
90
  - spec/lib/sysadmin/file_ext_spec.rb
90
91
  - spec/lib/sysadmin/time_ext_spec.rb
92
+ - spec/lib/sysadmin/util_spec.rb
91
93
  - spec/lib/sysadmin_spec.rb
92
94
  - spec/spec_helper.rb
93
- - spec/test_dir/.dir1/.file6
94
- - spec/test_dir/.file1
95
- - spec/test_dir/dir2/dir4/file4
96
- - spec/test_dir/dir2/file3
97
- - spec/test_dir/dir3/file5
98
- - spec/test_dir/dir6/dir7/.file7
99
- - spec/test_dir/file2
95
+ - spec/test_dir/a/d.txt
96
+ - spec/test_dir/a/g/h.txt
97
+ - spec/test_dir/a/g/m/n.txt
98
+ - spec/test_dir/a/o.txt
99
+ - spec/test_dir/b/e.txt
100
+ - spec/test_dir/b/i/j.txt
101
+ - spec/test_dir/c/f.txt
102
+ - spec/test_dir/c/k/l.txt
103
+ - spec/test_dir/p.txt
100
104
  - sysadmin.gemspec
101
105
  - vendor/.gitkeep
102
106
  homepage: http://github.com/id774/sysadmin
File without changes
data/spec/test_dir/.file1 DELETED
File without changes
File without changes
File without changes
File without changes
File without changes
data/spec/test_dir/file2 DELETED
File without changes