Sha256: 766af47c39dfc3f5f4d97123f3ef911bc31eb20d41ac7694a0ab5ba2a1225dac

Contents?: true

Size: 1.11 KB

Versions: 26

Compression:

Stored size: 1.11 KB

Contents

require 'tmpdir'
require 'tempfile'

module PkgForge
  ##
  # Add dir methods to Forge
  class Forge
    Contract Or[String, Symbol] => String
    def dep(package)
      tmpdir(package.to_sym)
    end

    Contract None => String
    def releasedir
      tmpdir(:release)
    end

    Contract Symbol => String
    def tmpdir(id)
      state[:tmpdirs] ||= {}
      state[:tmpdirs][id] ||= Dir.mktmpdir(id.to_s)
    end

    Contract Symbol => String
    def tmpfile(id)
      state[:tmpfiles] ||= {}
      state[:tmpfiles][id] ||= Tempfile.create(id.to_s).path
    end
  end

  module DSL
    ##
    # Add dir methods to Forge DSL
    class Forge
      Contract Or[String, Symbol] => String
      def dep(dep_name)
        @forge.dep(dep_name)
      end
    end

    ##
    # Add dir methods to Build DSL
    class Build
      Contract None => String
      def releasedir
        @forge.tmpdir(:release)
      end

      Contract Or[String, Symbol] => String
      def dep(package)
        @forge.tmpdir(package.to_sym)
      end

      Contract Symbol => String
      def tmpdir(id)
        @forge.tmpdir(id)
      end
    end
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
pkgforge-0.29.1 lib/pkgforge/components/dirs.rb
pkgforge-0.29.0 lib/pkgforge/components/dirs.rb
pkgforge-0.28.0 lib/pkgforge/components/dirs.rb
pkgforge-0.27.0 lib/pkgforge/components/dirs.rb
pkgforge-0.26.0 lib/pkgforge/components/dirs.rb
pkgforge-0.25.1 lib/pkgforge/components/dirs.rb
pkgforge-0.25.0 lib/pkgforge/components/dirs.rb
pkgforge-0.24.1 lib/pkgforge/components/dirs.rb
pkgforge-0.24.0 lib/pkgforge/components/dirs.rb
pkgforge-0.23.2 lib/pkgforge/components/dirs.rb
pkgforge-0.23.1 lib/pkgforge/components/dirs.rb
pkgforge-0.23.0 lib/pkgforge/components/dirs.rb
pkgforge-0.22.0 lib/pkgforge/components/dirs.rb
pkgforge-0.21.0 lib/pkgforge/components/dirs.rb
pkgforge-0.20.0 lib/pkgforge/components/dirs.rb
pkgforge-0.19.0 lib/pkgforge/components/dirs.rb
pkgforge-0.18.0 lib/pkgforge/components/dirs.rb
pkgforge-0.17.0 lib/pkgforge/components/dirs.rb
pkgforge-0.16.1 lib/pkgforge/components/dirs.rb
pkgforge-0.16.0 lib/pkgforge/components/dirs.rb