lib/plugins/plugin.rb in rsence-pre-2.1.0.10 vs lib/plugins/plugin.rb in rsence-pre-2.1.0.11

- old
+ new

@@ -342,23 +342,75 @@ default_value = 0 end name = name_with_manager_s ses[value_name] = HValue.new( msg, default_value, { :name => "#{name}.#{value_name}" } ) if value_properties.has_key?(:responders) - value_properties[:responders].each do |responder| - if responder.has_key?(:plugin) - responder_plugin = responder[:plugin] - else - responder_plugin = name + init_responders( msg, ses[value_name], value_properties[:responders] ) + end + end + + # @private Initialize a responder for a value. + def init_responder( msg, value, responder ) + name = name_with_manager_s + if responder.has_key?(:plugin) + responder_plugin = responder[:plugin] + else + responder_plugin = name + end + if responder.has_key?(:method) + responder_method = responder[:method] + if not value.bound?( responder_plugin, responder_method ) + value.bind( responder_plugin, responder[:method] ) + end + end + end + + # @private Initialize several responders for a value + def init_responders( msg, value, responders ) + members = value.members + release_list = [] + members.each_key do |pre_plugin| + members[pre_plugin].each do |pre_method| + found = false + responders.each do |responder| + name = name_with_manager_s + if responder.has_key?(:plugin) + responder_plugin = responder[:plugin] + else + responder_plugin = name + end + if responder.has_key?(:method) + responder_method = responder[:method] + if responder_plugin == pre_plugin and responder_method == pre_method + found = true + break + end + end end - if responder.has_key?(:method) - ses[value_name].bind( responder_plugin, responder[:method] ) + unless found + release_list.push( [ pre_plugin, pre_method ] ) end end end + release_list.each do | rel_plugin, rel_method | + value.release( rel_plugin, rel_method ) + end + responders.each do |responder| + init_responder( msg, value, responder ) + end end + # @private Releases all responders of a value + def release_responders( msg, value ) + members = value.members + members.each_key do |responder_plugin| + members.each do |responder_method| + value.release( responder_plugin, responder_method ) + end + end + end + # @private Initializes session values, if the contents of the +values.yaml+ # file is defined in the bundle directory and loaded in +#init_values+. def init_ses_values( msg ) return unless @values @values.each do | value_name, value_properties | @@ -424,9 +476,14 @@ def restore_ses_values( msg ) return unless @values ses = get_ses( msg ) @values.each do | value_name, value_properties | if ses.has_key?( value_name ) and ses[ value_name ].class == HValue + if value_properties.has_key?(:responders) + init_responders( msg, ses[value_name], value_properties[:responders] ) + else + release_responders( msg, ses[value_name] ) + end unless value_properties[:restore_default] == false if value_properties.has_key?(:value_call) default_value = init_value_call( msg, value_properties[:value_call] ) elsif value_properties.has_key?(:value) default_value = value_properties[:value]