require File.dirname(__FILE__) + '/base' module Martin # Martin delegation mixin. Mixing this module into an object causes all # methods to be delegated to the Martin::Application class. Used primarily # at the top-level. # 100% ripped from Sinatra::Delegator module Delegator #:nodoc: def self.delegate(*methods) methods.each do |method_name| eval <<-RUBY, binding, '(__DELEGATE__)', 1 def #{method_name}(*args, &b) ::Martin::Application.send(#{method_name.inspect}, *args, &b) end private #{method_name.inspect} RUBY end end delegate :configure, :command, :error, :run end # This is the class that gets loaded if you just require 'martin' class Application < Base error do |input| puts 'Could not find method ' + input.split.first end end at_exit { Application.run } end include Martin::Delegator