algerb 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,7 @@
1
+ == 0.0.3, released 2012-01-02
2
+
3
+ * FIX: some files were lost from generated autoloader script.
4
+
1
5
  == 0.0.2, released 2012-01-01
2
6
 
3
7
  * FIX: algerb command installed with RubyGems not worked:
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.2
1
+ 0.0.3
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "algerb"
8
- s.version = "0.0.2"
8
+ s.version = "0.0.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Yuya Takeyama"]
@@ -1,5 +1,6 @@
1
1
  class Algerb::Files
2
2
  include ::Enumerable
3
+ include Algerb::Util
3
4
 
4
5
  attr_reader :name, :files
5
6
 
@@ -8,15 +9,27 @@ class Algerb::Files
8
9
  @files = files
9
10
  end
10
11
 
12
+ def self.root(files = {})
13
+ new(nil, files)
14
+ end
15
+
11
16
  def add(file)
12
- if @files.has_key?(file.name)
13
- file.files.each do |name, _file|
14
- @files[file.name].files[name] = _file
17
+ @files[file.name] = file unless @files.has_key?(file.name)
18
+ self
19
+ end
20
+
21
+ def find_by_path(path)
22
+ next_path, rest = split_path_as_head_and_tail(path)
23
+ if files.has_key?(next_path)
24
+ found = files[next_path]
25
+ if rest.nil?
26
+ found
27
+ elsif found.is_a?(Algerb::Files)
28
+ found.find_by_path(rest)
29
+ else
30
+ found
15
31
  end
16
- else
17
- @files[file.name] = file
18
32
  end
19
- self
20
33
  end
21
34
 
22
35
  def ==(another)
@@ -1,4 +1,6 @@
1
1
  class Algerb::FilesBuilder
2
+ include Algerb::Util
3
+
2
4
  attr_reader :files
3
5
 
4
6
  FILE_PATTERN = %r{^([a-z0-9\_\.])/?}
@@ -8,13 +10,22 @@ class Algerb::FilesBuilder
8
10
  end
9
11
 
10
12
  def add(path)
11
- paths = path.split('/').reverse
12
- file = Algerb::File.new(paths.slice!(0, 1)[0])
13
- files = paths.inject(file) do |file, path|
14
- files = Algerb::Files.new(path).add(file)
15
- files
13
+ dir, file = split_dir_and_file(path)
14
+ if dir
15
+ mkdir_p(dir)
16
+ files.find_by_path(dir).add(Algerb::File.new(file))
17
+ else
18
+ files.add(Algerb::File.new(file))
16
19
  end
17
- @files.add files
18
20
  self
19
21
  end
22
+
23
+ def mkdir_p(path)
24
+ target = files
25
+ while path
26
+ dir, path = split_path_as_head_and_tail(path)
27
+ target.add(Algerb::Files.new(dir))
28
+ target = target.find_by_path(dir)
29
+ end
30
+ end
20
31
  end
@@ -14,4 +14,12 @@ module Algerb::Util
14
14
  def remove_ext(path)
15
15
  path.sub(/\.rb$/, '')
16
16
  end
17
+
18
+ def split_dir_and_file(path)
19
+ path.scan(%r{^(?:(.*)/)?([^/]+)$})[0]
20
+ end
21
+
22
+ def split_path_as_head_and_tail(path)
23
+ path.split('/', 2)
24
+ end
17
25
  end
@@ -12,12 +12,22 @@ describe Algerb::FilesBuilder do
12
12
 
13
13
  context 'when 1 file ("foo.rb") is added' do
14
14
  before { builder.add('foo.rb') }
15
- it { should == Algerb::Files.new.add(Algerb::File.new('foo.rb'))}
15
+ it {
16
+ should == Algerb::Files.root({
17
+ 'foo.rb' => Algerb::File.new('foo.rb'),
18
+ })
19
+ }
16
20
  end
17
21
 
18
22
  context 'when 1 file ("foo/bar.rb") is added' do
19
23
  before { builder.add('foo/bar.rb') }
20
- it { should == Algerb::Files.new.add(Algerb::Files.new('foo').add(Algerb::File.new('bar.rb')))}
24
+ it {
25
+ should == Algerb::Files.root(
26
+ 'foo' => Algerb::Files.new('foo', {
27
+ 'bar.rb' => Algerb::File.new('bar.rb'),
28
+ })
29
+ )
30
+ }
21
31
  end
22
32
 
23
33
  context 'when 2 files ("foo/bar.rb", "foo/baz.rb") are added' do
@@ -25,7 +35,96 @@ describe Algerb::FilesBuilder do
25
35
  builder.add('foo/bar.rb')
26
36
  builder.add('foo/baz.rb')
27
37
  end
28
- it { should == Algerb::Files.new.add(Algerb::Files.new('foo').add(Algerb::File.new('bar.rb')).add(Algerb::File.new('baz.rb'))) }
38
+ it {
39
+ should == Algerb::Files.root(
40
+ 'foo' => Algerb::Files.new('foo', {
41
+ 'bar.rb' => Algerb::File.new('bar.rb'),
42
+ 'baz.rb' => Algerb::File.new('baz.rb'),
43
+ })
44
+ )
45
+ }
46
+ end
47
+
48
+ context 'when a files is added to nested directory' do
49
+ before do
50
+ builder.add('foo/bar/baz.rb')
51
+ builder.add('foo/bar/foo_bar.rb')
52
+ end
53
+ it {
54
+ should == Algerb::Files.root(
55
+ 'foo' => Algerb::Files.new('foo',
56
+ 'bar' => Algerb::Files.new('bar', {
57
+ 'baz.rb' => Algerb::File.new('baz.rb'),
58
+ 'foo_bar.rb' => Algerb::File.new('foo_bar.rb'),
59
+ })
60
+ )
61
+ )
62
+ }
63
+ end
64
+ end
65
+
66
+ describe '#mkdir_p' do
67
+ subject { builder.files }
68
+
69
+ shared_examples_for 'create directory correctly' do
70
+ it { should == expected }
71
+ end
72
+
73
+ context 'no directories are conflicted' do
74
+ before { builder.mkdir_p(path) }
75
+
76
+ context 'foo' do
77
+ let(:path) { 'foo' }
78
+ let(:expected) do
79
+ Algerb::Files.root(
80
+ 'foo' => Algerb::Files.new('foo')
81
+ )
82
+ end
83
+ it_should_behave_like 'create directory correctly'
84
+ end
85
+
86
+ context 'foo/bar' do
87
+ let(:path) { 'foo/bar' }
88
+ let(:expected) do
89
+ Algerb::Files.root(
90
+ 'foo' => Algerb::Files.new('foo',
91
+ 'bar' => Algerb::Files.new('bar')
92
+ )
93
+ )
94
+ end
95
+ it_should_behave_like 'create directory correctly'
96
+ end
97
+
98
+ context 'foo/bar/baz' do
99
+ let(:path) { 'foo/bar/baz' }
100
+ let(:expected) do
101
+ Algerb::Files.root(
102
+ 'foo' => Algerb::Files.new('foo',
103
+ 'bar' => Algerb::Files.new('bar',
104
+ 'baz' => Algerb::Files.new('baz')
105
+ )
106
+ )
107
+ )
108
+ end
109
+ it_should_behave_like 'create directory correctly'
110
+ end
111
+ end
112
+
113
+ context 'directories are conflicted' do
114
+ before do
115
+ builder.add('foo/bar/baz.rb')
116
+ builder.mkdir_p('foo/bar')
117
+ end
118
+
119
+ it {
120
+ should == Algerb::Files.root(
121
+ 'foo' => Algerb::Files.new('foo',
122
+ 'bar' => Algerb::Files.new('bar',
123
+ 'baz.rb' => Algerb::File.new('baz.rb')
124
+ )
125
+ )
126
+ )
127
+ }
29
128
  end
30
129
  end
31
130
  end
@@ -48,4 +48,43 @@ describe Algerb::Files do
48
48
  it { should == {'foo' => dir1, 'bar' => dir2} }
49
49
  end
50
50
  end
51
+
52
+ describe '#find_by_path' do
53
+ context 'when no files are matched' do
54
+ subject { root.find_by_path('foo.rb') }
55
+ it { should be_nil }
56
+ end
57
+
58
+ context 'when a file is matched in the root' do
59
+ before { root.add(Algerb::File.new('foo.rb')) }
60
+ subject { root.find_by_path('foo.rb') }
61
+ it { should == Algerb::File.new('foo.rb') }
62
+ end
63
+
64
+ context 'when a file is matched in a directory' do
65
+ before do
66
+ root.add(Algerb::Files.new('foo',
67
+ 'bar.rb' => Algerb::File.new('bar.rb')
68
+ ))
69
+ end
70
+ subject { root.find_by_path('foo/bar.rb') }
71
+ it { should == Algerb::File.new('bar.rb') }
72
+ end
73
+
74
+ context 'when a directory is matched in the root' do
75
+ before { root.add(Algerb::Files.new('foo')) }
76
+ subject { root.find_by_path('foo') }
77
+ it { should == Algerb::Files.new('foo') }
78
+ end
79
+
80
+ context 'when a directory is matched in a directory' do
81
+ before do
82
+ root.add(Algerb::Files.new('foo',
83
+ 'bar' => Algerb::Files.new('bar')
84
+ ))
85
+ end
86
+ subject { root.find_by_path('foo/bar') }
87
+ it { should == Algerb::Files.new('bar') }
88
+ end
89
+ end
51
90
  end
@@ -75,4 +75,50 @@ describe Algerb::Util do
75
75
  it { should == 'foo/bar' }
76
76
  end
77
77
  end
78
+
79
+ describe '#split_dir_and_file' do
80
+ subject { split_dir_and_file(path) }
81
+
82
+ context 'foo.rb' do
83
+ let(:path) { 'foo.rb' }
84
+ it { should == [nil, 'foo.rb'] }
85
+ end
86
+
87
+ context 'foo/bar.rb' do
88
+ let(:path) { 'foo/bar.rb' }
89
+ it { should == ['foo', 'bar.rb'] }
90
+ end
91
+
92
+ context 'foo/bar/baz.rb' do
93
+ let(:path) { 'foo/bar/baz.rb' }
94
+ it { should == ['foo/bar', 'baz.rb'] }
95
+ end
96
+ end
97
+
98
+ describe '#split_path_as_head_and_tail' do
99
+ subject { split_path_as_head_and_tail(path) }
100
+
101
+ shared_examples_for 'head and tail are correct' do
102
+ it { should == [head, tail] }
103
+ end
104
+
105
+ context 'foo.rb' do
106
+ let(:path) { 'foo.rb' }
107
+ it { should == ['foo.rb'] }
108
+ end
109
+
110
+ context 'foo/bar.rb' do
111
+ let(:path) { 'foo/bar.rb' }
112
+ let(:head) { 'foo' }
113
+ let(:tail) { 'bar.rb' }
114
+ it_should_behave_like 'head and tail are correct'
115
+ end
116
+
117
+ context 'foo/bar/baz.rb' do
118
+ let(:path) { 'foo/bar/baz.rb' }
119
+ let(:head) { 'foo' }
120
+ let(:tail) { 'bar/baz.rb' }
121
+ it_should_behave_like 'head and tail are correct'
122
+ end
123
+ end
78
124
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: algerb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-01-01 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: thor
16
- requirement: &27852240 !ruby/object:Gem::Requirement
16
+ requirement: &17515760 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *27852240
24
+ version_requirements: *17515760
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rake
27
- requirement: &27851540 !ruby/object:Gem::Requirement
27
+ requirement: &17515060 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *27851540
35
+ version_requirements: *17515060
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: cucumber
38
- requirement: &27850800 !ruby/object:Gem::Requirement
38
+ requirement: &17514140 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *27850800
46
+ version_requirements: *17514140
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: aruba
49
- requirement: &27850100 !ruby/object:Gem::Requirement
49
+ requirement: &17513560 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *27850100
57
+ version_requirements: *17513560
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: guard-cucumber
60
- requirement: &27806440 !ruby/object:Gem::Requirement
60
+ requirement: &17461800 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *27806440
68
+ version_requirements: *17461800
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rspec
71
- requirement: &27805860 !ruby/object:Gem::Requirement
71
+ requirement: &17461280 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *27805860
79
+ version_requirements: *17461280
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: guard-rspec
82
- requirement: &27805200 !ruby/object:Gem::Requirement
82
+ requirement: &17460620 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: '0'
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *27805200
90
+ version_requirements: *17460620
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: jeweler
93
- requirement: &27804600 !ruby/object:Gem::Requirement
93
+ requirement: &17460020 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ~>
@@ -98,10 +98,10 @@ dependencies:
98
98
  version: 1.6.4
99
99
  type: :development
100
100
  prerelease: false
101
- version_requirements: *27804600
101
+ version_requirements: *17460020
102
102
  - !ruby/object:Gem::Dependency
103
103
  name: rcov
104
- requirement: &27804040 !ruby/object:Gem::Requirement
104
+ requirement: &17459400 !ruby/object:Gem::Requirement
105
105
  none: false
106
106
  requirements:
107
107
  - - ! '>='
@@ -109,7 +109,7 @@ dependencies:
109
109
  version: '0'
110
110
  type: :development
111
111
  prerelease: false
112
- version_requirements: *27804040
112
+ version_requirements: *17459400
113
113
  description: Generates autoloader script for your Ruby library.
114
114
  email: sign.of.the.wolf.pentagram@gmail.com
115
115
  executables:
@@ -162,7 +162,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
162
162
  version: '0'
163
163
  segments:
164
164
  - 0
165
- hash: 4221084203019020392
165
+ hash: -478649244556644149
166
166
  required_rubygems_version: !ruby/object:Gem::Requirement
167
167
  none: false
168
168
  requirements: