Class: Devup::Application

Inherits:
Object
  • Object
show all
Defined in:
lib/devup/application.rb

Instance Method Summary collapse

Instance Method Details

#app_envObject



44
45
46
# File 'lib/devup/application.rb', line 44

def app_env
  (ENV["RAILS_ENV"] || ENV["RACK_ENV"] || "development").to_sym
end

#bootObject



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/devup/application.rb', line 13

def boot
  devup.up

  begin
    require "spring/commands"

    Spring.watch devup.root.join("docker-compose.yml")
  rescue LoadError, ArgumentError, NameError
    # Spring is not available
  end
end

#devupObject



25
26
27
28
29
30
# File 'lib/devup/application.rb', line 25

def devup
  @devup ||= Devup::Environment.new(
    pwd: `pwd`,
    logger: Devup::Logger.new(level: log_level)
  )
end

#devup_disabled?Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/devup/application.rb', line 60

def devup_disabled?
  ENV.fetch("DEVUP_ENABLED", dotenv_vars["DEVUP_ENABLED"] || "true") != "true"
end

#dotenv_listObject



48
49
50
# File 'lib/devup/application.rb', line 48

def dotenv_list
  Devup::DotenvLoadList.new(env: app_env)
end

#dotenv_varsObject



52
53
54
# File 'lib/devup/application.rb', line 52

def dotenv_vars
  Dotenv.parse(*dotenv_list.to_a)
end

#load_envObject



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/devup/application.rb', line 32

def load_env
  if defined? ActiveSupport::Notifications
    Dotenv.instrumenter = ActiveSupport::Notifications
    ActiveSupport::Notifications.subscribe(/^dotenv/) do |*args|
      event = ActiveSupport::Notifications::Event.new(*args)
      Spring.watch event.payload[:env].filename if defined? Spring
    end
  end

  Dotenv.load(*dotenv_list.to_a)
end

#log_levelObject



56
57
58
# File 'lib/devup/application.rb', line 56

def log_level
  ENV.fetch("DEVUP_LOG_LEVEL", dotenv_vars["DEVUP_LOG_LEVEL"] || "info")
end

#runObject



8
9
10
11
# File 'lib/devup/application.rb', line 8

def run
  boot unless devup_disabled?
  load_env
end