Sha256: c6ba556ccf06b43cda04551ebcf0315e6f14192c403b65bfdfcfc6c90512f82e

Contents?: true

Size: 1.15 KB

Versions: 5

Compression:

Stored size: 1.15 KB

Contents

module Guard
  class Dsl

    class << self
      def evaluate_guardfile(options = {})
        @@options = options
        
        if File.exists?(guardfile_path)
          begin
            new.instance_eval(File.read(guardfile_path), guardfile_path, 1)
          rescue
            UI.error "Invalid Guardfile, original error is:\n#{$!}"
            exit 1
          end
        else
          UI.error "No Guardfile in current folder, please create one."
          exit 1
        end
      end

      def guardfile_include?(guard_name)
        File.read(guardfile_path).match(/^guard\s*\(?\s*['":]#{guard_name}['"]?/)
      end
      
      def guardfile_path
        File.join(Dir.pwd, 'Guardfile')
      end
    end

    def group(name, &guard_definition)
      guard_definition.call if guard_definition && (@@options[:group].empty? || @@options[:group].include?(name))
    end

    def guard(name, options = {}, &watch_definition)
      @watchers = []
      watch_definition.call if watch_definition
      ::Guard.add_guard(name, @watchers, options)
    end

    def watch(pattern, &action)
      @watchers << ::Guard::Watcher.new(pattern, action)
    end

  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
guard-0.3.4 lib/guard/dsl.rb
guard-0.3.3 lib/guard/dsl.rb
guard-0.3.2 lib/guard/dsl.rb
guard-0.3.1 lib/guard/dsl.rb
guard-0.3.0 lib/guard/dsl.rb