Sha256: 756e2a8abbd46bbd0dba962737a2cbd38d2844c9710bde0af53073b8f4b305a5

Contents?: true

Size: 1.38 KB

Versions: 5

Compression:

Stored size: 1.38 KB

Contents

# Author::    Marco Tessari  <marco.tessari@epita.fr>.
# Copyright:: Copyright (c) 2004, 2005 TTK team. All rights reserved.
# License::   LGPL
# $Id: Glob.rb 567 2005-04-13 08:00:06Z polrop $


module TTK

  module Strategies

    # The Glob strategy collects a set of files using a globing expression,
    # bundles them in a Composite strategy and finally run them sequentially.
    class Glob < Composite
      include Concrete

      def prologue
        super
        Dir[@glob].each do |file|
	  create(@test) do |t|
            # Symtbl must be filled before the test attributes initialization
            if file =~ @regexp
              t.symtbl[:match] = $1
            else
              raise ArgumentError,
                    "Path name (#{file}) doesn't match the regexp (#@regexp)"
            end
            t.symtbl[:path] = file
          end
        end
      end


      def regexp= ( aRegexp )
        @regexp = aRegexp
	@regexp = Regexp.new(aRegexp) unless aRegexp.is_a? Regexp
      end

      attribute :glob,   'a globing pattern',             :mandatory
      attribute :regexp, 'a regular expression to extract a part of the ' +
                         'path (ex: the tarball author)', :mandatory
      attribute :test,   'the test to run on each file',
                         :mandatory, :invisible, :dont_expand

    end # class Glob

  end # module Strategies

end # module TTK

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
ttk-0.1.576 lib/ttk/strategies/Glob.rb
ttk-0.1.580 lib/ttk/strategies/Glob.rb
ttk-0.2.1 lib/ttk/strategies/Glob.rb
ttk-0.1.579 lib/ttk/strategies/Glob.rb
ttk-0.2.0 lib/ttk/strategies/Glob.rb