Sha256: 8aec80faecd445cefde1300bbbe6e8131a8bfcb219b14fbe3f06b1d106bec72f

Contents?: true

Size: 1.74 KB

Versions: 19

Compression:

Stored size: 1.74 KB

Contents

module Guard
  module Compat
    module Test
      class Template
        class Session
          class MultipleGuardNotImplemented < NotImplementedError
            def message
              'multiple guards not supported!'
            end
          end

          class GlobalWatchesNotImplemented < NotImplementedError
            def message
              'global watches not supported!'
            end
          end

          def initialize(path, content)
            @watches = {}
            @current = nil
            instance_eval(content, path, 1)
          end

          def match(file)
            _watches.map do |expr, block|
              next unless (match = file.match(expr))
              block.nil? ? [file] : block.call([file] + match.captures)
            end.flatten.compact.uniq
          end

          def guard(name, _options = {})
            @current = name
            @watches[@current] = []
            yield
            @current = nil
          end

          def watch(expr, &block)
            @watches[@current] << [expr, block]
          end

          private

          def _watches
            keys = @watches.keys
            fail ArgumentError, 'no watches!' if keys.empty?
            fail MultipleGuardNotImplemented if keys.size > 1

            key = keys.first
            fail GlobalWatchesNotImplemented if key.nil?
            @watches[key]
          end
        end

        def initialize(plugin_class)
          name = plugin_class.to_s.sub('Guard::', '').downcase
          path = format('lib/guard/%s/templates/Guardfile', name)
          content = File.read(path)
          @session = Session.new(path, content)
        end

        def changed(file)
          @session.match(file)
        end
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 9 rubygems

Version Path
honeybadger-5.4.0 vendor/bundle/ruby/3.2.0/gems/guard-compat-1.2.1/lib/guard/compat/test/template.rb
honeybadger-5.3.0 vendor/bundle/ruby/3.2.0/gems/guard-compat-1.2.1/lib/guard/compat/test/template.rb
op_connect-0.1.2 vendor/bundle/ruby/3.1.0/gems/guard-compat-1.2.1/lib/guard/compat/test/template.rb
honeybadger-4.5.3 vendor/bundle/ruby/2.6.0/gems/guard-compat-1.2.1/lib/guard/compat/test/template.rb
alimentos-alu0100945645-0.1.0 vendor/bundle/ruby/2.3.0/gems/guard-compat-1.2.1/lib/guard/compat/test/template.rb
alimentos-alu0100945645-1.0.0 vendor/bundle/ruby/2.3.0/gems/guard-compat-1.2.1/lib/guard/compat/test/template.rb
comiditaULL-0.1.1 vendor/bundle/ruby/2.3.0/gems/guard-compat-1.2.1/lib/guard/compat/test/template.rb
comidita_ull-0.1.1 vendor/bundle/ruby/2.3.0/gems/guard-compat-1.2.1/lib/guard/compat/test/template.rb
comidita_ull-0.1.0 vendor/bundle/ruby/2.3.0/gems/guard-compat-1.2.1/lib/guard/compat/test/template.rb
gameboard-3.1.0 vendor/bundle/ruby/2.3.0/gems/guard-compat-1.2.1/lib/guard/compat/test/template.rb
gameboard-3.0.0 vendor/bundle/ruby/2.3.0/gems/guard-compat-1.2.1/lib/guard/compat/test/template.rb
mastermind_adeybee-0.1.4 vendor/bundle/ruby/2.2.0/gems/guard-compat-1.2.1/lib/guard/compat/test/template.rb
mastermind_adeybee-0.1.3 vendor/bundle/ruby/2.2.0/gems/guard-compat-1.2.1/lib/guard/compat/test/template.rb
mastermind_adeybee-0.1.2 vendor/bundle/ruby/2.2.0/gems/guard-compat-1.2.1/lib/guard/compat/test/template.rb
mastermind_adeybee-0.1.1 vendor/bundle/ruby/2.2.0/gems/guard-compat-1.2.1/lib/guard/compat/test/template.rb
geminfo-0.1.0 path/gems/guard-compat-1.2.1/lib/guard/compat/test/template.rb
guard-compat-1.2.1 lib/guard/compat/test/template.rb
guard-compat-1.2.0 lib/guard/compat/test/template.rb
guard-compat-1.1.0 lib/guard/compat/test/template.rb