Skip to content

Instantly share code, notes, and snippets.

@tcannonfodder
Created January 29, 2024 13:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tcannonfodder/23c47e8557a717ab167be377dd458ad4 to your computer and use it in GitHub Desktop.
Save tcannonfodder/23c47e8557a717ab167be377dd458ad4 to your computer and use it in GitHub Desktop.
Configuration PORO
# frozen_string_literal: true
class AppSettings
def self.env_fetch(method_name:, key:)
define_singleton_method(method_name){ ENV.fetch(key) }
end
env_fetch(method_name: :webserver_port, key: "PORT")
env_fetch(method_name: :default_host, key: "DEFAULT_HOST")
env_fetch(method_name: :relying_party_origin, key: "RELYING_PARTY_ORIGIN")
env_fetch(method_name: :support_url, key: "SUPPORT_URL")
env_fetch(method_name: :support_email, key: "SUPPORT_EMAIL")
env_fetch(method_name: :postmark_api_token, key: "POSTMARK_API_TOKEN")
def self.rails_semantic_logger_format
ENV.fetch("RAILS_SEMANTIC_LOGGER_FORMAT") { nil }
end
def self.default_host_uri
URI.parse("https://#{self.default_host}")
end
def self.generate_uri(subdomain:)
uri = default_host_uri
uri.host = uri.host.prepend(subdomain.to_s, ".")
return uri
end
def self.default_url_options
{ host: self.default_host, protocol: :https }
end
end
// Example Swift configuration Actor; where the idea originated
actor WorkoutAppConfiguration {
static let instance = WorkoutAppConfiguration()
public let authenticationSessionSchema: String
public let HealthKitIdentifier: String
init(){
self.authenticationSessionSchema = Bundle.main.infoDictionary!["AUTHENTICATION_SERVICES_CALLBACK_SCHEME"] as! String
self.HealthKitIdentifier = Bundle.main.infoDictionary!["HEALTH_KIT_IDENTIFIER"] as! String
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment