Class: Gemkeeper::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/gemkeeper/configuration.rb

Overview

Single source of truth for resolved paths and settings; callers never touch raw YAML keys.

Defined Under Namespace

Classes: GemDefinition

Constant Summary collapse

DEFAULT_PORT =
9292
DEFAULT_CONFIG_FILENAME =
"gemkeeper.yml"
CONFIG_PATHS =

Config file lookup paths in order of priority

[
  -> { File.join(Dir.pwd, DEFAULT_CONFIG_FILENAME) },              # ./gemkeeper.yml
  -> { File.expand_path("~/.config/gemkeeper/config.yml") },       # XDG config
  -> { File.expand_path("~/.gemkeeper.yml") },                     # Home directory
  -> { "/usr/local/etc/gemkeeper.yml" },                           # Homebrew (Intel)
  -> { "/opt/homebrew/etc/gemkeeper.yml" }                         # Homebrew (Apple Silicon)
].freeze
GLOBAL_CONFIG_PATHS =

Candidate paths for the global service config, in priority order

[
  -> { "/opt/homebrew/etc/gemkeeper.yml" },
  -> { "/usr/local/etc/gemkeeper.yml" },
  -> { File.expand_path("~/.config/gemkeeper/config.yml") }
].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config_path = nil) ⇒ Configuration

Returns a new instance of Configuration.



58
59
60
61
62
# File 'lib/gemkeeper/configuration.rb', line 58

def initialize(config_path = nil)
  @config_path = config_path || find_config_file
  @config = load_config
  apply_config
end

Instance Attribute Details

#gemsObject (readonly)

Returns the value of attribute gems.



48
49
50
# File 'lib/gemkeeper/configuration.rb', line 48

def gems
  @gems
end

#gems_pathObject (readonly)

Returns the value of attribute gems_path.



48
49
50
# File 'lib/gemkeeper/configuration.rb', line 48

def gems_path
  @gems_path
end

#pid_fileObject (readonly)

Returns the value of attribute pid_file.



48
49
50
# File 'lib/gemkeeper/configuration.rb', line 48

def pid_file
  @pid_file
end

#portObject (readonly)

Returns the value of attribute port.



48
49
50
# File 'lib/gemkeeper/configuration.rb', line 48

def port
  @port
end

#repos_pathObject (readonly)

Returns the value of attribute repos_path.



48
49
50
# File 'lib/gemkeeper/configuration.rb', line 48

def repos_path
  @repos_path
end

Class Method Details

.config_search_pathsObject



54
55
56
# File 'lib/gemkeeper/configuration.rb', line 54

def self.config_search_paths
  CONFIG_PATHS.map(&:call)
end

.global_config_pathsObject



28
29
30
31
32
33
# File 'lib/gemkeeper/configuration.rb', line 28

def self.global_config_paths
  override = ENV.fetch("GEMKEEPER_GLOBAL_CONFIG", nil)
  return [override] if override

  GLOBAL_CONFIG_PATHS.map(&:call)
end

.global_data_dir(config_path) ⇒ Object



39
40
41
42
43
44
45
46
# File 'lib/gemkeeper/configuration.rb', line 39

def self.global_data_dir(config_path)
  config_dir = File.dirname(File.expand_path(config_path))
  if config_dir.end_with?("/etc")
    File.join(File.dirname(config_dir), "var", "gemkeeper")
  else
    config_dir
  end
end

.load(config_path = nil) ⇒ Object



50
51
52
# File 'lib/gemkeeper/configuration.rb', line 50

def self.load(config_path = nil)
  new(config_path)
end

.resolve_global_pathObject



35
36
37
# File 'lib/gemkeeper/configuration.rb', line 35

def self.resolve_global_path
  global_config_paths.find { |path| File.directory?(File.dirname(path)) }
end

Instance Method Details

#cache_dirObject



72
73
74
75
76
77
78
# File 'lib/gemkeeper/configuration.rb', line 72

def cache_dir
  @cache_dir ||= begin
    dir = File.expand_path("./cache")
    FileUtils.mkdir_p(dir)
    dir
  end
end

#config_ru_pathObject



68
69
70
# File 'lib/gemkeeper/configuration.rb', line 68

def config_ru_path
  File.join(cache_dir, "config.ru")
end

#geminabox_urlObject



64
65
66
# File 'lib/gemkeeper/configuration.rb', line 64

def geminabox_url
  "http://localhost:#{port}"
end