Class: Rails::Credentials::Conflict::PathResolver
- Inherits:
-
Object
- Object
- Rails::Credentials::Conflict::PathResolver
- Defined in:
- lib/rails/credentials/conflict/path_resolver.rb,
sig/rails/credentials/conflict/path_resolver.rbs
Overview
Resolves file system paths for Rails encrypted credentials and their corresponding key files.
Supports both the default credentials (+config/credentials.yml.enc+)
and environment-specific ones (+config/credentials/
Constant Summary collapse
- VALID_ENVIRONMENT =
/\A[a-z0-9_]+\z/
Instance Attribute Summary collapse
-
#environment ⇒ String?
readonly
Returns the value of attribute environment.
Instance Method Summary collapse
-
#credentials_path ⇒ Pathname
Returns the absolute Pathname to the encrypted credentials file.
-
#initialize(environment = nil) ⇒ PathResolver
constructor
A new instance of PathResolver.
-
#key_path ⇒ Pathname
Returns the absolute Pathname to the encryption key file.
-
#relative_credentials_path ⇒ Pathname
Returns the credentials path relative to
Rails.root.
Constructor Details
#initialize(environment = nil) ⇒ PathResolver
Returns a new instance of PathResolver.
16 17 18 19 20 21 22 23 24 |
# File 'lib/rails/credentials/conflict/path_resolver.rb', line 16 def initialize(environment = nil) if environment && !VALID_ENVIRONMENT.match?(environment.to_s) raise Error, "Invalid environment name: #{environment.inspect}. " \ "Must contain only lowercase letters, digits, and underscores." end @environment = environment end |
Instance Attribute Details
#environment ⇒ String? (readonly)
Returns the value of attribute environment.
14 15 16 |
# File 'lib/rails/credentials/conflict/path_resolver.rb', line 14 def environment @environment end |
Instance Method Details
#credentials_path ⇒ Pathname
Returns the absolute Pathname to the encrypted credentials file.
27 28 29 30 31 32 33 |
# File 'lib/rails/credentials/conflict/path_resolver.rb', line 27 def credentials_path if environment ::Rails.root.join("config", "credentials", "#{environment}.yml.enc") else ::Rails.root.join("config", "credentials.yml.enc") end end |
#key_path ⇒ Pathname
Returns the absolute Pathname to the encryption key file.
36 37 38 39 40 41 42 |
# File 'lib/rails/credentials/conflict/path_resolver.rb', line 36 def key_path if environment ::Rails.root.join("config", "credentials", "#{environment}.key") else ::Rails.root.join("config", "master.key") end end |
#relative_credentials_path ⇒ Pathname
Returns the credentials path relative to Rails.root.
45 46 47 |
# File 'lib/rails/credentials/conflict/path_resolver.rb', line 45 def relative_credentials_path credentials_path.relative_path_from(::Rails.root) end |