Sha256: f29c99e8762ef4bd30672397f3a572294ad912ef0b405a50c45ef76f0a652d50

Contents?: true

Size: 879 Bytes

Versions: 1

Compression:

Stored size: 879 Bytes

Contents

module Praxis

  class FileGroup

    attr_reader :groups, :base

    def initialize(base, &block)
      @groups = Hash.new
      @base = base

      if block_given?
        self.instance_eval(&block)
      end
    end

    def layout(&block)
      self.instance_eval(&block)
    end

    def map(name, pattern, &block)
      if block_given?
        @groups[name] = FileGroup.new(base + pattern, &block)
      else
        @groups[name] ||= []
        file_enum = base.find.to_a
        files = file_enum.select do |file|
          path = file.relative_path_from(base)
          file.file? && path.fnmatch?(pattern, File::FNM_PATHNAME)
        end
        files.sort_by { |file| [file.to_s.split('/').size, file.to_s] }.each { |file| @groups[name] << file }
      end
    end

    def [](*names)
      names.inject(@groups) { |group, name| group[name] || [] }
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
praxis-0.9 lib/praxis/file_group.rb