treet 0.10.3 → 0.11.0

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/README.md CHANGED
@@ -85,6 +85,7 @@ are not allowed.
85
85
 
86
86
  ## TODO
87
87
 
88
+ * why is caching built into treet farm? The data on disk could change. Caching doesn't belong here.
88
89
  * Enforce limitation on structure depth (top-level elements can contain flat hashes or arrays, nothing else)
89
90
  * refac: move diff stuff from hash.rb to Treet::Diff class, to encapsulate the structure of a diff (array of arrays); create methods for hunting for special stuff in a diff
90
91
  * Check all exceptions for explicit classes
data/lib/treet/farm.rb CHANGED
@@ -14,17 +14,17 @@ class Treet::Farm
14
14
  end
15
15
 
16
16
  def repos(opts = {})
17
- @repos_cache ||= Dir.glob("#{root}/*").each_with_object({}) do |subdir,h|
17
+ xrefs.each_with_object({}) do |subdir,h|
18
18
  # in a Farm we are looking for repositories under the root
19
- if File.directory?(subdir)
20
- xref = File.basename(subdir)
21
- h[xref] = repotype.new(subdir, opts.merge(:xrefkey => xrefkey, :xref => xref))
22
- end
19
+ h[subdir] = repo(subdir, opts)
23
20
  end
24
21
  end
25
22
 
26
- def reset
27
- @repos_cache = nil
23
+ def repo(id, opts = {})
24
+ repotype.new("#{root}/#{id}", opts)
25
+ rescue Errno::ENOENT
26
+ # no such repository exists
27
+ nil
28
28
  end
29
29
 
30
30
  # export as an array, not as a hash
@@ -58,10 +58,6 @@ class Treet::Farm
58
58
  end
59
59
  end
60
60
 
61
- def [](xref)
62
- repos[xref]
63
- end
64
-
65
61
  # add a new repo, with data from an input hash
66
62
  # if an :id is provided, then the new repo will be stored under that directory name,
67
63
  # otherwise a unique id will be generated
@@ -70,4 +66,14 @@ class Treet::Farm
70
66
  thash = Treet::Hash.new(hash)
71
67
  repos[uuid] = thash.to_repo("#{root}/#{uuid}", opts.merge(:repotype => repotype))
72
68
  end
69
+
70
+ def xrefs
71
+ Dir.chdir(root) do
72
+ Dir.glob("*").select {|f| File.directory?(f)}
73
+ end
74
+ end
75
+
76
+ def count
77
+ xrefs.count
78
+ end
73
79
  end
data/lib/treet/gitfarm.rb CHANGED
@@ -18,6 +18,10 @@ class Treet::Gitfarm < Treet::Farm
18
18
  super(:author => author)
19
19
  end
20
20
 
21
+ def repo(id, opts = {})
22
+ super(id, opts.merge(:author => author))
23
+ end
24
+
21
25
  def add(hash, opts = {})
22
26
  repo = super(hash, opts.merge(:author => author))
23
27
  if opts[:tag]
data/lib/treet/repo.rb CHANGED
@@ -4,7 +4,7 @@ class Treet::Repo
4
4
  attr_reader :root
5
5
 
6
6
  def initialize(path, opts = {})
7
- raise "Missing or invalid source path #{path}" unless File.directory?(path)
7
+ raise Errno::ENOENT, "Missing or invalid source path #{path}" unless File.directory?(path)
8
8
 
9
9
  @root = path
10
10
  end
@@ -13,10 +13,6 @@ class Treet::Repo
13
13
  expand(root)
14
14
  end
15
15
 
16
- def reset
17
- # clear any cached data
18
- end
19
-
20
16
  def compare(target)
21
17
  Treet::Hash.diff(to_hash, target.to_hash)
22
18
  end
@@ -45,7 +41,7 @@ class Treet::Repo
45
41
 
46
42
  Dir.chdir(root) do
47
43
  diffs.each do |diff|
48
- flag, key, v1, v2 = diff
44
+ flag, key, v1, _ = diff
49
45
  # if key =~ /\[/
50
46
  # keyname = key.match(/^(.*)\[\]$/).captures
51
47
  # elsif key =~ /\./
data/lib/treet/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Treet
2
- VERSION = "0.10.3"
2
+ VERSION = "0.11.0"
3
3
  end
@@ -14,7 +14,6 @@ describe "Repo" do
14
14
  repo.to_hash.should == {
15
15
  'name' => {'full' => 'John Bigbooté'}
16
16
  }
17
- repo.reset
18
17
  repo.to_hash.should == {
19
18
  'name' => {'full' => 'John Bigbooté'}
20
19
  }
@@ -32,7 +32,7 @@ describe "Repository Farm" do
32
32
  end
33
33
 
34
34
  it "planting should create a directory of UUID-labeled repos" do
35
- farm = Treet::Farm.plant(:json => "#{File.dirname(__FILE__)}/../json/master.json", :root => Dir.mktmpdir)
35
+ farm = Treet::Farm.plant(:json => jsonfile('master'), :root => Dir.mktmpdir)
36
36
 
37
37
  Dir.glob("#{farm.root}/*").count.must_equal 3
38
38
  Dir.glob("#{farm.root}/*/emails/*").count.must_equal 5
@@ -47,9 +47,17 @@ describe "Repository Farm" do
47
47
  # farm['two'].to_hash['xref'].must_equal {'test' => 'two'}
48
48
  # end
49
49
 
50
+ it "should allow direct fetch by id" do
51
+ farm = Treet::Farm.plant(:json => jsonfile('master'), :root => Dir.mktmpdir)
52
+ repoid = farm.xrefs.sample
53
+ farm.repo(repoid).wont_be_nil
54
+ farm.repo("BOGUS").must_be_nil
55
+ end
56
+
50
57
  it "should take additions" do
51
- farm = Treet::Farm.plant(:json => "#{File.dirname(__FILE__)}/../json/master.json", :root => Dir.mktmpdir)
58
+ farm = Treet::Farm.plant(:json => jsonfile('master'), :root => Dir.mktmpdir)
52
59
  farm.repos.count.must_equal 3
60
+ farm.count.must_equal 3
53
61
 
54
62
  bob_hash = load_json("bob1")
55
63
  repo = farm.add(bob_hash)
@@ -35,6 +35,11 @@ describe Treet::Gitfarm do
35
35
  repo.tags.must_be_empty
36
36
  end
37
37
  end
38
+
39
+ it "should retrieve by id" do
40
+ repoid = farm.repos.keys.sample
41
+ farm.repo(repoid).wont_be_nil
42
+ end
38
43
  end
39
44
 
40
45
  describe "new repo in empty farm" do
@@ -185,7 +185,7 @@ describe Treet::Gitrepo do
185
185
 
186
186
  describe "a tagged & patched repo" do
187
187
  def self.makerepo
188
- @cache ||= begin
188
+ @repo ||= begin
189
189
  r = make_gitrepo('two',
190
190
  :author => {:name => 'Bob', :email => 'bob@example.com'},
191
191
  :xrefkey => 'app1',
@@ -269,7 +269,7 @@ describe Treet::Gitrepo do
269
269
 
270
270
  describe "a multiply-patched gitrepo" do
271
271
  def self.makerepo
272
- @cache ||= begin
272
+ @repo ||= begin
273
273
  r = make_gitrepo('two', :author => {:name => 'Bob', :email => 'bob@example.com'})
274
274
  r.tag('app1')
275
275
  r.tag('app2')
data/treet.gemspec CHANGED
@@ -23,4 +23,5 @@ Gem::Specification.new do |gem|
23
23
  gem.add_development_dependency "guard-rspec"
24
24
  gem.add_development_dependency "guard-minitest"
25
25
  gem.add_development_dependency "ruby_gntp"
26
+ gem.add_development_dependency "rb-fsevent"
26
27
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: treet
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.3
4
+ version: 0.11.0
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-12-12 00:00:00.000000000 Z
12
+ date: 2013-01-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: thor
@@ -123,6 +123,22 @@ dependencies:
123
123
  - - ! '>='
124
124
  - !ruby/object:Gem::Version
125
125
  version: '0'
126
+ - !ruby/object:Gem::Dependency
127
+ name: rb-fsevent
128
+ requirement: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ! '>='
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ type: :development
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
126
142
  description: Transform between trees of files and JSON blobs
127
143
  email:
128
144
  - jmay@pobox.com
@@ -190,7 +206,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
190
206
  version: '0'
191
207
  segments:
192
208
  - 0
193
- hash: 2545579231990389105
209
+ hash: -2853716979805169129
194
210
  required_rubygems_version: !ruby/object:Gem::Requirement
195
211
  none: false
196
212
  requirements:
@@ -199,7 +215,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
199
215
  version: '0'
200
216
  segments:
201
217
  - 0
202
- hash: 2545579231990389105
218
+ hash: -2853716979805169129
203
219
  requirements: []
204
220
  rubyforge_project:
205
221
  rubygems_version: 1.8.24