Class: Waves::Blackboard
Overview
Encapsulates the blackboard associated with a given request. The scope of the blackboard is the same as the request object it gets attached to.
The Waves blackboard is a very simple shared storaged usable during the request processing. It is available within:
- mappings
- controllers
- helpers
Adding a value:
blackboard.value1 = 1
blackboard[:value2] = 2
Retrieving values
blackboard.value1
blackboard[:value2]
see also blackboard_verify.rb
Instance Method Summary collapse
-
#[](key) ⇒ Object
Access a given data element of the blackboard using the given key.
-
#[]=(key, val) ⇒ Object
Set the given data element of the blackboard using the given key and value.
- #each(&block) ⇒ Object
-
#initialize(request) ⇒ Blackboard
constructor
Create a new blackboard object using the given request.
-
#method_missing(name, *args) ⇒ Object
also allow things like blackboard.test1 instead of blackboard blackboard.test1 = 2 instead of blackboard = 2.
Constructor Details
#initialize(request) ⇒ Blackboard
Create a new blackboard object using the given request.
25 26 27 28 |
# File 'lib/runtime/blackboard.rb', line 25 def initialize( request ) @request = request @data = {} end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
also allow things like blackboard.test1 instead of blackboard blackboard.test1 = 2 instead of blackboard = 2
47 48 49 50 51 52 53 |
# File 'lib/runtime/blackboard.rb', line 47 def method_missing(name,*args) if (name.to_s =~ /=$/) self[name.to_s.gsub('=', '')] = args[0] else self[name.to_s] end end |
Instance Method Details
#[](key) ⇒ Object
Access a given data element of the blackboard using the given key.
31 32 33 |
# File 'lib/runtime/blackboard.rb', line 31 def [](key) @data[key] end |
#[]=(key, val) ⇒ Object
Set the given data element of the blackboard using the given key and value.
36 37 38 |
# File 'lib/runtime/blackboard.rb', line 36 def []=(key,val) @data[key] = val end |
#each(&block) ⇒ Object
40 41 42 |
# File 'lib/runtime/blackboard.rb', line 40 def each(&block) @data.each(&block) end |