Class: GemCP::Config
- Inherits:
-
Object
- Object
- GemCP::Config
- Defined in:
- lib/gemcp/config.rb
Overview
Immutable configuration for a GemCP client. Reads from environment variables at construction time, with sensible defaults.
Instance Attribute Summary collapse
-
#cache_dir ⇒ String
readonly
Path to the persistent JSON cache directory.
-
#cache_ttl ⇒ Integer
readonly
Seconds before a cache entry is considered stale.
-
#local_first ⇒ Boolean
readonly
Whether to prefer installed gemspecs over network.
-
#requests_per_second ⇒ Float
readonly
Maximum outbound requests per second.
Instance Method Summary collapse
-
#initialize(cache_dir: ENV.fetch("GEMCP_CACHE_DIR", File.join(Dir.home, ".cache", "gemcp")), cache_ttl: Integer(ENV.fetch("GEMCP_CACHE_TTL", "3600")), requests_per_second: Float(ENV.fetch("GEMCP_REQUESTS_PER_SECOND", "2")), local_first: ENV.fetch("GEMCP_LOCAL_FIRST", "true") != "false") ⇒ Config
constructor
A new instance of Config.
Constructor Details
#initialize(cache_dir: ENV.fetch("GEMCP_CACHE_DIR", File.join(Dir.home, ".cache", "gemcp")), cache_ttl: Integer(ENV.fetch("GEMCP_CACHE_TTL", "3600")), requests_per_second: Float(ENV.fetch("GEMCP_REQUESTS_PER_SECOND", "2")), local_first: ENV.fetch("GEMCP_LOCAL_FIRST", "true") != "false") ⇒ Config
Returns a new instance of Config.
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/gemcp/config.rb', line 23 def initialize( cache_dir: ENV.fetch("GEMCP_CACHE_DIR", File.join(Dir.home, ".cache", "gemcp")), cache_ttl: Integer(ENV.fetch("GEMCP_CACHE_TTL", "3600")), requests_per_second: Float(ENV.fetch("GEMCP_REQUESTS_PER_SECOND", "2")), local_first: ENV.fetch("GEMCP_LOCAL_FIRST", "true") != "false" ) @cache_dir = cache_dir @cache_ttl = cache_ttl @requests_per_second = requests_per_second @local_first = local_first end |
Instance Attribute Details
#cache_dir ⇒ String (readonly)
Returns path to the persistent JSON cache directory.
8 9 10 |
# File 'lib/gemcp/config.rb', line 8 def cache_dir @cache_dir end |
#cache_ttl ⇒ Integer (readonly)
Returns seconds before a cache entry is considered stale.
11 12 13 |
# File 'lib/gemcp/config.rb', line 11 def cache_ttl @cache_ttl end |
#local_first ⇒ Boolean (readonly)
Returns whether to prefer installed gemspecs over network.
17 18 19 |
# File 'lib/gemcp/config.rb', line 17 def local_first @local_first end |
#requests_per_second ⇒ Float (readonly)
Returns maximum outbound requests per second.
14 15 16 |
# File 'lib/gemcp/config.rb', line 14 def requests_per_second @requests_per_second end |