Sha256: 3ad9f7f51c06d9732e08e31814208744236f5f6af94d0d8222cc8d88969d2f40

Contents?: true

Size: 713 Bytes

Versions: 6

Compression:

Stored size: 713 Bytes

Contents

module PM

# A Trigger performs an action when it sees a particular array of bytes.
# Instruments have zero or more triggers. The action is a symbol that gets
# sent to PM::PatchMaster.
#
# Since we want to save them to files, we store the text representation as
# well.
class Trigger

  attr_accessor :bytes, :block, :text

  def initialize(bytes, block)
    @bytes, @block = bytes, block
  end

  def method_missing(sym, *args)
    PM::PatchMaster.instance.send(sym, *args)
  end

  # If +bytes+ matches our +@bytes+ array then run +@block+.
  def signal(bytes)
    if bytes == @bytes
      block.call
    end
  end

  def to_s
    "#{@bytes.inspect} => #{@text ? @text.gsub(/\n\s*/, '; ') : ''}"
  end
end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
patchmaster-0.0.6 lib/patchmaster/trigger.rb
patchmaster-0.0.5 lib/patchmaster/trigger.rb
patchmaster-0.0.4 lib/patchmaster/trigger.rb
patchmaster-0.0.3 lib/patchmaster/trigger.rb
patchmaster-0.0.2 lib/patchmaster/trigger.rb
patchmaster-0.0.1 lib/patchmaster/trigger.rb