Sha256: 25fea6442fefd60106d5cc799e5ced08761923061ce88ec6f10db82bcdaf0487

Contents?: true

Size: 1.49 KB

Versions: 1

Compression:

Stored size: 1.49 KB

Contents

$LOAD_PATH << File.expand_path(File.dirname(__FILE__) + '/../lib')

require_relative 'troo/troo'
require_relative 'troo/version'

module Troo
  InvalidAccessToken = Class.new(StandardError)
  EndpointNotFound   = Class.new(StandardError)

  def self.configuration(file = Dir.home + '/.trooconf', env = :default)
    @configuration ||= Troo::Configuration.load(file, env)
  end
  configuration

  def self.endpoints(version = :version_1)
    @endpoints ||= Troo::API::Endpoints
      .load(File.dirname(__FILE__) + '/../config/trello_api.yml', version)
  end
  endpoints

  def self.logger
    @logger ||= Logger
      .new(File.dirname(__FILE__) + '/../logs/troo.log').tap do |log|
      log.formatter = proc do |mode, time, prog, msg|
        "#{time.iso8601} #{mode}:\n#{msg}\n\n"
      end
    end
  end

  # RestClient.log = File.dirname(__FILE__) + '/../logs/restclient.log'

  Ohm.connect(db: Troo.configuration.database)

  class Launcher
    def initialize(argv, stdin = STDIN,
                         stdout = STDOUT,
                         stderr = STDERR,
                         kernel = Kernel)
      @argv = argv
      @stdin = stdin
      @stdout = stdout
      @stderr = stderr
      @kernel = kernel
    end

    def execute!
      $stdin, $stdout, $stderr = @stdin, @stdout, @stderr
      pad { Troo::CLI::Main.start(@argv) }
      @kernel.exit(0)
    ensure
      $stdin, $stdout, $stderr = STDIN, STDOUT, STDERR
    end

    private

    def pad
      puts
      yield
      puts
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
troo-0.0.9 lib/troo.rb