Class: Bonchi::Config

Inherits:
Object
  • Object
show all
Includes:
Colors
Defined in:
lib/bonchi/config.rb

Constant Summary collapse

KNOWN_KEYS =
%w[min_version copy link ports replace pre_setup setup].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Config

Returns a new instance of Config.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/bonchi/config.rb', line 11

def initialize(path)
  data = YAML.load_file(path)

  unknown = data.keys - KNOWN_KEYS
  unknown.each { |k| warn "#{color(:yellow)}Warning:#{reset} unknown key '#{k}' in .worktree.yml, ignoring" }

  check_min_version!(data["min_version"]) if data["min_version"]

  @copy = Array(data["copy"])
  @link = Array(data["link"])
  @ports = Array(data["ports"])
  @replace = data["replace"] || {}
  @pre_setup = Array(data["pre_setup"])
  @setup = data["setup"] || "bin/setup"

  validate!
end

Instance Attribute Details

#copyObject (readonly)

Returns the value of attribute copy.



9
10
11
# File 'lib/bonchi/config.rb', line 9

def copy
  @copy
end

Returns the value of attribute link.



9
10
11
# File 'lib/bonchi/config.rb', line 9

def link
  @link
end

#portsObject (readonly)

Returns the value of attribute ports.



9
10
11
# File 'lib/bonchi/config.rb', line 9

def ports
  @ports
end

#pre_setupObject (readonly)

Returns the value of attribute pre_setup.



9
10
11
# File 'lib/bonchi/config.rb', line 9

def pre_setup
  @pre_setup
end

#replaceObject (readonly)

Returns the value of attribute replace.



9
10
11
# File 'lib/bonchi/config.rb', line 9

def replace
  @replace
end

#setupObject (readonly)

Returns the value of attribute setup.



9
10
11
# File 'lib/bonchi/config.rb', line 9

def setup
  @setup
end

Class Method Details

.from_main_worktreeObject



29
30
31
# File 'lib/bonchi/config.rb', line 29

def self.from_main_worktree
  from_worktree(Git.main_worktree)
end

.from_worktree(dir) ⇒ Object



33
34
35
36
37
38
# File 'lib/bonchi/config.rb', line 33

def self.from_worktree(dir)
  path = File.join(dir, ".worktree.yml")
  return nil unless File.exist?(path)

  new(path)
end