Class: Bonchi::GlobalConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/bonchi/global_config.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeGlobalConfig

Returns a new instance of GlobalConfig.



6
7
8
9
10
11
12
13
# File 'lib/bonchi/global_config.rb', line 6

def initialize
  @path = self.class.config_path
  @data = if File.exist?(@path)
    YAML.safe_load_file(@path) || {}
  else
    {}
  end
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



15
16
17
# File 'lib/bonchi/global_config.rb', line 15

def data
  @data
end

#pathObject (readonly)

Returns the value of attribute path.



15
16
17
# File 'lib/bonchi/global_config.rb', line 15

def path
  @path
end

Class Method Details

.config_pathObject



23
24
25
26
27
28
29
30
31
32
# File 'lib/bonchi/global_config.rb', line 23

def self.config_path
  xdg = ENV["XDG_CONFIG_HOME"]
  if xdg && !xdg.empty?
    dir = File.join(xdg, "bonchi")
    FileUtils.mkdir_p(dir)
    File.join(dir, "config.yml")
  else
    File.expand_path("~/.bonchi.yml")
  end
end

Instance Method Details

#worktree_rootObject



17
18
19
20
21
# File 'lib/bonchi/global_config.rb', line 17

def worktree_root
  ENV.fetch("WORKTREE_ROOT") {
    @data["worktree_root"] || File.join(Dir.home, "dev", "worktrees")
  }
end