Sha256: 13aa768ea58923b2aeffd5640b176d7cb8abfbe861e4e6e18fbc9a7ebaf7b354

Contents?: true

Size: 1.14 KB

Versions: 2

Compression:

Stored size: 1.14 KB

Contents

require 'readline'

module Space
  class App
    autoload :Command, 'space/app/command'
    autoload :Handler, 'space/app/handler'
    autoload :Logger,  'space/app/logger'
    autoload :Parser,  'space/app/parser'

    class << self
      def logger
        @logger ||= Logger.new
      end
    end

    include Readline

    attr_reader :name, :project, :screen

    def initialize(name)
      @name    = name
      @project = Models::Project.new(name)
      @screen  = Screen.new(project)

      project.subscribe(screen)
    end

    def run
      refresh
      screen.display(:dashboard)
      cli_loop
    end

    private

      def refresh
        screen.display(:progress)
        project.refresh
      end

      def cli_loop
        loop do
          line = readline(prompt, true)
          break if line.nil?
          handle(line) unless line.empty?
        end
      end

      def handle(line)
        screen.display(:progress)
        Handler.new(project).run(line)
        screen.display(:dashboard)
      end

      def prompt
        "#{project.repos.scoped? ? project.repos.scope.map { |r| r.name }.join(', ') : project.name} > "
      end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
space-0.0.5 lib/space/app.rb
space-0.0.4 lib/space/app.rb