Class: Fluke::Result

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/fluke/result.rb

Defined Under Namespace

Classes: Body

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.from_response(args) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/fluke/result.rb', line 28

def self.from_response(args)
  opts = {
    :mime_type => 'binary/octet-stream',
    :generated_url => nil
  }.merge(args)

  checksum = Digest::SHA1.hexdigest(opts[:content])
  result = Result.new :checksum => checksum
  result.watcher = opts[:watcher]
  if opts[:generated_url] and opts[:generated_url] != opts[:watcher].url
    result.url = opts[:generated_url]
  end
  result.save

  Thread.new do
    if result.body?
      Fluke.log { "#{result.watcher} exists: #{result.body_key}" }
    else
      Fluke.log { "#{result.watcher} store: #{result.body_key}" }
      Body.store(result.body_key, opts[:content].dup, :content_type => opts[:mime_type])
    end
  end

  result
end

Instance Method Details

#bodyObject



16
17
18
19
20
21
22
# File 'lib/fluke/result.rb', line 16

def body
  begin
    return Body.find self.body_key
  rescue AWS::S3::NoSuchKey => nsk
    return nil
  end
end

#body?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/fluke/result.rb', line 24

def body?
  Body.exists? self.body_key
end

#body_keyObject



12
13
14
# File 'lib/fluke/result.rb', line 12

def body_key
  "#{self.watcher.name}/#{self.checksum}"
end

#diff_against(right) ⇒ Object



54
55
56
# File 'lib/fluke/result.rb', line 54

def diff_against(right)
  differ = Differ.(self.body.value, right.body.value)
end