Sha256: 0b26bffc7e3fafe654c7893be16f381c4c23d5111b0ed6881de80b294654679d

Contents?: true

Size: 990 Bytes

Versions: 4

Compression:

Stored size: 990 Bytes

Contents

require 'rbconfig'

module Gitenv

  class Context
    attr_accessor :ignores

    def initialize config, options = {}
      @config, @from, @ignores = config, options[:from], options[:ignores]

      @to ||= File.expand_path('~')

      @ignores = options[:ignores] || []
      @ignores << '.DS_Store' if @ignores.empty? and RbConfig::CONFIG['host_os'] =~ /darwin/
    end

    def from path = nil, &block
      return @from if path.nil?

      old = @from
      @from = @from ? File.expand_path(path, @from) : File.expand_path(path)

      if block
        @config.instance_eval &block
        @from = old
      end

      self
    end

    def to path = nil, &block
      return @to if path.nil?

      old = @to
      @to = @to ? File.expand_path(path, @to) : File.expand_path(path)

      if block
        @config.instance_eval &block
        @to = old
      end

      self
    end

    def dup
      Context.new @config, from: @from, to: @to, ignores: @ignores.dup
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
gitenv-1.0.0 lib/gitenv/context.rb
gitenv-0.3.0 lib/gitenv/context.rb
gitenv-0.2.0 lib/gitenv/context.rb
gitenv-0.1.0 lib/gitenv/context.rb