module Rockt::Environment

This modules is responsible for detecting the current underlying environment.

It is meant to be extended by any module that represents an environment; these must implement a regex method, which should match the environment name returned by the host_os property from RbConfig, and a commands method, which returns a list of the commands that could be ran to launch the application.

Constants

KNOWN_ENVIRONMENTS

List containing all modules extending Rockt::Environment.

UnknownEnvironment

Raised when cannot recognize the environment.

Public Class Methods

detect() click to toggle source

Detect current environment.

# File lib/rockt/environment.rb, line 35
def self.detect
  host_os = RbConfig::CONFIG['host_os']

  KNOWN_ENVIRONMENTS.find { |env| env.regex =~ host_os } or
    fail UnknownEnvironment
end
extended(env) click to toggle source

Keep tack of defined environments.

# File lib/rockt/environment.rb, line 22
def self.extended(env)
  KNOWN_ENVIRONMENTS << env

  env_name = "#{env.to_s.split('::').last}?"

  # Define a #{environment_name}? method for each of the known.
  # environments.
  self.singleton_class.send(:define_method, env_name.downcase.to_sym) do
    detect == env
  end
end