Sha256: 5917dd0e74edc7cda81f635ab10c3517a6d58db54822210d1cec0ee24f357c72

Contents?: true

Size: 1.13 KB

Versions: 2

Compression:

Stored size: 1.13 KB

Contents

module Canpe
  class RepositoryOperationContext
    attr_accessor :repository_operation, :root_directory

    def initialize(repository_operation, root_directory = nil)
      @repository_operation = repository_operation
      @root_directory = root_directory
    end

    def repository
      repository_operation.repository
    end

    def prepare(options)
      working_directory = options[:working_directory]

      if working_directory.nil?
        print "working directory (#{Dir.pwd}) ? "
        working_directory = STDIN.gets.chomp
      end

      if working_directory.blank?
        working_directory = Dir.pwd
      elsif !File.directory?(working_directory)
        raise FileManipulation::NotDirectoryError, "#{working_directory} is not a directory."
      end

      @root_directory = working_directory
    end

    def source_root
      repository.templates_url
    end

    def destination_root
      root_directory
    end

    def source_file_path(path)
      File.join(source_root, path)
    end

    def destination_file_path(path)
      repository_operation.renderer.render_string(File.join(destination_root, path))
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
canpe-0.1.1 lib/canpe/repository_operation_context.rb
canpe-0.1.0 lib/canpe/repository_operation_context.rb