and_feathers 1.0.0.pre → 1.0.0.pre.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c8677ebc7f56d9f906f50385f52023ac81ba58bd
4
- data.tar.gz: c480d1890de2bc3d78f2d7da5daf317300113be0
3
+ metadata.gz: 0d9656435e6178a04aab438ddf7e730aa2d577b8
4
+ data.tar.gz: 49ac9dc20c608f43b2c90cf9a28bb462718c0439
5
5
  SHA512:
6
- metadata.gz: f9fb0a23273a125b5a519d11c3f8a5a00cde68e7a33afbf0c5159c8d2b10954b159c42fc9de5212f5a8d4ff97d0a1fec8d463910f1960f9fd29503465b6614b3
7
- data.tar.gz: 9e541a6708157de758811e543cbc6bef2cdd25dea3dad6aac1c0243f0f288b62834eb702d1672633ef7788a53718826da671c09753080422a9dc803675fd4a43
6
+ metadata.gz: b30cb6a4608a3608ae83cba864e65d1d050067aa22436c6a6e25cf4bf564e60e0aa066c25174f76673223fc702eb9439e856b20b4d3699792c22866f130d8598
7
+ data.tar.gz: d62bd5885dfd95b601cdd37a8b5e23ad20e7cc6462a4991869638fd9d410b9b8df2fdb2f5d1966baf957a184e5e704c897ece207013d8e8d398fd0da31148185
data/and_feathers.gemspec CHANGED
@@ -14,8 +14,7 @@ Gem::Specification.new do |spec|
14
14
  spec.license = "MIT"
15
15
 
16
16
  spec.files = `git ls-files`.split($/)
17
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
17
+ spec.test_files = spec.files.grep(%r{^spec/})
19
18
  spec.require_paths = ["lib"]
20
19
 
21
20
  spec.add_development_dependency "bundler", "~> 1.3"
@@ -9,7 +9,7 @@ module AndFeathers
9
9
  include Enumerable
10
10
 
11
11
  attr_reader :name, :mode
12
- attr_writer :parent
12
+ attr_accessor :parent
13
13
 
14
14
  #
15
15
  # @!attribute [r] name
@@ -36,6 +36,28 @@ module AndFeathers
36
36
  @directories = {}
37
37
  end
38
38
 
39
+ #
40
+ # Reset +parent+ and clone +files+ and +directories+ when calling +dup+ or
41
+ # +clone+ on a +Directory+
42
+ #
43
+ # @param source [Directory]
44
+ #
45
+ def initialize_copy(source)
46
+ super
47
+
48
+ @files = {}
49
+ @directories = {}
50
+ @parent = nil
51
+
52
+ source.directories.map(&:dup).each do |new_directory|
53
+ add_directory(new_directory)
54
+ end
55
+
56
+ source.files.map(&:dup).each do |new_file|
57
+ add_file(new_file)
58
+ end
59
+ end
60
+
39
61
  #
40
62
  # This +Directory+'s path
41
63
  #
@@ -80,7 +102,7 @@ module AndFeathers
80
102
  raise ArgumentError, "#{other} is not a Directory"
81
103
  end
82
104
 
83
- self.dup.tap do |directory|
105
+ dup.tap do |directory|
84
106
  other.files.each do |file|
85
107
  directory.add_file(file.dup)
86
108
  end
@@ -91,7 +113,7 @@ module AndFeathers
91
113
  if existing_directory.nil?
92
114
  directory.add_directory(new_directory.dup)
93
115
  else
94
- directory.add_directory(new_directory.dup | existing_directory.dup)
116
+ directory.add_directory(new_directory | existing_directory)
95
117
  end
96
118
  end
97
119
  end
@@ -4,7 +4,7 @@ module AndFeathers
4
4
  #
5
5
  class File
6
6
  attr_reader :name, :mode, :content
7
- attr_writer :parent
7
+ attr_accessor :parent
8
8
 
9
9
  #
10
10
  # @!attribute [r] name
@@ -34,6 +34,17 @@ module AndFeathers
34
34
  @parent = nil
35
35
  end
36
36
 
37
+ #
38
+ # Reset +parent+ when calling +dup+ or +clone+ on a +File+
39
+ #
40
+ # @param source [File]
41
+ #
42
+ def initialize_copy(source)
43
+ super
44
+
45
+ @parent = nil
46
+ end
47
+
37
48
  #
38
49
  # This +File+'s path
39
50
  #
@@ -4,5 +4,5 @@ module AndFeathers
4
4
  # introduces the change to a configurable output format, which breaks the
5
5
  # interface of the initial release.
6
6
  #
7
- VERSION = "1.0.0.pre"
7
+ VERSION = "1.0.0.pre.1"
8
8
  end
@@ -3,66 +3,136 @@ require 'and_feathers/directory'
3
3
 
4
4
  module AndFeathers
5
5
  describe Directory do
6
- it 'can be unioned with another directory' do
7
- one = Directory.new
8
- two = Directory.new
9
- one.dir('a') do |a|
10
- a.dir('b') do |b|
11
- b.file('c')
12
- end
13
- a.dir('c')
6
+ describe 'dupping/cloning' do
7
+ it 'does not preserve the parent relationship' do
8
+ one = Directory.new.tap { |d| d.file('a/b/c') }
9
+
10
+ b = one.find { |e| e.name == 'b' }
11
+
12
+ expect(b.dup.parent).to be_nil
14
13
  end
14
+ end
15
15
 
16
- two.dir('a') do |a|
17
- a.dir('b') do |b|
18
- b.file('d')
16
+ describe '#|' do
17
+ it 'unions the contents of two directories' do
18
+ one = Directory.new
19
+ one.dir('a') do |a|
20
+ a.file('b/c')
21
+ a.dir('c')
19
22
  end
23
+
24
+ two = Directory.new
25
+ two.file('a/b/d')
26
+
27
+ three = one | two
28
+
29
+ expect(three.to_a.map(&:path)).
30
+ to eql(['./a', './a/b', './a/b/c', './a/b/d', './a/c'])
31
+ end
32
+
33
+ it 'does not mutate the left-hand side files' do
34
+ one = Directory.new.tap { |o| o.file('a/b') }
35
+ two = Directory.new.tap { |t| t.file('a/c') ; t.file('d/e') }
36
+
37
+ one_a = one.to_a.find { |e| e.name == 'a' }
38
+
39
+ expect do
40
+ one | two
41
+ end.to_not change(one_a, :files)
20
42
  end
21
43
 
22
- three = one | two
44
+ it 'does not mutate the right-hand side files' do
45
+ one = Directory.new.tap { |o| o.file('a/b') }
46
+ two = Directory.new.tap { |t| t.file('a/c') ; t.file('d/e') }
47
+
48
+ two_a = one.to_a.find { |e| e.name == 'a' }
49
+
50
+ expect do
51
+ one | two
52
+ end.to_not change(two_a, :files)
53
+ end
23
54
 
24
- expect(three.to_a.map(&:path)).
25
- to eql(['./a', './a/b', './a/b/c', './a/b/d', './a/c'])
55
+ it 'does not mutate the left-hand side directories' do
56
+ one = Directory.new.tap { |o| o.file('a/b') }
57
+ two = Directory.new.tap { |t| t.file('a/c') ; t.file('d/e') }
58
+
59
+ expect do
60
+ one | two
61
+ end.to_not change(one, :directories)
62
+ end
63
+
64
+ it 'does not mutate the right-hand side directories' do
65
+ one = Directory.new.tap { |o| o.file('a/b') }
66
+ two = Directory.new.tap { |t| t.file('a/c') ; t.file('d/e') }
67
+
68
+ expect do
69
+ one | two
70
+ end.to_not change(two, :directories)
71
+ end
72
+
73
+ it 'does not mutate the left-hand side parents' do
74
+ one = Directory.new.tap { |o| o.file('a/b') ; o.file('f/g') }
75
+ two = Directory.new.tap { |t| t.file('a/c') ; t.file('d/e') }
76
+
77
+ one_f = one.to_a.find { |e| e.name == 'f' }
78
+ one_f_parent = one_f.parent
79
+
80
+ one | two
81
+
82
+ expect(one_f_parent).to eql(one_f.parent)
83
+ end
84
+
85
+ it 'does not mutate the right-hand side parents' do
86
+ one = Directory.new.tap { |o| o.file('a/b') }
87
+ two = Directory.new.tap { |t| t.file('a/c') ; t.file('d/e') }
88
+
89
+ two_d = two.to_a.find { |e| e.name == 'd' }
90
+ two_d_parent = two_d.parent
91
+
92
+ one | two
93
+
94
+ expect(two_d.parent).to eql(two_d_parent)
95
+ end
26
96
  end
27
97
 
28
98
  it 'allows for manually nesting directories' do
29
- archive = Directory.new
30
- archive.dir('a') do |a|
99
+ directory = Directory.new
100
+ directory.dir('a') do |a|
31
101
  a.dir('b') do |b|
32
102
  b.dir('c')
33
103
  end
34
104
  end
35
105
 
36
- expect(archive.to_a.map(&:path)).to eql(['./a', './a/b', './a/b/c'])
106
+ expect(directory.to_a.map(&:path)).to eql(['./a', './a/b', './a/b/c'])
37
107
  end
38
108
 
39
109
  it 'allows for convenient nesting of directories' do
40
- archive = Directory.new
41
- archive.dir('a/b/c')
110
+ directory = Directory.new
111
+ directory.dir('a/b/c')
42
112
 
43
- expect(archive.to_a.map(&:path)).to eql(['./a', './a/b', './a/b/c'])
113
+ expect(directory.to_a.map(&:path)).to eql(['./a', './a/b', './a/b/c'])
44
114
  end
45
115
 
46
116
  it 'only creates a given path once' do
47
- archive = Directory.new
48
- archive.dir('a/b/c')
49
- archive.dir('a/b/c/d')
117
+ directory = Directory.new
118
+ directory.dir('a/b/c')
119
+ directory.dir('a/b/c/d')
50
120
 
51
- expect(archive.to_a.map(&:path)).
121
+ expect(directory.to_a.map(&:path)).
52
122
  to eql(['./a', './a/b', './a/b/c', './a/b/c/d'])
53
123
  end
54
124
 
55
125
  it 'takes the most recent duplicate directory as authoritative' do
56
- archive = Directory.new
57
- archive.dir('a/b/c')
58
- archive.dir('a/b/d')
126
+ directory = Directory.new
127
+ directory.dir('a/b/c')
128
+ directory.dir('a/b/d')
59
129
 
60
- expect(archive.to_a.map(&:path)).to eql(['./a', './a/b', './a/b/d'])
130
+ expect(directory.to_a.map(&:path)).to eql(['./a', './a/b', './a/b/d'])
61
131
  end
62
132
 
63
133
  it 'allows for manually nesting files in directories' do
64
- archive = Directory.new
65
- archive.dir('a') do |a|
134
+ directory = Directory.new
135
+ directory.dir('a') do |a|
66
136
  a.dir('b') do |b|
67
137
  b.dir('c') do |c|
68
138
  c.file 'README'
@@ -70,32 +140,32 @@ module AndFeathers
70
140
  end
71
141
  end
72
142
 
73
- expect(archive.to_a.map(&:path)).
143
+ expect(directory.to_a.map(&:path)).
74
144
  to eql(['./a', './a/b', './a/b/c', './a/b/c/README'])
75
145
  end
76
146
 
77
147
  it 'allows for convenient nesting of files in directories' do
78
- archive = Directory.new
79
- archive.file('a/b/c/README')
148
+ directory = Directory.new
149
+ directory.file('a/b/c/README')
80
150
 
81
- expect(archive.to_a.map(&:path)).
151
+ expect(directory.to_a.map(&:path)).
82
152
  to eql(['./a', './a/b', './a/b/c', './a/b/c/README'])
83
153
  end
84
154
 
85
155
  it 'only creates a given file once' do
86
- archive = Directory.new
87
- archive.file('a/README')
88
- archive.file('a/README')
156
+ directory = Directory.new
157
+ directory.file('a/README')
158
+ directory.file('a/README')
89
159
 
90
- expect(archive.to_a.map(&:path)).to eql(['./a', './a/README'])
160
+ expect(directory.to_a.map(&:path)).to eql(['./a', './a/README'])
91
161
  end
92
162
 
93
163
  it 'takes the most recent file as the authoritative file' do
94
- archive = Directory.new
95
- archive.file('a/README') { '1' }
96
- archive.file('a/README') { '2' }
164
+ directory = Directory.new
165
+ directory.file('a/README') { '1' }
166
+ directory.file('a/README') { '2' }
97
167
 
98
- readme = archive.to_a.find { |e| e.is_a?(File) }
168
+ readme = directory.to_a.find { |e| e.is_a?(File) }
99
169
 
100
170
  expect(readme.read).to eql('2')
101
171
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: and_feathers
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.pre
4
+ version: 1.0.0.pre.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Cobb
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-23 00:00:00.000000000 Z
11
+ date: 2014-03-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler