sysadmin 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
data/doc/ChangeLog CHANGED
@@ -1,3 +1,10 @@
1
+ === 0.1.1 / 2012-09-06
2
+
3
+ * Add Class
4
+
5
+ * Sysadmin::Directory
6
+
7
+
1
8
  === 0.1.0 / 2012-07-17
2
9
 
3
10
  * Re-construction
data/doc/README CHANGED
@@ -31,6 +31,15 @@ Module
31
31
  Extend the Dir class.
32
32
 
33
33
 
34
+ =====
35
+ Class
36
+ =====
37
+
38
+ - Sysadmin::Directory
39
+
40
+ Enumerable Dir class.
41
+
42
+
34
43
  ======
35
44
  Method
36
45
  ======
data/doc/README.ja CHANGED
@@ -31,6 +31,15 @@ $ gem install sysadmin
31
31
  Dir クラスを拡張する
32
32
 
33
33
 
34
+ ======
35
+ クラス
36
+ ======
37
+
38
+ - Sysadmin::Directory
39
+
40
+ Enumerable な Dir クラス
41
+
42
+
34
43
  ========
35
44
  メソッド
36
45
  ========
data/lib/sysadmin.rb CHANGED
@@ -2,12 +2,12 @@
2
2
  # Name:: Sysadmin
3
3
  # Author:: 774 <http://id774.net>
4
4
  # Created:: Mar 23, 2012
5
- # Updated:: Jul 17, 2012
5
+ # Updated:: Sep 6, 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.0"
10
+ VERSION = "0.1.1"
11
11
  USER_DIR = "/."
12
12
  ROOT_DIR = File.expand_path("..", File.dirname(__FILE__))
13
13
  $:.unshift ROOT_DIR
@@ -16,4 +16,5 @@ module Sysadmin
16
16
 
17
17
  require 'file_ext'
18
18
  require 'dir_ext'
19
+ require 'directory'
19
20
  end
@@ -0,0 +1,30 @@
1
+ # Name:: Sysadmin::Directory
2
+ # Forked from https://gist.github.com/3296137
3
+
4
+ module Sysadmin
5
+ class Directory
6
+ include Enumerable
7
+
8
+ def initialize(dirname)
9
+ @dirname = dirname
10
+ @files = Dir.open(dirname) {|dir|
11
+ dir.reject {|name| name == "." || name == ".." }
12
+ }
13
+ end
14
+
15
+ def each(&block)
16
+ if block_given?
17
+ @files.each do |name|
18
+ path = File.join(@dirname, name)
19
+ if File.directory?(path)
20
+ Directory.new(path).each(&block)
21
+ else
22
+ yield path
23
+ end
24
+ end
25
+ else
26
+ Enumerator.new(self, :each)
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,57 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require File.dirname(__FILE__) + '/../../spec_helper'
4
+
5
+ describe Sysadmin::Directory, 'Directory クラス' do
6
+ context 'で map メソッドを呼ぶ場合' do
7
+ describe 'ディレクトリ名を指定すると' do
8
+ it "ディレクトリ内のファイル一覧が返却される" do
9
+ test_dir = File.expand_path("../../test_dir", File.dirname(__FILE__))
10
+ Sysadmin::Directory.new(test_dir).map{|f|f}.should have(7).items
11
+ end
12
+ end
13
+
14
+ describe 'ディレクトリ名を指定すると' do
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
18
+ end
19
+ end
20
+
21
+ describe 'ディレクトリ名を指定すると' do
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
25
+ end
26
+ end
27
+
28
+ describe 'ディレクトリ名を指定すると' do
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
32
+ end
33
+ end
34
+
35
+ describe 'ディレクトリ名を指定し grep すると' do
36
+ it "ディレクトリ内の grep に適合したファイル一覧が返却される" do
37
+ test_dir = File.expand_path("../../test_dir", File.dirname(__FILE__))
38
+ Sysadmin::Directory.new(test_dir).grep(/\.file7$/).should have(1).item
39
+ end
40
+ end
41
+
42
+ describe 'ディレクトリ名を指定し grep すると' do
43
+ it "ディレクトリ内の grep に適合したファイル一覧が返却される" do
44
+ test_dir = File.expand_path("../../test_dir", File.dirname(__FILE__))
45
+ Sysadmin::Directory.new(test_dir).grep(/\.file/).should have(3).items
46
+ end
47
+ end
48
+
49
+ describe 'ディレクトリ名を指定し grep して take すると' do
50
+ it "ディレクトリ内の grep に適合し take した数だけファイル一覧が返却される" do
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
53
+ end
54
+ end
55
+
56
+ end
57
+ 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.0'
8
+ expect = '0.1.1'
9
9
  Sysadmin.const_get(:VERSION).should be_true
10
10
  Sysadmin.const_get(:VERSION).should == expect
11
11
  end
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.0"
8
+ s.version = "0.1.1"
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-07-17"
12
+ s.date = "2012-09-06"
13
13
  s.description = "System Administration General Library"
14
14
  s.email = "idnanashi@gmail.com"
15
15
  s.extra_rdoc_files = [
@@ -29,10 +29,12 @@ Gem::Specification.new do |s|
29
29
  "doc/README.ja",
30
30
  "lib/sysadmin.rb",
31
31
  "lib/sysadmin/dir_ext.rb",
32
+ "lib/sysadmin/directory.rb",
32
33
  "lib/sysadmin/file_ext.rb",
33
34
  "script/.gitkeep",
34
35
  "script/build",
35
36
  "spec/lib/sysadmin/dir_ext_spec.rb",
37
+ "spec/lib/sysadmin/directory_spec.rb",
36
38
  "spec/lib/sysadmin/file_ext_spec.rb",
37
39
  "spec/lib/sysadmin_spec.rb",
38
40
  "spec/spec_helper.rb",
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.0
4
+ version: 0.1.1
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-07-17 00:00:00.000000000 Z
12
+ date: 2012-09-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: cucumber
@@ -79,10 +79,12 @@ files:
79
79
  - doc/README.ja
80
80
  - lib/sysadmin.rb
81
81
  - lib/sysadmin/dir_ext.rb
82
+ - lib/sysadmin/directory.rb
82
83
  - lib/sysadmin/file_ext.rb
83
84
  - script/.gitkeep
84
85
  - script/build
85
86
  - spec/lib/sysadmin/dir_ext_spec.rb
87
+ - spec/lib/sysadmin/directory_spec.rb
86
88
  - spec/lib/sysadmin/file_ext_spec.rb
87
89
  - spec/lib/sysadmin_spec.rb
88
90
  - spec/spec_helper.rb