Class: Hushed::Blackboard
- Inherits:
-
Object
- Object
- Hushed::Blackboard
- Defined in:
- lib/hushed/blackboard.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Instance Method Summary collapse
- #build_document(type, contents) ⇒ Object
- #fetch(message) ⇒ Object
-
#initialize(client) ⇒ Blackboard
constructor
A new instance of Blackboard.
- #post(document) ⇒ Object
- #remove(message) ⇒ Object
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
#client ⇒ Object (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() bucket = client.from_quiet_bucket contents = bucket.objects[.document_name].read build_document(.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() bucket = client.from_quiet_bucket object = bucket.objects[.document_name] if object.exists? object.delete true else false end end |