Envlogic
[Unmaintained] Envlogic is a library used to manage environments for your Ruby application in a similar to Rails.env way
Install / Use
/learn @karafka/EnvlogicREADME
Envlogic [Unmaintained]
Note: This library is no longer in use in the Karafka ecosystem. It was developed for Karafka versions prior to 2.0.
Envlogic is a library used to manage environments for your Ruby application in a similar to Rails.env way.
Installation
Add the gem to your Gemfile
gem 'envlogic'
Usage
On a class/module level
Extend your class or module in which you want to use this library with Envlogic module.
module ExampleModule
extend Envlogic
# code of this module
end
Once you extend your class/module with it, you will have two additional methods (with two aliases):
- .env (.environment) - obtain current env and work with it
- .env= (.environment=) - set your own environment
ExampleModule.env = 'development'
ExampleModule.env.development? # => true
ExampleModule.env.production? # => false
On a per instance basis
Include the Envlogic module in the class for which instances you want to use it.
class ExampleClass
include Envlogic
# code of this class
end
Once you include it in your class, you will have two additional methods (with two aliases):
- .env (.environment) - obtain current env and work with it
- .env= (.environment=) - set your own environment
instance = ExampleClass.new
instance.env = 'development'
instance.env.development? # => true
instance.env.production? # => false
ENV variables key names and default fallbacks
Application root directory env key name
By default, the gem is looking for ENV variable that is based on your application root directory.
For example, if your application lies in /home/deploy/my_app it will look for MY_APP_ENV variable.
Module/class name based env key name
If there's no env value under the app directory name key, it will fallback to the module/class based env variable name (including the whole namespace chain):
module Basic
module Karafka
extend Envlogic
# code of Karafka module
end
end
ENV['FACEBOOK_API_ENV'] = nil
ENV['BASIC_KARAFKA_ENV'] = 'development'
Basic::Karafka.env.production? # => false
Basic::Karafka.env.development? # => true
Default fallbacks
If there's no other way to determine the environment, Envlogic will fallback to ENV['RACK_ENV'] and if it fails, it will just assume that we're in 'development' mode.
You can also assign the environment directly in Ruby:
module Basic
module Karafka
extend Envlogic
# code of Karafka module
end
end
Basic::Karafka.env = :development
Basic::Karafka.env.production? # => false
Basic::Karafka.env.development? # => true
References
Note on contributions
First, thank you for considering contributing to the Karafka ecosystem! It's people like you that make the open source community such a great community!
Each pull request must pass all the RSpec specs, integration tests and meet our quality requirements.
Fork it, update and wait for the Github Actions results.
Related Skills
node-connect
351.4kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
110.7kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
351.4kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
351.4kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
