paperbin 0.0.3 → 0.1.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 +4 -4
- data/lib/paperbin/handler.rb +21 -9
- data/lib/paperbin/version.rb +1 -1
- data/lib/paperbin/version_mixin.rb +2 -0
- data/spec/paperbin_handler_spec.rb +6 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cf1cd912977e0f0847d562a7812fc4b5e3399968
|
4
|
+
data.tar.gz: 124ee2cfe0f4268eaddac9ed35ce692896c7cc14
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 21307c488260585d7a632144d23635bd9c8faaa070ad5935446f7efd8ff5c4a3ccaba02696275a1d9dbfc598321f9685d719b7cfd888c07f3b439f2f5532b7e3
|
7
|
+
data.tar.gz: 97468df41f6899cf2aca5fd6024c784a1e2344baf11758da243b56db6f3b94f6e0662963228f415ad2d22412183e7f42dd9428ecf5bb903bad948a5c7c0dd121
|
data/lib/paperbin/handler.rb
CHANGED
@@ -77,20 +77,32 @@ class Paperbin::Handler < Struct.new(:id, :type)
|
|
77
77
|
|
78
78
|
def generate_files
|
79
79
|
versions.each do |version|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
80
|
+
write_gz_file version
|
81
|
+
write_md5_file version
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def write_gz_file(version)
|
86
|
+
path = gz_file version
|
87
|
+
unless files_exist?(path)
|
88
|
+
Zlib::GzipWriter.open(path) { |gz| gz.write string_data(version) }
|
86
89
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
+
timestamp = version.created_at.to_time
|
91
|
+
File.utime timestamp, timestamp, path
|
92
|
+
end
|
93
|
+
end
|
90
94
|
|
95
|
+
def write_md5_file(version)
|
96
|
+
File.open(md5_file(version), "w") do |file|
|
97
|
+
md5 = Digest::MD5.hexdigest(string_data(version))
|
98
|
+
file.write md5
|
91
99
|
end
|
92
100
|
end
|
93
101
|
|
102
|
+
def string_data(version)
|
103
|
+
version.to_json
|
104
|
+
end
|
105
|
+
|
94
106
|
def check_versions
|
95
107
|
versions.each_with_index do |version, index|
|
96
108
|
# check both file exist or not
|
data/lib/paperbin/version.rb
CHANGED
@@ -46,8 +46,9 @@ describe Paperbin::Handler do
|
|
46
46
|
end
|
47
47
|
|
48
48
|
context 'generate_files' do
|
49
|
-
let(:
|
50
|
-
let(:
|
49
|
+
let(:timestamp) { Time.now }
|
50
|
+
let(:version_1) { double(id: 1, to_json: "json", created_at: timestamp) }
|
51
|
+
let(:version_2) { double(id: 2, to_json: "json", created_at: timestamp) }
|
51
52
|
let(:file) { double(write: true) }
|
52
53
|
|
53
54
|
before do
|
@@ -57,6 +58,9 @@ describe Paperbin::Handler do
|
|
57
58
|
|
58
59
|
it 'create correct Gzip files' do
|
59
60
|
Zlib::GzipWriter.should_receive(:open).twice
|
61
|
+
expect(File).to receive(:utime).twice.with(
|
62
|
+
timestamp, timestamp, an_instance_of(String)
|
63
|
+
)
|
60
64
|
handler.generate_files
|
61
65
|
end
|
62
66
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: paperbin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- morhekil
|
@@ -13,7 +13,7 @@ authors:
|
|
13
13
|
autorequire:
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
|
-
date: 2014-01-
|
16
|
+
date: 2014-01-23 00:00:00.000000000 Z
|
17
17
|
dependencies:
|
18
18
|
- !ruby/object:Gem::Dependency
|
19
19
|
name: bundler
|