auser-suitcase 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :minor: 0
3
- :patch: 6
4
- :major: 0
3
+ :patch: 7
4
+ :major: 0
@@ -61,37 +61,37 @@ module Suitcase
61
61
  end
62
62
  end
63
63
  end
64
-
65
- def self.gems(gem_list, gem_location)
64
+
65
+ # TODO: MOVE
66
+ def self.gems(gem_list, o={})
66
67
  require 'rubygems/dependency_installer'
67
68
  gem_list = [gem_list] unless gem_list.is_a?(Array)
68
- ensure_location_exists gem_location
69
-
70
- cache_dir = "#{gem_location}/cache"
71
- ::FileUtils.mkdir_p cache_dir rescue nil unless File.exist? cache_dir
69
+
70
+ gem_list.each do |g|
71
+ add find_gem(g, o), "gems"
72
+ end
73
+ end
74
+
75
+ # Find the gem named named
76
+ # First, search in the :search_paths passed in via the options
77
+ # If it's not found there, then search in the locally installed gems
78
+ # and finally search online if the gem isn't available
79
+ def self.find_gem(named, o={})
80
+ require 'rubygems/dependency_installer'
72
81
 
73
- locally_installed_gems = Gem::SourceIndex.from_installed_gems.map {|n,s| s.name }
82
+ # Look for the gem in a path passed
83
+ found_path = search_path_for_gem_in_paths(named, o[:search_paths]) if o[:search_paths]
84
+ return found_path if found_path
74
85
 
75
- locally_installable_gems = gem_list & locally_installed_gems
76
- remotely_installable = gem_list - locally_installable_gems
86
+ found_path = find_gem_in_locally_installed_gems(named)
87
+ return found_path if found_path
77
88
 
78
- # First, add the locally installed gems
79
- locally_installable_gems.each do |spec|
80
- spec = Gem::SourceIndex.from_installed_gems.find_name(spec).last#.sort_by {|a,b| a.version <=> b.version }.last
81
- f = Dir[File.join(Gem.dir, 'cache', "#{spec.full_name}.gem")].first
82
- add(f, "gems")
83
- end
89
+ gem_location = o[:temp_path] || "/tmp/gems"
90
+ ensure_location_exists(gem_location)
84
91
 
85
- remotely_installable.each do |g|
86
- di = Gem::DependencyInstaller.new
87
- spec, url = di.find_spec_by_name_and_version(g).first
88
- f = begin
89
- Gem::RemoteFetcher.fetcher.download spec, "http://gems.github.com", gem_location
90
- rescue Exception => e
91
- Gem::RemoteFetcher.fetcher.download spec, url, gem_location
92
- end
93
- add(f, "gems")
94
- end
92
+ found_path = find_gem_remotely_by_name_and_download_to(named, gem_location)
93
+ return found_path if found_path
94
+ nil
95
95
  end
96
96
 
97
97
  def self.packages(package_list, package_location="#{Dir.pwd}/packages")
@@ -114,6 +114,54 @@ module Suitcase
114
114
  def self.add_content_as(content="", filename="", namespace="files")
115
115
  items.merge!({"__p__string#{filename}_#{namespace}".to_sym => {:name => ::File.basename(filename), :content => content, :namespace => namespace}})
116
116
  end
117
+
118
+ def self.reset!
119
+ @items = nil
120
+ end
121
+
122
+ private
123
+ # Search for the gem in a given path
124
+ def self.search_path_for_gem_in_paths(named, dirs)
125
+ fi = dirs.map do |d|
126
+ q = Dir["#{d}/*"].entries.detect {|fi|fi =~ /#{named}/}
127
+ q ? q : nil
128
+ end.compact.first
129
+ end
130
+
131
+ # Search in the locally installed gems
132
+ def self.find_gem_in_locally_installed_gems(named)
133
+ locally_installed_gems_list = locally_installed_gems.map {|n,s| s.name }
134
+
135
+ locally_installed_gems_list.detect do |g|
136
+ if g == named
137
+ spec = locally_installed_gems.find_name(g).last
138
+ if f = Dir[File.join(Gem.dir, 'cache', "#{spec.full_name}.gem")].first
139
+ return f
140
+ end
141
+ end
142
+ end
143
+ nil
144
+ end
145
+
146
+ def self.locally_installed_gems
147
+ @locally_installed_gems ||= Gem::SourceIndex.from_installed_gems
148
+ end
149
+
150
+ # Find the gem from online, first trying gems.github.com
151
+ # and then from rubyforge
152
+ def self.find_gem_remotely_by_name_and_download_to(named, to, o={})
153
+ # Look for the gems from remote
154
+ di = Gem::DependencyInstaller.new
155
+ spec, url = di.find_spec_by_name_and_version(named).first
156
+ f = begin
157
+ Gem::RemoteFetcher.fetcher.download spec, "http://gems.github.com", to
158
+ rescue Exception => e
159
+ Gem::RemoteFetcher.fetcher.download spec, url, to
160
+ end
161
+ return f if f
162
+ nil
163
+ end
164
+
117
165
 
118
166
  end
119
167
  end
@@ -23,15 +23,16 @@ class DependenciesTest < Test::Unit::TestCase
23
23
  end
24
24
  should "be able to add directories to the suitcase" do
25
25
  Suitcase::Zipper.add("#{::File.dirname(__FILE__)}/test_dir")
26
- assert_equal Suitcase::Zipper.items.size, 2
26
+ assert_equal Suitcase::Zipper.items.size, 3
27
27
  assert Suitcase::Zipper.items["test_dir/box.rb"] =~ /test_dir\/box\.rb/
28
28
  end
29
29
  should "be able to add_content_as" do
30
30
  Suitcase::Zipper.add_content_as("hello world", "hello.txt", "files")
31
31
  assert_equal Suitcase::Zipper.items.size, 1
32
- assert Suitcase::Zipper.items[:string][:name] == "hello.txt"
33
- assert Suitcase::Zipper.items[:string][:content] == "hello world"
34
- assert Suitcase::Zipper.items[:string][:namespace] == "files"
32
+ fitem = Suitcase::Zipper.items[:"__p__stringhello.txt_files"]
33
+ assert fitem[:name] == "hello.txt"
34
+ assert fitem[:content] == "hello world"
35
+ assert fitem[:namespace] == "files"
35
36
  end
36
37
  should "add the content as a file when build_dir!" do
37
38
  Suitcase::Zipper.add_content_as("hello world", "hello.txt", "files")
@@ -45,12 +46,17 @@ class DependenciesTest < Test::Unit::TestCase
45
46
  end
46
47
  # UNCOMMENT THESE TO LIVE-TEST THE USAGE
47
48
  should "be able to add gems to the suitcase" do
48
- Suitcase::Zipper.gems("rake", Dir.pwd)
49
+ Suitcase::Zipper.gems("rake", :temp_path => Dir.pwd)
49
50
  Suitcase::Zipper.build_dir! "#{Dir.pwd}/cache"
50
51
  assert ::File.file?(::File.expand_path("#{Dir.pwd}/cache/gems/rake-0.8.4.gem"))
51
52
  end
53
+ should "be able to add gems to the suitcase with a direct search path" do
54
+ Suitcase::Zipper.gems("carrot", :temp_path => Dir.pwd, :search_paths => ["#{File.dirname(__FILE__)}/test_dir/gems"])
55
+ Suitcase::Zipper.build_dir! "#{Dir.pwd}/cache"
56
+ assert ::File.file?(::File.expand_path("#{Dir.pwd}/cache/gems/famoseagle-carrot-0.6.0.gem"))
57
+ end
52
58
  should "find the gem online if it is not locally installed" do
53
- Suitcase::Zipper.gems("aaronp-meow", Dir.pwd)
59
+ Suitcase::Zipper.gems("aaronp-meow", :temp_path => Dir.pwd)
54
60
  assert ::File.file?(::File.expand_path("#{Dir.pwd}/cache/aaronp-meow-1.1.0.gem"))
55
61
  end
56
62
  # should "be able to add packages to the suitcase" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: auser-suitcase
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ari Lerner
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-04-27 00:00:00 -07:00
12
+ date: 2009-06-15 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -41,6 +41,8 @@ files:
41
41
  - test/suitcase_test.rb
42
42
  - test/test_dir
43
43
  - test/test_dir/box.rb
44
+ - test/test_dir/gems
45
+ - test/test_dir/gems/famoseagle-carrot-0.6.0.gem
44
46
  - test/test_dir/test.txt
45
47
  - test/test_helper.rb
46
48
  - LICENSE
@@ -69,7 +71,7 @@ requirements: []
69
71
  rubyforge_project:
70
72
  rubygems_version: 1.2.0
71
73
  signing_key:
72
- specification_version: 2
74
+ specification_version: 3
73
75
  summary: TODO
74
76
  test_files: []
75
77