Class: Gem::Guardian::Configuration
- Inherits:
-
Object
- Object
- Gem::Guardian::Configuration
- Defined in:
- lib/gem/guardian/configuration.rb
Overview
Project-level configuration loaded from .gem-guardian.yml.
The configuration file is intentionally small and policy-oriented. Its first supported use case is declaring publisher checksum providers for private gem registries that do not expose RubyGems.org checksum metadata.
Constant Summary collapse
- DEFAULT_PATH =
".gem-guardian.yml"
Instance Attribute Summary collapse
-
#checksum_providers ⇒ Object
readonly
Returns the value of attribute checksum_providers.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Class Method Summary collapse
-
.load(path: ENV.fetch("GEM_GUARDIAN_CONFIG", DEFAULT_PATH), cwd: Dir.pwd) ⇒ Configuration
Loads configuration from
.gem-guardian.ymlin the current directory, or fromGEM_GUARDIAN_CONFIGwhen that environment variable is set.
Instance Method Summary collapse
-
#checksum_providers? ⇒ Boolean
Whether the config declares any checksum providers.
-
#initialize(path: nil, checksum_providers: []) ⇒ Configuration
constructor
A new instance of Configuration.
Constructor Details
#initialize(path: nil, checksum_providers: []) ⇒ Configuration
Returns a new instance of Configuration.
46 47 48 49 |
# File 'lib/gem/guardian/configuration.rb', line 46 def initialize(path: nil, checksum_providers: []) @path = path @checksum_providers = checksum_providers end |
Instance Attribute Details
#checksum_providers ⇒ Object (readonly)
Returns the value of attribute checksum_providers.
23 24 25 |
# File 'lib/gem/guardian/configuration.rb', line 23 def checksum_providers @checksum_providers end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
23 24 25 |
# File 'lib/gem/guardian/configuration.rb', line 23 def path @path end |
Class Method Details
.load(path: ENV.fetch("GEM_GUARDIAN_CONFIG", DEFAULT_PATH), cwd: Dir.pwd) ⇒ Configuration
Loads configuration from .gem-guardian.yml in the current directory,
or from GEM_GUARDIAN_CONFIG when that environment variable is set.
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/gem/guardian/configuration.rb', line 32 def self.load(path: ENV.fetch("GEM_GUARDIAN_CONFIG", DEFAULT_PATH), cwd: Dir.pwd) full_path = absolute_path(path, cwd) return new(path: full_path) unless File.file?(full_path) data = YAML.safe_load_file(full_path, permitted_classes: [], aliases: false) || {} raise Error, "#{full_path} must contain a YAML mapping" unless data.is_a?(Hash) new(path: full_path, checksum_providers: build_checksum_providers(data.fetch("checksum_providers", []))) rescue Psych::Exception => e raise Error, "Invalid gem-guardian config #{full_path}: #{e.}" end |
Instance Method Details
#checksum_providers? ⇒ Boolean
Returns whether the config declares any checksum providers.
52 53 54 |
# File 'lib/gem/guardian/configuration.rb', line 52 def checksum_providers? !checksum_providers.empty? end |