Class: OmfEc::Context::GroupContext
- Inherits:
-
Object
- Object
- OmfEc::Context::GroupContext
- Defined in:
- lib/omf_ec/context/group_context.rb
Overview
Holds group configuration
Instance Attribute Summary collapse
-
#group ⇒ Object
Returns the value of attribute group.
-
#guard ⇒ Object
Returns the value of attribute guard.
-
#operation ⇒ Object
Returns the value of attribute operation.
Instance Method Summary collapse
-
#[](opts = {}) ⇒ Object
Supports OEDL 6 syntax [] for setting FRCP guard.
-
#initialize(opts) ⇒ GroupContext
constructor
A new instance of GroupContext.
-
#method_missing(name, *args, &block) ⇒ Object
Calling standard methods or assignments will simply trigger sending a FRCP message.
-
#send_message(name, value = nil, &block) ⇒ Object
Send FRCP message.
Constructor Details
#initialize(opts) ⇒ GroupContext
Returns a new instance of GroupContext.
13 14 15 16 17 |
# File 'lib/omf_ec/context/group_context.rb', line 13 def initialize(opts) self.group = opts.delete(:group) self.guard = opts self end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
Calling standard methods or assignments will simply trigger sending a FRCP message
45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/omf_ec/context/group_context.rb', line 45 def method_missing(name, *args, &block) if name =~ /(.+)=/ self.operation = :configure name = $1 elsif name =~ /release/ self.operation = :release else self.operation = :request end (name, *args, &block) end |
Instance Attribute Details
#group ⇒ Object
Returns the value of attribute group.
9 10 11 |
# File 'lib/omf_ec/context/group_context.rb', line 9 def group @group end |
#guard ⇒ Object
Returns the value of attribute guard.
10 11 12 |
# File 'lib/omf_ec/context/group_context.rb', line 10 def guard @guard end |
#operation ⇒ Object
Returns the value of attribute operation.
11 12 13 |
# File 'lib/omf_ec/context/group_context.rb', line 11 def operation @operation end |
Instance Method Details
#[](opts = {}) ⇒ Object
Supports OEDL 6 syntax [] for setting FRCP guard
29 30 31 32 |
# File 'lib/omf_ec/context/group_context.rb', line 29 def [](opts = {}) self.guard.merge!(opts) self end |
#send_message(name, value = nil, &block) ⇒ Object
Send FRCP message
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/omf_ec/context/group_context.rb', line 61 def (name, value = nil, &block) if self.guard[:type] topic = self.group.resource_topic(self.guard[:type]) else topic = self.group.topic end if topic.nil? if self.guard[:type] warn "Group '#{self.group.name}' has NO resources of type '#{self.guard[:type]}' ready. Could not send message." else warn "Group topic '#{self.group.name}' NOT subscribed. Could not send message." end return end case self.operation when :configure topic.configure({ name => value }, { guard: self.guard }) when :request topic.request([:uid, :hrn, name], { guard: self.guard }) when :release topics_to_release = OmfEc.experiment.state.find_all do |res_state| all_equal(self.guard.keys) do |k| res_state[k] == self.guard[k] end end topics_to_release.each do |res_state| OmfEc.subscribe_and_monitor(res_state.uid) do |child_topic| OmfEc.subscribe_and_monitor(self.group.id) do |group_topic| group_topic.release(child_topic) if child_topic end end end end end |