ungulate 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/ungulate/job.rb +16 -1
- data/spec/ungulate/job_spec.rb +14 -0
- metadata +4 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.4
|
data/lib/ungulate/job.rb
CHANGED
@@ -10,6 +10,9 @@ module Ungulate
|
|
10
10
|
class Job
|
11
11
|
attr_accessor :bucket, :key, :notification_url, :queue, :versions
|
12
12
|
|
13
|
+
@@blobs_from_urls = {}
|
14
|
+
cattr_accessor :blobs_from_urls
|
15
|
+
|
13
16
|
def self.s3
|
14
17
|
@s3 ||=
|
15
18
|
RightAws::S3.new(ENV['AMAZON_ACCESS_KEY_ID'],
|
@@ -50,12 +53,24 @@ module Ungulate
|
|
50
53
|
end
|
51
54
|
end
|
52
55
|
|
56
|
+
def blob_from_url(url)
|
57
|
+
Job.blobs_from_urls[url] ||=
|
58
|
+
begin
|
59
|
+
@logger.info "Grabbing blob from URL #{url}"
|
60
|
+
Curl::Easy.http_get(url).body_str
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def magick_image_from_url(url)
|
65
|
+
Magick::Image.from_blob(blob_from_url(url)).first
|
66
|
+
end
|
67
|
+
|
53
68
|
def instruction_args(args)
|
54
69
|
args.map do |arg|
|
55
70
|
if arg.is_a?(Symbol)
|
56
71
|
"Magick::#{arg.to_s.classify}".constantize
|
57
72
|
elsif arg.respond_to?(:match) && arg.match(/^http/)
|
58
|
-
|
73
|
+
magick_image_from_url(arg)
|
59
74
|
else
|
60
75
|
arg
|
61
76
|
end
|
data/spec/ungulate/job_spec.rb
CHANGED
@@ -156,6 +156,7 @@ module Ungulate
|
|
156
156
|
before do
|
157
157
|
Curl::Easy.stub(:http_get).and_return(curl_easy)
|
158
158
|
Magick::Image.stub(:from_blob).and_return([overlay])
|
159
|
+
source_image.stub(:composite).and_return(processed_image_1)
|
159
160
|
end
|
160
161
|
|
161
162
|
context "when an argument is a URL" do
|
@@ -169,6 +170,19 @@ module Ungulate
|
|
169
170
|
subject.image_from_instruction(source_image, instruction).
|
170
171
|
should == processed_image_1
|
171
172
|
end
|
173
|
+
|
174
|
+
it "caches the image blob in a hash for later reuse" do
|
175
|
+
subject.image_from_instruction(source_image, instruction)
|
176
|
+
Ungulate::Job.blobs_from_urls[url].should == 'blob'
|
177
|
+
end
|
178
|
+
|
179
|
+
context "image is already cached" do
|
180
|
+
it "reuses the cached image" do
|
181
|
+
subject.class.blobs_from_urls[url] = 'cachedblob'
|
182
|
+
Magick::Image.should_receive(:from_blob).with('cachedblob').and_return([overlay])
|
183
|
+
subject.image_from_instruction(source_image, instruction)
|
184
|
+
end
|
185
|
+
end
|
172
186
|
end
|
173
187
|
|
174
188
|
context "when argument isn't a valid http URL" do
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ungulate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 4
|
10
|
+
version: 0.1.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Andrew Bruce
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-09-
|
18
|
+
date: 2011-09-19 00:00:00 +01:00
|
19
19
|
default_executable: ungulate_server.rb
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|