Class: Gemkeeper::Configuration

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

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

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.



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

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.



20
21
22
# File 'lib/gemkeeper/configuration.rb', line 20

def gems
  @gems
end

#gems_pathObject (readonly)

Returns the value of attribute gems_path.



20
21
22
# File 'lib/gemkeeper/configuration.rb', line 20

def gems_path
  @gems_path
end

#pid_fileObject (readonly)

Returns the value of attribute pid_file.



20
21
22
# File 'lib/gemkeeper/configuration.rb', line 20

def pid_file
  @pid_file
end

#portObject (readonly)

Returns the value of attribute port.



20
21
22
# File 'lib/gemkeeper/configuration.rb', line 20

def port
  @port
end

#repos_pathObject (readonly)

Returns the value of attribute repos_path.



20
21
22
# File 'lib/gemkeeper/configuration.rb', line 20

def repos_path
  @repos_path
end

Class Method Details

.config_search_pathsObject



26
27
28
# File 'lib/gemkeeper/configuration.rb', line 26

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

.load(config_path = nil) ⇒ Object



22
23
24
# File 'lib/gemkeeper/configuration.rb', line 22

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

Instance Method Details

#cache_dirObject



44
45
46
47
48
49
50
# File 'lib/gemkeeper/configuration.rb', line 44

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

#config_ru_pathObject



40
41
42
# File 'lib/gemkeeper/configuration.rb', line 40

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

#geminabox_urlObject



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

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