Class: Gitenv::Config

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



7
8
9
10
11
# File 'lib/gitenv/config.rb', line 7

def initialize
  @context = Context.new self
  @repos = []
  @actions = []
end

Instance Attribute Details

#actionsObject (readonly)

Returns the value of attribute actions.



5
6
7
# File 'lib/gitenv/config.rb', line 5

def actions
  @actions
end

#reposObject (readonly)

Returns the value of attribute repos.



5
6
7
# File 'lib/gitenv/config.rb', line 5

def repos
  @repos
end

Instance Method Details

#all_files(options = {}) ⇒ Object



31
32
33
# File 'lib/gitenv/config.rb', line 31

def all_files(options = {})
  matcher :all_files, options
end

#copy(file, options = {}) ⇒ Object



25
26
27
28
29
# File 'lib/gitenv/config.rb', line 25

def copy(file, options = {})
  raise 'You must specify a repository or a source directory to copy from' unless @context.from

  Copy::Action.new(@context.dup, matcher(file), options).tap { |a| @actions << a }
end

#dot_files(options = {}) ⇒ Object



35
36
37
# File 'lib/gitenv/config.rb', line 35

def dot_files(options = {})
  matcher :dot_files, options
end

#ignoresObject



46
47
48
# File 'lib/gitenv/config.rb', line 46

def ignores
  @context.ignores
end

#include(other_config_file, optional: false) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/gitenv/config.rb', line 50

def include(other_config_file, optional: false)
  raise 'Only absolute paths can be included' unless Pathname.new(other_config_file).absolute?

  absolute_path = File.expand_path(other_config_file)
  unless File.exist?(absolute_path)
    raise "Cannot find file to include #{absolute_path}" unless optional

    return
  end

  contents = File.open(absolute_path, 'r').read
  instance_eval contents, absolute_path
end

#repo(path, &block) ⇒ Object



13
14
15
16
17
# File 'lib/gitenv/config.rb', line 13

def repo(path, &block)
  @repos << Repository.new(path)
  @context.from path, &block
  self
end


19
20
21
22
23
# File 'lib/gitenv/config.rb', line 19

def symlink(file, options = {})
  raise 'You must specify a repository or a source directory to symlink from' unless @context.from

  Symlink::Action.new(@context.dup, matcher(file), options).tap { |a| @actions << a }
end