Class: Hushed::Blackboard

Inherits:
Object
  • Object
show all
Defined in:
lib/hushed/blackboard.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Blackboard

Returns a new instance of Blackboard.



7
8
9
# File 'lib/hushed/blackboard.rb', line 7

def initialize(client)
  @client = client
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



5
6
7
# File 'lib/hushed/blackboard.rb', line 5

def client
  @client
end

Instance Method Details

#build_document(type, contents) ⇒ Object



35
36
37
38
39
40
41
42
# File 'lib/hushed/blackboard.rb', line 35

def build_document(type, contents)
  namespace = if Response.valid_type?(type)
    Documents::Response
  elsif Request.valid_type?(type)
    Documents::Request
  end
  namespace.const_get(type).new(:io => contents) if namespace
end

#fetch(message) ⇒ Object



18
19
20
21
22
# File 'lib/hushed/blackboard.rb', line 18

def fetch(message)
  bucket = client.from_quiet_bucket
  contents = bucket.objects[message.document_name].read
  build_document(message.document_type, contents)
end

#post(document) ⇒ Object



11
12
13
14
15
16
# File 'lib/hushed/blackboard.rb', line 11

def post(document)
  bucket = client.to_quiet_bucket
  if bucket.objects[document.filename].write(document.to_xml)
    Message.new(:client => @client, :document => document)
  end
end

#remove(message) ⇒ Object



24
25
26
27
28
29
30
31
32
33
# File 'lib/hushed/blackboard.rb', line 24

def remove(message)
  bucket = client.from_quiet_bucket
  object = bucket.objects[message.document_name]
  if object.exists?
    object.delete
    true
  else
    false
  end
end