Sha256: 2911e335d1a25a5a15872c5bf451b4d6f29259a508f5e408283b39bb6ad662a8

Contents?: true

Size: 963 Bytes

Versions: 1

Compression:

Stored size: 963 Bytes

Contents

module Main
  class Proxy
    instance_methods.each{|m| undef_method m unless m[%r/__/]}

    attribute 'main'

    def initialize main
      @main = main
    end

    def as_main &b
      @main.instance_eval &b
    end

    def run 
      as_main do
        parse_parameters

        if params['help'] and params['help'].given?
          print usage.to_s
          exit
        end

        pre_run

        begin
          run
        rescue Exception => e
          if SystemExit === e
            exit_status(( e.status ))
          else
            fatal{ e }
            exit_status(( EXIT_FAILURE )) if exit_status == exit_success
          end
        end

        post_run

        finalize

        exit_status(( Integer(exit_status) rescue(exit_status ? 0 : 1) ))
        exit exit_status
      end
    end

    def method_missing m, *a, &b
      if @main.respond_to? m
        @main.send m, *a, &b
      else
        raise
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
main-0.0.2 lib/main/proxy.rb