Sha256: 55fca18fb6d9928ad16e3d3c08d052b4ff6bb40b206d0c4ed9cc089b2f8d7a25

Contents?: true

Size: 1.09 KB

Versions: 1

Compression:

Stored size: 1.09 KB

Contents

# encoding: UTF-8

require 'fileutils'

module RepoFixture

  class Fixture
    DEFAULT_STRATEGY = :zip

    attr_reader :repo

    def initialize(repo)
      @repo = repo
    end

    # Copies files into the repo.
    # Optional block receives each file, return value is the desired path inside the archive.
    def copy_files(files)
      Array(files).each do |file|
        output_file = if block_given?
          yield file
        else
          file
        end

        output_file = File.join(repo.working_dir, output_file)
        FileUtils.mkdir_p(File.dirname(output_file))
        FileUtils.cp(file, output_file)
      end
    end

    def respond_to?(method)
      repo.respond_to?(method)
    end

    def method_missing(method, *args, &block)
      repo.send(method, *args, &block)
    end

    def export(export_file, strategy = DEFAULT_STRATEGY)
      strategy_class_for(strategy).export(export_file, self)
    end

    def sh(command)
      repo.in_repo { `#{command}` }
    end

    private

    def strategy_class_for(strategy)
      RepoFixture.strategy_class_for(strategy)
    end
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
repo-fixture-1.0.0 lib/repo-fixture/fixture.rb