module SyncWrap::ChangeKeyListener

Support module for components which listen for and act on changes set on SyncWrap::Context#state keys.

Attributes

change_key[RW]

An optional state key, or array of state keys, to check for changes. (Default: nil; Example: :source_tree)

Public Class Methods

new( opts = {} ) click to toggle source
Calls superclass method
# File lib/syncwrap/change_key_listener.rb, line 25
def initialize( opts = {} )
  @change_key = nil
  super
end

Protected Instance Methods

change_key_changes() click to toggle source

Returns the combined array of all changes on all change_key.

# File lib/syncwrap/change_key_listener.rb, line 43
def change_key_changes
  Array( change_key ).inject( [] ) do |m,k|
    c = state[ k ]
    if c
      m + c
    else
      m
    end
  end
end
change_key_changes?() click to toggle source

Returns true if there are any changes with any change_key.

# File lib/syncwrap/change_key_listener.rb, line 35
def change_key_changes?
  Array( change_key ).any? do |k|
    c = state[ k ]
    c && !c.empty?
  end
end