Sha256: 0b5b5a5b631e6df98037b8e55db8a6a3db48b0e55ce744cc256658448c39e91e

Contents?: true

Size: 1.28 KB

Versions: 34

Compression:

Stored size: 1.28 KB

Contents

require "forwardable"

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

    extend Forwardable
    delegate [:foreground, :background, :handle_interrupt] => :idle_job

    # 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

34 entries across 34 versions & 8 rubygems

Version Path
guard-2.19.0 lib/guard/interactor.rb
honeybadger-5.4.0 vendor/bundle/ruby/3.2.0/gems/guard-2.18.1/lib/guard/interactor.rb
honeybadger-5.3.0 vendor/bundle/ruby/3.2.0/gems/guard-2.18.1/lib/guard/interactor.rb
guard-2.18.1 lib/guard/interactor.rb
op_connect-0.1.2 vendor/bundle/ruby/3.1.0/gems/guard-2.18.0/lib/guard/interactor.rb
guard-2.18.0 lib/guard/interactor.rb
guard-2.17.0 lib/guard/interactor.rb
qiita_org-0.1.35 gems/ruby/2.7.0/gems/guard-2.16.2/lib/guard/interactor.rb
qiita_org-0.1.34 gems/ruby/2.7.0/gems/guard-2.16.2/lib/guard/interactor.rb
qiita_org-0.1.33 gems/ruby/2.7.0/gems/guard-2.16.2/lib/guard/interactor.rb
qiita_org-0.1.32 gems/ruby/2.7.0/gems/guard-2.16.2/lib/guard/interactor.rb
qiita_org-0.1.31 gems/ruby/2.7.0/gems/guard-2.16.2/lib/guard/interactor.rb
qiita_org-0.1.30 gems/ruby/2.7.0/gems/guard-2.16.2/lib/guard/interactor.rb
qiita_org-0.1.29 gems/ruby/2.7.0/gems/guard-2.16.2/lib/guard/interactor.rb
qiita_org-0.1.28 gems/ruby/2.7.0/gems/guard-2.16.2/lib/guard/interactor.rb
qiita_org-0.1.27 gems/ruby/2.7.0/gems/guard-2.16.2/lib/guard/interactor.rb
qiita_org-0.1.26 gems/ruby/2.7.0/gems/guard-2.16.2/lib/guard/interactor.rb
qiita_org-0.1.25 gems/ruby/2.7.0/gems/guard-2.16.2/lib/guard/interactor.rb
guard-2.16.2 lib/guard/interactor.rb
honeybadger-4.5.3 vendor/bundle/ruby/2.6.0/gems/guard-2.15.0/lib/guard/interactor.rb