### Home Classes Methods

### In Files

- lib/termtter/hookable.rb

### Methods

- ::call_hooks
- ::clear_hooks
- ::get_hook
- ::get_hooks
- ::included
- ::register_hook
- ::remove_hook

### Files

- ChangeLog
- README.rdoc

### Class/Module Index

Quicksearch

- Termtter
- Termtter::API
- Termtter::ActiveRubytter
- Termtter::Client
- Termtter::Client::DirectMessage
- Termtter::Client::Jakigan
- Termtter::Client::SearchEvent
- Termtter::Client::UserSearchEvent
- Termtter::Command
- Termtter::CommandCanceled
- Termtter::CommandLine
- Termtter::CommandNotFound
- Termtter::Config
- Termtter::ConfigSetup
- Termtter::Crypt
- Termtter::English
- Termtter::Event
- Termtter::HTTPpool
- Termtter::Hook
- Termtter::HookCanceled
- Termtter::Hookable
- Termtter::JSONError
- Termtter::MemoryCache
- Termtter::MemoryCache::MemCacheMock
- Termtter::OptParser
- Termtter::Plugin
- Termtter::Plugin::Screen
- Termtter::Plugins
- Termtter::Plugins::Haml
- Termtter::Plugins::ListSwitch
- Termtter::RubytterProxy
- Termtter::RubytterProxy::FrequentAccessError
- Termtter::RubytterProxy::LimitManager
- Termtter::Status
- Termtter::StdOut
- Termtter::Storage
- Termtter::Storage::SQLite3
- Termtter::Storage::Status
- Termtter::Task
- Termtter::TaskManager
- Termtter::TypableIdGenerator
- Termtter::UserStreamReceiver
- Yharian
- Yharian::Alex
- Yharian::Jenifer
- Yharian::Remark
- Yharian::Speaker
- Yharian::Vicki
- Yharian::Yhara
- HatenaKeywordHaiku
- HatenaKeywordHaiku::Word
- OAuth
- OAuth::AccessToken
- Readline
- Readline::LIBREADLINE
- AAMaker
- Array
- BrowserNotFound
- Growl
- IRB
- Object
- Status
- String
- Symbol
- TermColor
- TermtterIrcGateway
- User

No matching classes.

# Termtter::Hookable

### Attributes

hooks[R]

### Public Class Methods

call_hooks(point, *args) click to toggle source

return last hook return value

    # File lib/termtter/hookable.rb, line 52
    def call_hooks(point, *args)
      Termtter::Client.logger.debug { "call_hooks: [:point => #{point}, :args => [#{args.map {|a| a.inspect.each_char.take(11).join}.join(', ')}]]" }
      result = nil
      get_hooks(point).each {|hook|
        break if result == false # interrupt if hook return false
        Termtter::Client.logger.debug { "call_hooks: #{point} #{hook.inspect}" }
        result = hook.call(*args)
      }
      Termtter::Client.logger.debug { "call_hooks: [:point => #{point}, :args => [#{args.map {|a| a.inspect.each_char.take(11).join}.join(', ')}]], done" }
      result
    end

clear_hooks() click to toggle source

    # File lib/termtter/hookable.rb, line 64
    def clear_hooks
      hooks.clear
    end

get_hook(name) click to toggle source

    # File lib/termtter/hookable.rb, line 40
    def get_hook(name)
      hooks[name]
    end

get_hooks(point) click to toggle source

    # File lib/termtter/hookable.rb, line 44
    def get_hooks(point)
      # TODO: sort by alphabet
      hooks.values.select do |hook|
        hook.match?(point)
      end
    end

included(base) click to toggle source

    # File lib/termtter/hookable.rb, line 12
    def self.included(base)
      base.class_eval do
        @hooks = {}

        class << self
          attr_reader :hooks

          def register_hook(arg, opts = {}, &block)
            hook = case arg
              when Hook
                arg
              when Hash
                Hook.new(arg)
              when String, Symbol
                options = { :name => arg }
                options.merge!(opts)
                options[:exec_proc] = block
                Hook.new(options)
              else
                raise ArgumentError, 'must be given Termtter::Hook, Hash, String or Symbol'
              end
            hooks[hook.name] = hook
          end

          def remove_hook(name)
            hooks.delete(name.to_sym)
          end

          def get_hook(name)
            hooks[name]
          end

          def get_hooks(point)
            # TODO: sort by alphabet
            hooks.values.select do |hook|
              hook.match?(point)
            end
          end

          # return last hook return value
          def call_hooks(point, *args)
            Termtter::Client.logger.debug { "call_hooks: [:point => #{point}, :args => [#{args.map {|a| a.inspect.each_char.take(11).join}.join(', ')}]]" }
            result = nil
            get_hooks(point).each {|hook|
              break if result == false # interrupt if hook return false
              Termtter::Client.logger.debug { "call_hooks: #{point} #{hook.inspect}" }
              result = hook.call(*args)
            }
            Termtter::Client.logger.debug { "call_hooks: [:point => #{point}, :args => [#{args.map {|a| a.inspect.each_char.take(11).join}.join(', ')}]], done" }
            result
          end

          def clear_hooks
            hooks.clear
          end
        end
      end
    end

register_hook(arg, opts = {}, &block) click to toggle source

    # File lib/termtter/hookable.rb, line 19
    def register_hook(arg, opts = {}, &block)
      hook = case arg
        when Hook
          arg
        when Hash
          Hook.new(arg)
        when String, Symbol
          options = { :name => arg }
          options.merge!(opts)
          options[:exec_proc] = block
          Hook.new(options)
        else
          raise ArgumentError, 'must be given Termtter::Hook, Hash, String or Symbol'
        end
      hooks[hook.name] = hook
    end

remove_hook(name) click to toggle source

    # File lib/termtter/hookable.rb, line 36
    def remove_hook(name)
      hooks.delete(name.to_sym)
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.