Sha256: 073440c1b769ce092a36c50dd8235a68b763c6509f71f4790cd6601de480c657

Contents?: true

Size: 1.12 KB

Versions: 1

Compression:

Stored size: 1.12 KB

Contents

require 'sysexits'
require 'usaidwat/client'
require 'usaidwat/pager'

require 'timecop' if ENV['USAIDWAT_ENV'] == 'cucumber'

module USaidWat
  module Application
    class Command
      include Pager
      include Sysexits

      attr_reader :client

      class << self
        def subclasses
          @subclasses ||= []
        end

        def inherited(base)
          subclasses << base
          super
        end
      end

      def initialize(prog)
        @client = cucumber? ? USaidWat::Client::TestRedditor : USaidWat::Client::Redditor
        Timecop.freeze(Time.parse(ENV['USAIDWAT_CURRENT_TIME'])) if cucumber_time?
      end

      def quit(message, code=:ok)
        stream = code == :ok ? $stdout : $stderr
        stream.puts message
        exit code
      end

      protected

      def dispatch_process(process, method, arg)
        send(process, method, arg)
      rescue ArgumentError => e
        quit e.message, :usage
      end

      def cucumber?
        ENV['USAIDWAT_ENV'] == 'cucumber'
      end

      def cucumber_time?
        cucumber? && !ENV['USAIDWAT_CURRENT_TIME'].nil?
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
usaidwat-1.6.1 lib/usaidwat/command.rb