Module: HerokuEnv
Instance Method Summary collapse
- #add_env(**args) ⇒ Object
- #app_name ⇒ Object
- #configure(&block) ⇒ Object
- #env ⇒ Object
- #heroku_app_name_to_env_mappings ⇒ Object
Instance Method Details
#add_env(**args) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/nxt_heroku_env/heroku_env.rb', line 12 def add_env(**args) args.each do |env_name, heroku_app_name| app_name_pattern = heroku_app_name.is_a?(Regexp) ? heroku_app_name : Regexp.new(heroku_app_name.to_s) heroku_app_name_to_env_mappings[app_name_pattern] = env_name.to_sym define_method("#{env_name}?") do env == env_name.to_sym end define_method(env_name) do |&block| block.call if env == env_name.to_sym end end end |
#app_name ⇒ Object
4 5 6 |
# File 'lib/nxt_heroku_env/heroku_env.rb', line 4 def app_name ENV["HEROKU_APP_NAME"].presence end |
#configure(&block) ⇒ Object
37 38 39 |
# File 'lib/nxt_heroku_env/heroku_env.rb', line 37 def configure(&block) block.call(self) end |
#env ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/nxt_heroku_env/heroku_env.rb', line 27 def env @env ||= begin env_name = heroku_app_name_to_env_mappings.keys.find { |heroku_app_name_pattern| heroku_app_name_pattern.match?(app_name) } heroku_app_name_to_env_mappings[env_name] end end |
#heroku_app_name_to_env_mappings ⇒ Object
8 9 10 |
# File 'lib/nxt_heroku_env/heroku_env.rb', line 8 def heroku_app_name_to_env_mappings @heroku_app_name_to_env_mappings ||= {} end |