Class: Apes::RuntimeConfiguration

Inherits:
Object
  • Object
show all
Defined in:
lib/apes/runtime_configuration.rb

Overview

Internal class to handle runtime configuration.

Class Method Summary collapse

Class Method Details

.cors_source(default = "http://localhost") ⇒ String

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

Parameters:

  • default (String) (defaults to: "http://localhost")

    The fallback if no valid CORS source is found in Rails secrets file.

Returns:

  • (String)

    The CORS source used by Apes.



59
60
61
# 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?Boolean

Check if Rails is in development environment.

Returns:

  • (Boolean)

    true if Rails is in development environment, false otherwise.



43
44
45
# File 'lib/apes/runtime_configuration.rb', line 43

def development?
  environment == "development"
end

.environment(default = "development") ⇒ String

Returns the current Rails environment.

Parameters:

  • default (String) (defaults to: "development")

    The fallback environment if Rails configuration is invalid.

Returns:

  • (String)

    The the current Rails environment.



36
37
38
# File 'lib/apes/runtime_configuration.rb', line 36

def environment(default = "development")
  fetch_with_fallback(default) { Rails.env }
end

.gems_root(default = nil) ⇒ String

Returns the current RubyGems root directory.

Parameters:

  • default (String) (defaults to: nil)

    The fallback if RubyGems configuration is invalid.

Returns:

  • (String)

    The current RubyGems root directory.



28
29
30
# 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") ⇒ String

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

Parameters:

  • default (String) (defaults to: "secret")

    The fallback if no valid secret is found in Rails secrets file.

Returns:

  • (String)

    The JWT token used by Apes.



51
52
53
# 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) ⇒ String

Returns the current Rails root directory.

Parameters:

  • default (String) (defaults to: nil)

    The fallback if Rails configuration is invalid.

Returns:

  • (String)

    The current Rails root directory.



20
21
22
# File 'lib/apes/runtime_configuration.rb', line 20

def rails_root(default = nil)
  fetch_with_fallback(default) { Rails.root.to_s }
end

.rootString

Returns the root directory of apes.

Returns:

  • (String)


12
13
14
# 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 = {}) ⇒ Hash

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

Parameters:

  • default (String) (defaults to: {})

    The fallback if no valid configuration is found in Rails.

Returns:

  • (Hash)

    A object describing valid timestamps formats.



67
68
69
# File 'lib/apes/runtime_configuration.rb', line 67

def timestamp_formats(default = {})
  fetch_with_fallback(default) { Rails.application.config.timestamp_formats }
end