Class: Rodbot::Env

Inherits:
Object
  • Object
show all
Defined in:
lib/rodbot/env.rb

Overview

Note:

Use the Rodbot.env shortcut to access these methods!

Environment the bot is currently living in

Constant Summary collapse

ENVS =

Supported environments

%w(production development test).freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root: nil) ⇒ Env

Returns a new instance of Env.

Parameters:

  • root (Pathname, String) (defaults to: nil) —

    root path (default: current directory)



26
27
28
29
30
31
32
# File 'lib/rodbot/env.rb', line 26

def initialize(root: nil)
  @root = root ? Pathname(root).realpath : Pathname.pwd
  @tmp = @root.join('tmp')
  @gem = Pathname(__dir__).join('..', '..').realpath
  @current = ENV['RODBOT_ENV'] || ENV['APP_ENV']
  @current = 'development' unless ENVS.include? @current
end

Instance Attribute Details

#current ⇒ String (readonly)

Returns current environment - any of ENVS.

Returns:

  • (String) —

    current environment - any of ENVS



23
24
25
# File 'lib/rodbot/env.rb', line 23

def current
  @current
end

#gem ⇒ Pathname (readonly)

Returns gem root directory.

Returns:

  • (Pathname) —

    gem root directory



20
21
22
# File 'lib/rodbot/env.rb', line 20

def gem
  @gem
end

#root ⇒ Pathname (readonly)

Returns root directory.

Returns:

  • (Pathname) —

    root directory



14
15
16
# File 'lib/rodbot/env.rb', line 14

def root
  @root
end

#tmp ⇒ Pathname (readonly)

Returns root directory.

Returns:

  • (Pathname) —

    root directory



17
18
19
# File 'lib/rodbot/env.rb', line 17

def tmp
  @tmp
end

Instance Method Details

#development? ⇒ Boolean

Inquire the env based on RODBOT_ENV

Returns:

  • (Boolean)


41
42
43
44
45
# File 'lib/rodbot/env.rb', line 41

ENVS.each do |env|
  define_method "#{env}?" do
    env == current
  end
end

#production? ⇒ Boolean

Inquire the env based on RODBOT_ENV

Returns:

  • (Boolean)


41
42
43
44
45
# File 'lib/rodbot/env.rb', line 41

ENVS.each do |env|
  define_method "#{env}?" do
    env == current
  end
end

#test? ⇒ Boolean

Inquire the env based on RODBOT_ENV

Returns:

  • (Boolean)


41
42
43
44
45
# File 'lib/rodbot/env.rb', line 41

ENVS.each do |env|
  define_method "#{env}?" do
    env == current
  end
end