Class: BindAction
- Defined in:
- lib/MINT-core/mapping/action/bind_action.rb
Instance Method Summary collapse
- #attrIn ⇒ Object
- #attrOut ⇒ Object
- #channelIn ⇒ Object
- #channelOut ⇒ Object
- #elementIn ⇒ Object
- #elementOut ⇒ Object
- #identifier ⇒ Object
-
#initialize(params) ⇒ BindAction
constructor
A new instance of BindAction.
- #initiated_callback(cb) ⇒ Object
- #nameIn ⇒ Object
- #nameOut ⇒ Object
-
#start(observation_results) ⇒ Object
TODO handle observation_variables.
- #unbind ⇒ Object
Methods inherited from Action
Constructor Details
#initialize(params) ⇒ BindAction
Returns a new instance of BindAction.
4 5 6 7 8 9 |
# File 'lib/MINT-core/mapping/action/bind_action.rb', line 4 def initialize(params) super() @action = params @cb_observation_has_subscribed=nil @is_bound = false end |
Instance Method Details
#attrIn ⇒ Object
37 38 39 |
# File 'lib/MINT-core/mapping/action/bind_action.rb', line 37 def attrIn @action[:attrIn] end |
#attrOut ⇒ Object
41 42 43 |
# File 'lib/MINT-core/mapping/action/bind_action.rb', line 41 def attrOut @action[:attrOut] end |
#channelIn ⇒ Object
45 46 47 |
# File 'lib/MINT-core/mapping/action/bind_action.rb', line 45 def channelIn "#{attrIn}:#{elementIn}.#{nameIn}" end |
#channelOut ⇒ Object
49 50 51 |
# File 'lib/MINT-core/mapping/action/bind_action.rb', line 49 def channelOut "#{attrOut}:#{elementOut}.#{nameOut}" end |
#elementIn ⇒ Object
17 18 19 |
# File 'lib/MINT-core/mapping/action/bind_action.rb', line 17 def elementIn @action[:elementIn] end |
#elementOut ⇒ Object
21 22 23 |
# File 'lib/MINT-core/mapping/action/bind_action.rb', line 21 def elementOut @action[:elementOut] end |
#identifier ⇒ Object
25 26 27 |
# File 'lib/MINT-core/mapping/action/bind_action.rb', line 25 def identifier elementIn end |
#initiated_callback(cb) ⇒ Object
11 12 13 |
# File 'lib/MINT-core/mapping/action/bind_action.rb', line 11 def initiated_callback(cb) @cb_observation_has_subscribed = cb end |
#nameIn ⇒ Object
29 30 31 |
# File 'lib/MINT-core/mapping/action/bind_action.rb', line 29 def nameIn @action[:nameIn] end |
#nameOut ⇒ Object
33 34 35 |
# File 'lib/MINT-core/mapping/action/bind_action.rb', line 33 def nameOut @action[:nameOut] end |
#start(observation_results) ⇒ Object
TODO handle observation_variables
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/MINT-core/mapping/action/bind_action.rb', line 54 def start(observation_results) # TODO handle observation_variables @result = false if @is_bound @cb_observation_has_subscribed.call(elementIn) if @cb_observation_has_subscribed return self end redis = RedisConnector.redis redis.pubsub.subscribe(channelIn) { || found=MultiJson.decode if nameIn.eql? found['name'] if found.has_key? @action[:attrIn] result = found[@action[:attrIn]] result = @action[:transform].call result if @action[:transform] redis.publish channelOut, MultiJson.encode({:name=>@action[:nameOut], @action[:attrOut] => result}) end end }.callback do @is_bound = true @cb_observation_has_subscribed.call(elementIn) if @cb_observation_has_subscribed end @result = true self end |
#unbind ⇒ Object
85 86 87 |
# File 'lib/MINT-core/mapping/action/bind_action.rb', line 85 def unbind RedisConnector.sub.unsubscribe(@action[:in]) end |