Sha256: 74dd84759efa625bd3340a466a5ca84ae42e7b31a3547affd958dacb5452be00

Contents?: true

Size: 1.45 KB

Versions: 21

Compression:

Stored size: 1.45 KB

Contents

module Guard
  class Interactor
    # Initializes the interactor. This configures
    # Pry and creates some custom commands and aliases
    # for Guard.
    #
    def initialize(no_interaction = false)
      @interactive = !no_interaction && self.class.enabled?

      # TODO: only require the one used
      require "guard/jobs/sleep"
      require "guard/jobs/pry_wrapper"

      job_klass = interactive? ? Jobs::PryWrapper : Jobs::Sleep
      @idle_job = job_klass.new(self.class.options)
    end

    def interactive?
      @interactive
    end

    # Run in foreground and wait until interrupted or closed
    def foreground
      idle_job.foreground
    end

    # Remove interactor so other tasks can run in foreground
    def background
      idle_job.background
    end

    def handle_interrupt
      idle_job.handle_interrupt
    end

    # TODO: everything below is just so the DSL can set options
    # before setup() is called, which makes it useless for when
    # Guardfile is reevaluated
    class << self
      def options
        @options ||= {}
      end

      # Pass options to interactor's job when it's created
      attr_writer :options

      # TODO: allow custom user idle jobs, e.g. [:pry, :sleep, :exit, ...]
      def enabled?
        @enabled || @enabled.nil?
      end

      alias_method :enabled, :enabled?

      # TODO: handle switching interactors during runtime?
      attr_writer :enabled
    end

    private

    attr_reader :idle_job
  end
end

Version data entries

21 entries across 21 versions & 3 rubygems

Version Path
mastermind_adeybee-0.1.4 vendor/bundle/ruby/2.2.0/gems/guard-2.13.0/lib/guard/interactor.rb
mastermind_adeybee-0.1.3 vendor/bundle/ruby/2.2.0/gems/guard-2.13.0/lib/guard/interactor.rb
mastermind_adeybee-0.1.2 vendor/bundle/ruby/2.2.0/gems/guard-2.13.0/lib/guard/interactor.rb
mastermind_adeybee-0.1.1 vendor/bundle/ruby/2.2.0/gems/guard-2.13.0/lib/guard/interactor.rb
geminfo-0.1.0 path/gems/guard-2.13.0/lib/guard/interactor.rb
guard-2.13.0 lib/guard/interactor.rb
guard-2.12.9 lib/guard/interactor.rb
guard-2.12.8 lib/guard/interactor.rb
guard-2.12.7 lib/guard/interactor.rb
guard-2.12.6 lib/guard/interactor.rb
guard-2.12.5 lib/guard/interactor.rb
guard-2.12.4 lib/guard/interactor.rb
guard-2.12.3 lib/guard/interactor.rb
guard-2.12.2 lib/guard/interactor.rb
guard-2.12.1 lib/guard/interactor.rb
guard-2.12.0 lib/guard/interactor.rb
guard-2.11.1 lib/guard/interactor.rb
guard-2.11.0 lib/guard/interactor.rb
guard-2.10.5 lib/guard/interactor.rb
guard-2.10.4 lib/guard/interactor.rb