Sha256: a2ebd4fee5ba2e657fb68fc6c7660110470ee93cfd006d8c48dc8a28be1358a3

Contents?: true

Size: 869 Bytes

Versions: 13

Compression:

Stored size: 869 Bytes

Contents

# -*- coding: utf-8 -*-


require 'ostruct'


module Xot


  module Invoker

    def initialize ()
    end

    def handlers (create = false)
      if create
        @handlers ||= []
      else
        @handlers ? @handlers : []
      end
    end

    def add_handler (handler)
      return unless handler
      a = self.handlers true
      a.push handler unless a.include? handler
    end

    def remove_handler (handler)
      return unless handler
      self.handlers.delete handler
    end

    def invoke (name, attributes = {}, options = {})
      only     = options[:only]
      only     = [only] if only && !only.kind_of?(Array)
      handlers = only ? only : @handlers
      return unless handlers

      handlers.each do |handler|
        handler.send name, OpenStruct.new(attributes) if handler.respond_to? name
      end
    end

  end# Invoker


end# Xot

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
xot-0.1.21 lib/xot/invoker.rb
xot-0.1.20 lib/xot/invoker.rb
xot-0.1.19 lib/xot/invoker.rb
xot-0.1.16 lib/xot/invoker.rb
xot-0.1.15 lib/xot/invoker.rb
xot-0.1.14 lib/xot/invoker.rb
xot-0.1.13 lib/xot/invoker.rb
xot-0.1.12 lib/xot/invoker.rb
xot-0.1.11 lib/xot/invoker.rb
xot-0.1.10 lib/xot/invoker.rb
xot-0.1.9 lib/xot/invoker.rb
xot-0.1.8 lib/xot/invoker.rb
xot-0.1.7 lib/xot/invoker.rb