Sha256: 52a93c62ae47374bfc4cffbf7fb0e37a8eea2f05d16aeacdf8531bcf5060ebec

Contents?: true

Size: 926 Bytes

Versions: 1

Compression:

Stored size: 926 Bytes

Contents

module Vedeu
  class Application
    class << self
      def start(options = {})
        new(options).start
      end
    end

    def initialize(options = {})
      @options = options || {}
    end

    def start
      Terminal.open(options) do
        Output.render

        runner { main_sequence }
      end
    ensure
      Terminal.close
    end

    private

    attr_reader :options

    def runner
      if interactive?
        interactive { yield }
      else
        run_once    { yield }
      end
    end

    def main_sequence
      Input.capture

      Process.evaluate

      Output.render
    end

    def interactive?
      options.fetch(:interactive)
    end

    def interactive
      loop { yield }
    rescue StopIteration
    end

    def run_once
      yield
    end

    def options
      defaults.merge!(@options)
    end

    def defaults
      {
        interactive: true
      }
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
vedeu-0.0.25 lib/vedeu/application.rb