Class: Rodbot::Env
- Inherits:
-
Object
- Object
- Rodbot::Env
- 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
-
#current ⇒ String
readonly
Current environment - any of ENVS.
-
#gem ⇒ Pathname
readonly
Gem root directory.
-
#root ⇒ Pathname
readonly
Root directory.
-
#tmp ⇒ Pathname
readonly
Root directory.
Instance Method Summary collapse
-
#development? ⇒ Boolean
Inquire the env based on RODBOT_ENV.
-
#initialize(root: nil) ⇒ Env
constructor
A new instance of Env.
-
#production? ⇒ Boolean
Inquire the env based on RODBOT_ENV.
-
#test? ⇒ Boolean
Inquire the env based on RODBOT_ENV.
Constructor Details
#initialize(root: nil) ⇒ Env
Returns a new instance of 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
#current ⇒ String (readonly)
Returns 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.
20 21 22 |
# File 'lib/rodbot/env.rb', line 20 def gem @gem end |
#root ⇒ Pathname (readonly)
Returns root directory.
14 15 16 |
# File 'lib/rodbot/env.rb', line 14 def root @root end |
#tmp ⇒ Pathname (readonly)
Returns 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
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 |