Class: Lono::ProjectChecker

Inherits:
Object
  • Object
show all
Defined in:
lib/lono/project_checker.rb

Overview

Checks to see command is running in a lono project. If not, provide a friendly message and possibly exit.

Constant Summary collapse

@@checked =

2 ways to use lono.

1. A standalone project - not available below version 5
2. A multimode project - available after version 5
false

Class Method Summary collapse

Class Method Details

.checkObject



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

def check
  return if @@checked

  unless standalone? or multimode?
    puts "ERROR: Was unable to detect that you are within a lono project. Are you sure you are in lono project?".color(:red)
    quit 1
  end

  @@mode = standalone? ? :standalone : :multimode

  @@checked = true
end

.empty_templatesObject

Dont exit for this one. It’s okay. But show a warning.



45
46
47
48
49
# File 'lib/lono/project_checker.rb', line 45

def empty_templates
  if Dir["#{Lono.config.templates_path}/**/*"].empty?
    puts "INFO: The app/templates folder does not contain any lono template definitions.".color(:yellow)
  end
end

.modeObject



26
27
28
# File 'lib/lono/project_checker.rb', line 26

def mode
  @@mode
end

.multimode?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/lono/project_checker.rb', line 40

def multimode?
  File.exist?("#{Lono.root}/configs/settings.yml")
end

.quit(signal) ⇒ Object



51
52
53
54
55
56
57
# File 'lib/lono/project_checker.rb', line 51

def quit(signal)
  if ENV['TEST'] == '1'
    signal == 0 || raise("Not in lono project")
  else
    exit(signal)
  end
end

.standalone?Boolean

Returns:

  • (Boolean)


30
31
32
33
34
35
36
37
38
# File 'lib/lono/project_checker.rb', line 30

def standalone?
  paths = %w[
    app/definitions
    app/templates
  ]
  paths.all? do |path|
    File.exist?("#{Lono.root}/#{path}")
  end
end