class Dhall::Rails::Configuration

Attributes

credentials[R]

Public Class Methods

new(*) click to toggle source
Calls superclass method
# File lib/dhall/rails/configuration.rb, line 10
def initialize(*)
        super
        @credentials              = ActiveSupport::OrderedOptions.new
        @credentials.content_path = default_credentials_content_path
        @credentials.key_path     = default_credentials_key_path
end

Public Instance Methods

active_storage() click to toggle source
Calls superclass method
# File lib/dhall/rails/configuration.rb, line 53
def active_storage
        as = super
        dhall_config = Pathname.new(root.join("config/storage.dhall"))
        yaml_config = Pathname.new(root.join("config/storage.yml"))

        unless dhall_config.exist? || yaml_config.exist?
                raise "Couldn't find Active Storage configuration in #{dhall_config}"
        end

        if as.service_configurations.nil? && dhall_config.exist?
                as.service_configurations = Dhall::Rails.load_decoded(dhall_config)
        end

        as
end
credentials_available_for_current_env?() click to toggle source
# File lib/dhall/rails/configuration.rb, line 85
def credentials_available_for_current_env?
        File.exist?(
                root&.join("config", "credentials", "#{::Rails.env}.dhall.enc").to_s
        )
end
database_configuration() click to toggle source
# File lib/dhall/rails/configuration.rb, line 38
def database_configuration
        path = pathname("config/database")

        return Dhall::Rails.load_decoded("#{path} ? {}") if path&.exist?

        # Value from ENV['DATABASE_URL'] is set to default database connection
        # by Active Record.
        return {} if ENV["DATABASE_URL"]

        raise "Could not load database configuration. No such file - " \
                        "#{paths["config/database"].instance_variable_get(:@paths)}"
rescue => e
        raise e, "Cannot load database configuration:\n#{e.message}", e.backtrace
end
default_credentials_content_path() click to toggle source
# File lib/dhall/rails/configuration.rb, line 69
def default_credentials_content_path
        if credentials_available_for_current_env?
                root&.join("config", "credentials", "#{::Rails.env}.dhall.enc")
        else
                root&.join("config", "credentials.dhall.enc")
        end
end
default_credentials_key_path() click to toggle source
# File lib/dhall/rails/configuration.rb, line 77
def default_credentials_key_path
        if credentials_available_for_current_env?
                root&.join("config", "credentials", "#{::Rails.env}.key")
        else
                root&.join("config", "master.key")
        end
end
load_database_yaml() click to toggle source
# File lib/dhall/rails/configuration.rb, line 25
def load_database_yaml
        if (path = paths["config/database"].existent.first)
                Dhall::Rails.load_decoded("#{path} ? {}")
        else
                {}
        end
end
pathname(key) click to toggle source
# File lib/dhall/rails/configuration.rb, line 33
def pathname(key)
        path = paths[key].existent.first
        path.nil? ? nil : Pathname.new(path)
end
paths() click to toggle source
Calls superclass method
# File lib/dhall/rails/configuration.rb, line 17
def paths
        @paths ||= begin
                paths = super
                paths.add "config/database", with: "config/database.dhall"
                paths
        end
end