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



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

#currentString (readonly)



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

def current
  @current
end

#gemPathname (readonly)



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

def gem
  @gem
end

#rootPathname (readonly)



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

def root
  @root
end

#tmpPathname (readonly)



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



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



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



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

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