Sha256: 4c199de3c2ab1efadc6d42cc1ab6b4fae2d25d0d94732eb6101e64a6d35cb150

Contents?: true

Size: 944 Bytes

Versions: 9

Compression:

Stored size: 944 Bytes

Contents

# encoding: UTF-8

require 'pathname'

module Spontaneous
  class Paths < ::Hash
    # TODO: Move this kind of stuff into the Revision class
    # Instead of throwing around revision numbers we should
    # be throwing around Revision instances. It is fecking OO
    # after all...
    def self.pad_revision_number(revision)
      revision.to_s.rjust(5, "0")
    end

    def initialize(root)
      @root = File.expand_path(root)
      super() { |hash, key| hash[key] = [] }
    end

    def add(category, *paths)
      self[category].concat(paths)
    end

    def expanded(category)
      self[category].map do |path, glob|
        path = Pathname.new(path)
        path = Pathname.new(@root) + path unless (path.absolute? && path.exist?)
        if path.exist?
          path = path.cleanpath
          path += glob if glob
          path.to_s
        else
          nil
        end
      end.compact
    end
  end # Paths
end # Spontaneous

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
spontaneous-0.2.0.beta10 lib/spontaneous/paths.rb
spontaneous-0.2.0.beta9 lib/spontaneous/paths.rb
spontaneous-0.2.0.beta8 lib/spontaneous/paths.rb
spontaneous-0.2.0.beta7 lib/spontaneous/paths.rb
spontaneous-0.2.0.beta6 lib/spontaneous/paths.rb
spontaneous-0.2.0.beta5 lib/spontaneous/paths.rb
spontaneous-0.2.0.beta4 lib/spontaneous/paths.rb
spontaneous-0.2.0.beta3 lib/spontaneous/paths.rb
spontaneous-0.2.0.beta2 lib/spontaneous/paths.rb