Class: Fluke::Result

Inherits:
Object
  • Object
show all
Includes:
DataMapper::Resource
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



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/fluke/result.rb', line 37

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

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

  result
end

Instance Method Details

#bodyObject



23
24
25
26
27
28
29
30
31
# File 'lib/fluke/result.rb', line 23

def body
  begin
    return Fluke.mutex[:s3].synchronize do
      Body.find self.body_key
    end
  rescue AWS::S3::NoSuchKey => nsk
    return nil
  end
end

#body?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/fluke/result.rb', line 33

def body?
  Fluke.mutex[:s3].synchronize { Body.exists? self.body_key }
end

#body_keyObject



19
20
21
# File 'lib/fluke/result.rb', line 19

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

#diff_against(right) ⇒ Object



63
64
65
# File 'lib/fluke/result.rb', line 63

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