auser-suitcase 0.0.3 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :major: 0
3
3
  :minor: 0
4
- :patch: 3
4
+ :patch: 5
@@ -13,8 +13,14 @@ module Suitcase
13
13
  File.open(filepath,"w") do |tarfile|
14
14
  Archive::Tar::Minitar::Writer.open(tarfile) do |tar|
15
15
  items.each do |name, path|
16
- data = open(path).read
17
- tar.add_file_simple(name, :size=>data.size, :mode=>0644) { |f| f.write(data) }
16
+ if name == :string
17
+ ::File.open("#{dirpath}/#{path[:namespace]}/#{path[:name]}", "w+") do |tf|
18
+ tf << path[:content]
19
+ end
20
+ else
21
+ data = open(path).read
22
+ tar.add_file_simple(name, :size=>data.size, :mode=>0644) { |f| f.write(data) }
23
+ end
18
24
  end
19
25
  end
20
26
  end
@@ -24,11 +30,17 @@ module Suitcase
24
30
  def self.build_dir!(dirpath)
25
31
  ::FileUtils.mkdir_p dirpath unless ::File.directory? dirpath
26
32
  items.each do |name, path|
27
- end_path = "#{dirpath}/#{name}"
28
- unless name == ::File.basename(name)
29
- ::FileUtils.mkdir_p ::File.dirname(end_path) unless ::File.directory? ::File.dirname(end_path)
33
+ if name.to_s =~ /string/
34
+ fpath = "#{dirpath}/#{path[:namespace]}/#{path[:name]}"
35
+ ensure_location_exists(::File.dirname(fpath))
36
+ ::File.open(fpath, "w+") do |tf|
37
+ tf << path[:content]
38
+ end
39
+ else
40
+ end_path = "#{dirpath}/#{name}"
41
+ ::FileUtils.mkdir_p ::File.dirname(end_path) unless ::File.directory? ::File.dirname(end_path) unless name == ::File.basename(name)
42
+ ::FileUtils.cp path, end_path
30
43
  end
31
- ::FileUtils.cp path, end_path
32
44
  end
33
45
  dirpath
34
46
  end
@@ -45,7 +57,7 @@ module Suitcase
45
57
  elsif ::File.directory? f
46
58
  Dir["#{f}/*"].each do |f|
47
59
  add(f, "#{namespace.empty? ? "" : "#{namespace}/"}#{::File.basename(::File.dirname(f))}")
48
- end
60
+ end
49
61
  end
50
62
  end
51
63
  end
@@ -98,6 +110,10 @@ module Suitcase
98
110
  def self.ensure_location_exists(loc)
99
111
  ::FileUtils.mkdir_p loc unless ::File.directory? loc
100
112
  end
113
+
114
+ def self.add_content_as(content="", filename="", namespace="files")
115
+ items.merge!({"string_#{filename}_#{namespace}".to_sym => {:name => ::File.basename(filename), :content => content, :namespace => namespace}})
116
+ end
101
117
 
102
118
  end
103
119
  end
@@ -26,6 +26,19 @@ class DependenciesTest < Test::Unit::TestCase
26
26
  assert_equal Suitcase::Zipper.items.size, 2
27
27
  assert Suitcase::Zipper.items["test_dir/box.rb"] =~ /test_dir\/box\.rb/
28
28
  end
29
+ should "be able to add_content_as" do
30
+ Suitcase::Zipper.add_content_as("hello world", "hello.txt", "files")
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"
35
+ end
36
+ should "add the content as a file when build_dir!" do
37
+ Suitcase::Zipper.add_content_as("hello world", "hello.txt", "files")
38
+ Suitcase::Zipper.build_dir! "#{Dir.pwd}/cache"
39
+ assert ::File.file?(::File.expand_path("#{Dir.pwd}/cache/files/hello.txt"))
40
+ assert_equal open(::File.expand_path("#{Dir.pwd}/cache/files/hello.txt")).read, "hello world"
41
+ end
29
42
  should "be able to add directories into namespaces" do
30
43
  Suitcase::Zipper.add("#{::File.dirname(__FILE__)}/test_dir", "box")
31
44
  assert Suitcase::Zipper.items["box/test_dir/box.rb"] =~ /test_dir\/box\.rb/
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.3
4
+ version: 0.0.5
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-12 00:00:00 -07:00
12
+ date: 2009-04-16 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -29,24 +29,26 @@ executables: []
29
29
  extensions: []
30
30
 
31
31
  extra_rdoc_files:
32
- - LICENSE
33
32
  - README.rdoc
34
- files:
35
33
  - LICENSE
34
+ files:
36
35
  - README.rdoc
37
- - Rakefile
38
36
  - VERSION.yml
39
- - lib/suitcase.rb
37
+ - lib/suitcase
40
38
  - lib/suitcase/unzipper.rb
41
39
  - lib/suitcase/zipper.rb
40
+ - lib/suitcase.rb
42
41
  - test/suitcase_test.rb
42
+ - test/test_dir
43
43
  - test/test_dir/box.rb
44
44
  - test/test_dir/test.txt
45
45
  - test/test_helper.rb
46
+ - LICENSE
46
47
  has_rdoc: true
47
48
  homepage: http://github.com/auser/suitcase
48
49
  post_install_message:
49
50
  rdoc_options:
51
+ - --inline-source
50
52
  - --charset=UTF-8
51
53
  require_paths:
52
54
  - lib
@@ -69,7 +71,5 @@ rubygems_version: 1.2.0
69
71
  signing_key:
70
72
  specification_version: 2
71
73
  summary: TODO
72
- test_files:
73
- - test/suitcase_test.rb
74
- - test/test_dir/box.rb
75
- - test/test_helper.rb
74
+ test_files: []
75
+
data/Rakefile DELETED
@@ -1,57 +0,0 @@
1
- require 'rubygems'
2
- require 'rake'
3
-
4
- begin
5
- require 'jeweler'
6
- Jeweler::Tasks.new do |gem|
7
- gem.name = "suitcase"
8
- gem.summary = %Q{TODO}
9
- gem.email = "arilerner@mac.com"
10
- gem.homepage = "http://github.com/auser/suitcase"
11
- gem.authors = ["Ari Lerner"]
12
- gem.add_dependency('tarruby')
13
-
14
- # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
- end
16
- rescue LoadError
17
- puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
18
- end
19
-
20
- require 'rake/testtask'
21
- Rake::TestTask.new(:test) do |test|
22
- test.libs << 'lib' << 'test'
23
- test.pattern = 'test/**/*_test.rb'
24
- test.verbose = false
25
- end
26
-
27
- begin
28
- require 'rcov/rcovtask'
29
- Rcov::RcovTask.new do |test|
30
- test.libs << 'test'
31
- test.pattern = 'test/**/*_test.rb'
32
- test.verbose = true
33
- end
34
- rescue LoadError
35
- task :rcov do
36
- abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
37
- end
38
- end
39
-
40
-
41
- task :default => :test
42
-
43
- require 'rake/rdoctask'
44
- Rake::RDocTask.new do |rdoc|
45
- if File.exist?('VERSION.yml')
46
- config = YAML.load(File.read('VERSION.yml'))
47
- version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
48
- else
49
- version = ""
50
- end
51
-
52
- rdoc.rdoc_dir = 'rdoc'
53
- rdoc.title = "suitcase #{version}"
54
- rdoc.rdoc_files.include('README*')
55
- rdoc.rdoc_files.include('lib/**/*.rb')
56
- end
57
-