Class: Gitenv::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/gitenv/context.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, options = {}) ⇒ Context

Returns a new instance of Context.



8
9
10
11
12
13
14
15
# File 'lib/gitenv/context.rb', line 8

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

Instance Attribute Details

#ignoresObject

Returns the value of attribute ignores.



6
7
8
# File 'lib/gitenv/context.rb', line 6

def ignores
  @ignores
end

Instance Method Details

#dupObject



45
46
47
# File 'lib/gitenv/context.rb', line 45

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

#from(path = nil, &block) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/gitenv/context.rb', line 17

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

#to(path = nil, &block) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/gitenv/context.rb', line 31

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