dynamic_image 0.9.8 → 0.9.9
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/app/controllers/images_controller.rb +1 -1
- data/dynamic_image.gemspec +1 -1
- data/lib/binary_storage.rb +2 -2
- data/lib/binary_storage/blob.rb +17 -18
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.9.
|
1
|
+
0.9.9
|
data/dynamic_image.gemspec
CHANGED
data/lib/binary_storage.rb
CHANGED
@@ -12,11 +12,11 @@ module BinaryStorage
|
|
12
12
|
def storage_dir
|
13
13
|
@@storage_dir ||= Rails.root.join('db/binary_storage', Rails.env)
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
def storage_dir=(new_storage_dir)
|
17
17
|
@@storage_dir = new_storage_dir
|
18
18
|
end
|
19
|
-
|
19
|
+
|
20
20
|
def hexdigest_file(path)
|
21
21
|
Digest::SHA1.file(path).hexdigest
|
22
22
|
end
|
data/lib/binary_storage/blob.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module BinaryStorage
|
2
2
|
class Blob
|
3
|
-
|
3
|
+
|
4
4
|
class << self
|
5
5
|
def find(hash_string)
|
6
6
|
blob = self.new(:hash_string => hash_string)
|
@@ -18,52 +18,51 @@ module BinaryStorage
|
|
18
18
|
blob.save
|
19
19
|
blob
|
20
20
|
end
|
21
|
-
|
21
|
+
|
22
22
|
def storage_dir(hash_string=nil)
|
23
23
|
root = BinaryStorage.storage_dir
|
24
24
|
(hash_string) ? File.join(root, hash_string.match(/^(..)/)[1]) : root
|
25
25
|
end
|
26
|
-
|
26
|
+
|
27
27
|
def storage_path(hash_string)
|
28
28
|
File.join(storage_dir(hash_string), hash_string.gsub(/^(..)/, ''))
|
29
29
|
end
|
30
30
|
end
|
31
|
-
|
31
|
+
|
32
32
|
def initialize(*args)
|
33
|
-
args = *args
|
34
33
|
options = {
|
35
34
|
:hash_string => nil,
|
36
35
|
:data => nil
|
37
36
|
}
|
38
|
-
if args.kind_of?(Hash)
|
39
|
-
options.merge!(args)
|
37
|
+
if args.first.kind_of?(Hash)
|
38
|
+
options.merge!(args.first)
|
40
39
|
else
|
41
|
-
options[:data] = args
|
40
|
+
options[:data] = args.first
|
42
41
|
end
|
43
42
|
@hash_string = options[:hash_string]
|
44
43
|
@data = options[:data]
|
45
44
|
end
|
46
|
-
|
45
|
+
|
47
46
|
def data
|
48
47
|
@data
|
49
48
|
end
|
50
|
-
|
49
|
+
|
51
50
|
def data=(new_data)
|
52
51
|
@hash_string = nil
|
53
52
|
@data = new_data
|
54
53
|
end
|
55
|
-
|
54
|
+
|
56
55
|
def hash_string
|
57
56
|
unless @hash_string
|
58
57
|
if @data
|
59
58
|
@hash_string = BinaryStorage.hexdigest(data)
|
60
59
|
else
|
61
|
-
raise "Binary has no data!"
|
60
|
+
raise "Binary has no data!"
|
62
61
|
end
|
63
62
|
end
|
64
63
|
@hash_string
|
65
64
|
end
|
66
|
-
|
65
|
+
|
67
66
|
def storage_dir
|
68
67
|
BinaryStorage::Blob.storage_dir(hash_string)
|
69
68
|
end
|
@@ -71,20 +70,20 @@ module BinaryStorage
|
|
71
70
|
def storage_path
|
72
71
|
BinaryStorage::Blob.storage_path(hash_string)
|
73
72
|
end
|
74
|
-
|
73
|
+
|
75
74
|
def exists?
|
76
75
|
File.exists?(storage_path)
|
77
76
|
end
|
78
|
-
|
77
|
+
|
79
78
|
def empty?
|
80
79
|
(hash_string && !exists?) || !data || data.empty?
|
81
80
|
end
|
82
|
-
|
81
|
+
|
83
82
|
def load
|
84
83
|
raise "File not found" unless exists?
|
85
84
|
@data = File.open(storage_path, "rb") {|io| io.read }
|
86
85
|
end
|
87
|
-
|
86
|
+
|
88
87
|
def delete
|
89
88
|
if exists?
|
90
89
|
FileUtils.rm(storage_path)
|
@@ -100,6 +99,6 @@ module BinaryStorage
|
|
100
99
|
end
|
101
100
|
return true
|
102
101
|
end
|
103
|
-
|
102
|
+
|
104
103
|
end
|
105
104
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dynamic_image
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 41
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 9
|
9
|
-
-
|
10
|
-
version: 0.9.
|
9
|
+
- 9
|
10
|
+
version: 0.9.9
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- "Inge J\xC3\xB8rgensen"
|