Class: Gemkeeper::Configuration
- Inherits:
-
Object
- Object
- Gemkeeper::Configuration
- 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.("~/.config/gemkeeper/config.yml") }, # XDG config -> { File.("~/.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.("~/.config/gemkeeper/config.yml") } ].freeze
Instance Attribute Summary collapse
-
#gems ⇒ Object
readonly
Returns the value of attribute gems.
-
#gems_path ⇒ Object
readonly
Returns the value of attribute gems_path.
-
#pid_file ⇒ Object
readonly
Returns the value of attribute pid_file.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#repos_path ⇒ Object
readonly
Returns the value of attribute repos_path.
Class Method Summary collapse
- .config_search_paths ⇒ Object
- .global_config_paths ⇒ Object
- .global_data_dir(config_path) ⇒ Object
- .load(config_path = nil) ⇒ Object
- .resolve_global_path ⇒ Object
Instance Method Summary collapse
- #cache_dir ⇒ Object
- #config_ru_path ⇒ Object
- #geminabox_url ⇒ Object
-
#initialize(config_path = nil) ⇒ Configuration
constructor
A new instance of Configuration.
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
#gems ⇒ Object (readonly)
Returns the value of attribute gems.
48 49 50 |
# File 'lib/gemkeeper/configuration.rb', line 48 def gems @gems end |
#gems_path ⇒ Object (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_file ⇒ Object (readonly)
Returns the value of attribute pid_file.
48 49 50 |
# File 'lib/gemkeeper/configuration.rb', line 48 def pid_file @pid_file end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
48 49 50 |
# File 'lib/gemkeeper/configuration.rb', line 48 def port @port end |
#repos_path ⇒ Object (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_paths ⇒ Object
54 55 56 |
# File 'lib/gemkeeper/configuration.rb', line 54 def self.config_search_paths CONFIG_PATHS.map(&:call) end |
.global_config_paths ⇒ Object
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.(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_path ⇒ Object
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_dir ⇒ Object
72 73 74 75 76 77 78 |
# File 'lib/gemkeeper/configuration.rb', line 72 def cache_dir @cache_dir ||= begin dir = File.("./cache") FileUtils.mkdir_p(dir) dir end end |
#config_ru_path ⇒ Object
68 69 70 |
# File 'lib/gemkeeper/configuration.rb', line 68 def config_ru_path File.join(cache_dir, "config.ru") end |
#geminabox_url ⇒ Object
64 65 66 |
# File 'lib/gemkeeper/configuration.rb', line 64 def geminabox_url "http://localhost:#{port}" end |