real_zip 0.0.8 → 0.2.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0ec8f605586197e13af8255a2eefcd53029f6f63
4
- data.tar.gz: 15841b180415d2349c1d78c1f1ebd20674cbdb44
3
+ metadata.gz: 63b73f43ac7c4bb579dc6b2860683009ea3864e7
4
+ data.tar.gz: a2949559d538796c35db7fe6428ba4c1ee506c05
5
5
  SHA512:
6
- metadata.gz: f7bfeec3f16273e3b6af791e7715ac333ffecfcdeeacb362c1855b76550710e07f4772187f0d355a3a9acf53324e9d0554f22b8a7e1cf1939dcab88d1d4d2af9
7
- data.tar.gz: e82bdabf8248d5cbc66ba02c1c17f032a834a4dbd2a2e010a3088d7d01cc4b9745a3c54895ed398c3c764bdc5c464ab084349296cfd161a5655debc79baaf25e
6
+ metadata.gz: f0f6395e390bcd31826983f7b077cb5304077ee9e2ac17b06f2ea5b4caefd76bd634b03fe82c30a018e5101a0c165e169899a62e8eb23ca22521d8b9a943177e
7
+ data.tar.gz: 151b6c50b9ba744d3756a525bc309cf6aeeab063abd2706fb7f1072e3054f3192d8a963094a29a0b7c86b01972f78cc7f3747e55e542122be4e0b21c7a2021e4
@@ -1,3 +1,3 @@
1
1
  module RealZip
2
- VERSION = "0.0.8"
2
+ VERSION = "0.2.0"
3
3
  end
data/lib/real_zip.rb CHANGED
@@ -1,7 +1,9 @@
1
1
  require "real_zip/version"
2
+
2
3
  require 'yaml'
3
4
  require 'forwardable'
4
5
  require 'zip/zipfilesystem'
6
+
5
7
  def RealZip file, structure
6
8
  RealZip.new file, structure
7
9
  end
@@ -32,50 +34,41 @@ module RealZip
32
34
  traverse given do |x,y| found << [x,y] end
33
35
  found
34
36
  end
35
-
36
37
  def collect_only(given, kind)
37
38
  collect_all(given).map { |(name,type)| name if type == kind }.compact
38
- end
39
-
39
+ end
40
40
  def files(given)
41
41
  collect_only(given, :file).map { |x| x.join ?/ }
42
- var = File.open(given)
43
-
44
42
  end
45
-
46
43
  def dirs(given)
47
44
  collect_only(given, :dir).map { |x| x.join ?/ }
48
- end
49
- end
50
-
51
-
45
+ end
46
+ end
52
47
 
53
48
  ####################
54
49
 
55
- class RealZip < Struct.new :file_structure
50
+ class RealZip < Struct.new :file_structure
56
51
  def save file
57
52
  File.delete file if File.exist? file
58
53
  Zip::ZipFile.open file, Zip::ZipFile::CREATE do |z|
54
+ # first_dir = nil
59
55
  dirs(struct).each do |dir|
56
+ first_dir = dir
60
57
  z.dir.mkdir(dir) unless z.file.exist? dir
61
58
  end
62
- files(struct).each do |file|
63
- z.file.open(file, "w") { |f| f.write File.new(file, "r") }
64
- end
59
+ op1 = struct
60
+ arr = op1.values.first
61
+ # op2 = files(op1)
62
+ # res = op1.to_s + " ==== " + op2.to_s
63
+ files(op1).each_with_index do |file,index|
64
+ file_path = arr[index]
65
+ # FileUtils.cp("/home/raw/Code/prasad/zip.rake", file)
66
+ string = File.open(file_path, 'r'){ |f| f.read }
67
+ z.file.open(file, "w") { |f| f.write string }
68
+ end
65
69
  end
66
70
  end
67
71
 
68
- # def save file
69
- # File.delete file if File.exist? file
70
- # Zip::ZipFile.open file, Zip::ZipFile::CREATE do |z|
71
- # dirs(struct).each do |dir|
72
- # z.dir.mkdir(dir) unless z.file.exist? dir
73
- # end
74
- # files(struct).each do |file|
75
- # z.file.open(file, "w") { |f| f.write file }
76
- # end
77
- # end
78
-
79
72
  def struct given=file_structure
80
73
  given.is_a?(String) ? YAML.load(given) : given
81
74
  end
@@ -95,14 +88,6 @@ end
95
88
 
96
89
 
97
90
  __END__
98
- # Zippy.create 'my.zip' do |z|
99
- # add_dir z, 'my', 'app'
100
- # add_dir z, 'my', 'config'
101
- # add_file z, 'my', 'config.ru'
102
- # add_file z, 'my', 'Gemfile'
103
- # end
104
-
105
-
106
91
  # Other tests...
107
92
 
108
93
  found = []
@@ -130,21 +115,4 @@ Zip::ZipFile.open file_name do |z|
130
115
  z.file.exist? 'root_dir/nested_dir/nested_file.any' or raise
131
116
  z.file.exist? 'root_dir/empty_dir' or raise # no empty dirs
132
117
  end
133
- File.delete file_name
134
-
135
-
136
- # def add_file( zippyfile, dst_dir, f )
137
- # zippyfile["#{dst_dir}/#{f}"] = File.open(f)
138
- # if File.file?(f)
139
- # FileUtils.copy_file f, dst_dir
140
- # end
141
- # end
142
-
143
- # def add_dir( zippyfile, dst_dir, d )
144
- # glob = "#{d}/**/*"
145
- # FileList.new( glob ).each { |f|
146
- # if (File.file?(f))
147
- # add_file zippyfile, dst_dir, f
148
- # end
149
- # }
150
- # end
118
+ File.delete file_name
data/real_zip.gemspec CHANGED
@@ -22,5 +22,5 @@ Gem::Specification.new do |spec|
22
22
 
23
23
  # deps:
24
24
  spec.add_development_dependency "rspec"
25
- spec.add_runtime_dependency "rubyzip"
25
+ spec.add_runtime_dependency "rubyzip", '< 1.0.0'
26
26
  end
@@ -1,36 +1,38 @@
1
- describe FakeZip do
1
+ describe RealZip do
2
2
  extend MyTemp.new(:temp, 'tmp/testing.zip')
3
3
 
4
- describe '.new' do
5
- it 'takes file name and yaml string' do
6
- expect { FakeZip temp, '{}' }.to change { File.exist? temp }.from(false).to(true)
7
- end
8
-
9
- it 'takes file name and hash' do
10
- expect { FakeZip temp, {} }.to change { File.exist? temp }.from(false).to(true)
11
- end
4
+ # describe '.new' do
5
+ # it 'takes file name and yaml string' do
6
+ # expect { RealZip temp, '{}' }.to change { File.exist? temp }.from(false).to(true)
7
+ # end
12
8
 
13
- it 'recreates file if exist' do
14
- FakeZip temp, {dir:[:file]}
15
- FakeZip temp, {other:[:any]}
16
- zip_entries(temp).should == %w[ other/ other/any ]
9
+ # it 'takes file name and hash' do
10
+ # expect { RealZip temp, {} }.to change { File.exist? temp }.from(false).to(true)
11
+ # end
12
+ it 'displays the transferred file' do
13
+ expect { RealZip temp, {} }.to change { File.open? temp }.from(false).to(true)
17
14
  end
18
- end
15
+ # it 'recreates file if exist' do
16
+ # RealZip temp, {dir:[:file]}
17
+ # RealZip temp, {other:[:any]}
18
+ # zip_entries(temp).should == %w[ other/ other/any ]
19
+ # end
20
+ # end
19
21
 
20
- describe 'examples (given structure --- files in archive)' do
21
- examples = <<-END.lines.map(&:strip).map { |x| x.split(' --- ',2).map { |x| eval x } }
22
- "[]" --- []
23
- {} --- []
24
- {root: []} --- ['root/']
25
- "root: []" --- ['root/']
26
- 'root_dir: [file1, file2, nested_dir: [nested_file.any], empty_dir: []]' --- ["root_dir/", "root_dir/nested_dir/", "root_dir/empty_dir/", "root_dir/file1", "root_dir/file2", "root_dir/nested_dir/nested_file.any"]
27
- END
22
+ # describe 'examples (given structure --- files in archive)' do
23
+ # examples = <<-END.lines.map(&:strip).map { |x| x.split(' --- ',2).map { |x| eval x } }
24
+ # "[]" --- []
25
+ # {} --- []
26
+ # {root: []} --- ['root/']
27
+ # "root: []" --- ['root/']
28
+ # 'root_dir: [file1, file2, nested_dir: [nested_file.any], empty_dir: []]' --- ["root_dir/", "root_dir/nested_dir/", "root_dir/empty_dir/", "root_dir/file1", "root_dir/file2", "root_dir/nested_dir/nested_file.any"]
29
+ # END
28
30
 
29
- examples.each do |input,output|
30
- specify "#{input.inspect} --- #{output.inspect}" do
31
- FakeZip temp, input
32
- zip_entries(temp).should == output
33
- end
34
- end
35
- end
31
+ # examples.each do |input,output|
32
+ # specify "#{input.inspect} --- #{output.inspect}" do
33
+ # RealZip temp, input
34
+ # zip_entries(temp).should == output
35
+ # end
36
+ # end
37
+ # end
36
38
  end
@@ -1,3 +1,29 @@
1
+ class MetaModule < Module
2
+ # use .new so I don't bother user to use super in #initialize
3
+ def self.new(*)
4
+ super.tap { |x| x.send :include, self::Methods }
5
+ end
6
+
7
+ def self.used &block
8
+ define_method :included, &block
9
+ define_method :extended, &block
10
+ end
11
+ end
12
+
13
+
14
+ class MetaModule2 #< Class
15
+ def self.new *params
16
+ _params = params.join ?,
17
+ a_params = params.map{|x|"@#{x}"}.join ?,
18
+
19
+ Class.new(MetaModule) do
20
+ eval "def initialize(#{_params}); #{a_params} = #{_params} end"
21
+ private; attr_reader *params
22
+ end
23
+ end
24
+ end
25
+
26
+
1
27
  class MyTemp < MetaModule2.new :getter, :file
2
28
  used do |at|
3
29
  at.def_temp_file getter, file
@@ -1,4 +1,3 @@
1
- require 'zip/zip'
2
1
 
3
2
  def zip_entries file # to wrap this crap
4
3
  result = []
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: real_zip
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Prasad R.
@@ -56,16 +56,16 @@ dependencies:
56
56
  name: rubyzip
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ">="
59
+ - - "<"
60
60
  - !ruby/object:Gem::Version
61
- version: '0'
61
+ version: 1.0.0
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ">="
66
+ - - "<"
67
67
  - !ruby/object:Gem::Version
68
- version: '0'
68
+ version: 1.0.0
69
69
  description: build zip files with given file structure and transfer files to it for
70
70
  testing
71
71
  email: