Sha256: 732cc2824e2cd69e18e8b813cf8a5c2c6cad40e0764b3fc46795f9af9940d920

Contents?: true

Size: 1.22 KB

Versions: 5

Compression:

Stored size: 1.22 KB

Contents

module Gem
  module Release
    module Files
      class Templates
        class Group
          attr_reader :groups, :data, :sources, :files

          def initialize(groups, data, sources, files)
            @groups  = [:default] + Array(groups)
            @data    = data
            @sources = sources
            @files   = Array(files)
          end

          def all
            return [] unless paths.any?
            all = Dir.glob(pattern, File::FNM_DOTMATCH)
            all = all.select { |file| File.file?(file) }
            all.map { |file| [file, relative(file)] }
          end

          private

            def pattern
              "{#{paths.join(',')}}/{#{files.join(',')}}"
            end

            def relative(file)
              paths.inject(file) { |file, path| file.sub("#{path}/", '') }
            end

            def paths
              @paths ||= groups.map do |group|
                paths = paths_for(group).map { |path| File.expand_path(*path) }
                paths.detect { |path| File.exist?(path) }
              end.compact
            end

            def paths_for(group)
              sources.map { |paths| paths.map { |path| path % group } }
            end
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
gem-release-2.0.0.rc.2 lib/gem/release/files/templates/group.rb
gem-release-2.0.0.rc.1 lib/gem/release/files/templates/group.rb
gem-release-2.0.0.dev.5 lib/gem/release/files/templates/group.rb
gem-release-2.0.0.dev.4 lib/gem/release/files/templates/group.rb
gem-release-2.0.0.dev.3 lib/gem/release/files/templates/group.rb