Sha256: 055d5ac0123f9d2b527e3dc4ce2d6243f7041972e2d18a939104e88a8b18225e

Contents?: true

Size: 729 Bytes

Versions: 1

Compression:

Stored size: 729 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 || '# no block text found').gsub(/\n\s*/, '; ')}"
  end
end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
patchmaster-1.0.0 lib/patchmaster/trigger.rb