Sha256: 40b609e5208a9bc1132595605aedb9af575185cecfd57760b0c247440725a4c3

Contents?: true

Size: 1013 Bytes

Versions: 4

Compression:

Stored size: 1013 Bytes

Contents

class MPlayer
  class Callback # :nodoc:all
    def initialize(callback_options)
      @block = callback_options[:block]
      @type  = callback_options[:type]
      @scope = callback_options[:scope]
    end
    
    def run!(args)
      unless @block.nil?
        case @type
        when :instance then @block.call(*args)
        when :class    then @scope.instance_exec(*args, &@block)
        end
      end
    end
  end
  
  class CallbackList < Array # :nodoc:all
    attr_reader :name
    
    def initialize(list_name)
      @name = list_name.to_sym
    end

    def register(opts)
      push Callback.new(opts)
    end

    def run!(args)
      each do |x|
        x.run!(args)
      end
    end

    class << self
      def all
        @all ||= Hash.new
      end
      
      def find(name)
        all[name.to_sym] ||= new(name)
      end

      def register(opts)
        find(opts[:name]).register(opts)
      end

      def run!(name, args)
        find(name).run!(args)
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
easy_mplayer-1.2.1 lib/easy_mplayer/callback.rb
easy_mplayer-1.2.0 lib/easy_mplayer/callback.rb
easy_mplayer-1.1.0 lib/easy_mplayer/callback.rb
easy_mplayer-1.0.0 lib/easy_mplayer/callback.rb