class Apes::RuntimeConfiguration

Internal class to handle runtime configuration.

Public Class Methods

cors_source(default = "http://localhost") click to toggle source

Returns the CORS source used by Apes. This should be defined in the Rails secrets.yml file.

@param default [String] The fallback if no valid CORS source is found in Rails secrets file. @return [String] The CORS source used by Apes.

# File lib/apes/runtime_configuration.rb, line 59
def cors_source(default = "http://localhost")
  fetch_with_fallback(default) { Rails.application.secrets.cors_source }
end
development?() click to toggle source

Check if Rails is in development environment.

@return [Boolean] `true` if Rails is in `development` environment, `false` otherwise.

# File lib/apes/runtime_configuration.rb, line 43
def development?
  environment == "development"
end
environment(default = "development") click to toggle source

Returns the current Rails environment.

@param default [String] The fallback environment if Rails configuration is invalid. @return [String] The the current Rails environment.

# File lib/apes/runtime_configuration.rb, line 36
def environment(default = "development")
  fetch_with_fallback(default) { Rails.env }
end
gems_root(default = nil) click to toggle source

Returns the current RubyGems root directory.

@param default [String] The fallback if RubyGems configuration is invalid. @return [String] The current RubyGems root directory.

# File lib/apes/runtime_configuration.rb, line 28
def gems_root(default = nil)
  fetch_with_fallback(default) { Pathname.new(Gem.loaded_specs["lazier"].full_gem_path).parent.to_s }
end
jwt_token(default = "secret") click to toggle source

Returns the JWT token used by Apes. This should be defined in the Rails secrets.yml file.

@param default [String] The fallback if no valid secret is found in Rails secrets file. @return [String] The JWT token used by Apes.

# File lib/apes/runtime_configuration.rb, line 51
def jwt_token(default = "secret")
  fetch_with_fallback(default) { Rails.application.secrets.jwt }
end
rails_root(default = nil) click to toggle source

Returns the current Rails root directory.

@param default [String] The fallback if Rails configuration is invalid. @return [String] The current Rails root directory.

# File lib/apes/runtime_configuration.rb, line 20
def rails_root(default = nil)
  fetch_with_fallback(default) { Rails.root.to_s }
end
root() click to toggle source

Returns the root directory of apes. @return [String]

# File lib/apes/runtime_configuration.rb, line 12
def root
  Pathname.new(Gem.loaded_specs["apes"].full_gem_path).to_s
end
timestamp_formats(default = {}) click to toggle source

Returns a map where keys are tags and values are strftime compliant formats.

@param default [String] The fallback if no valid configuration is found in Rails. @return [Hash] A object describing valid timestamps formats.

# File lib/apes/runtime_configuration.rb, line 67
def timestamp_formats(default = {})
  fetch_with_fallback(default) { Rails.application.config.timestamp_formats }
end

Private Class Methods

fetch_with_fallback(default) { || ... } click to toggle source
# File lib/apes/runtime_configuration.rb, line 73
def fetch_with_fallback(default)
  yield
rescue
  default
end