Class: Jets::Thor::ProjectCheck

Inherits:
Object
  • Object
show all
Defined in:
lib/jets/thor/project_check.rb

Defined Under Namespace

Classes: NotProjectError

Constant Summary collapse

@@no_project_command =

Tricky: Thor load the command and then the subcommand. IE: jets generate:event

@args = ["generate", "event"] # first pass
@args = ["event"]             # second pass

We only check first pass to see if it is a no_project_command. And cache it so the second pass never occurs.

nil

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ ProjectCheck

Returns a new instance of ProjectCheck.



5
6
7
# File 'lib/jets/thor/project_check.rb', line 5

def initialize(args)
  @args = args
end

Instance Method Details

#check!Object

Raises:



9
10
11
12
# File 'lib/jets/thor/project_check.rb', line 9

def check!
  return if no_project_command? || project?
  raise NotProjectError, "Not a Jets project. Please run this command from a Jets project folder."
end

#no_project_command?Boolean

Returns:

  • (Boolean)


25
26
27
28
# File 'lib/jets/thor/project_check.rb', line 25

def no_project_command?
  return @@no_project_command unless @@no_project_command.nil?
  @@no_project_command = (no_project_commands & @args).any? || @args.empty?
end

#no_project_commandsObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/jets/thor/project_check.rb', line 30

def no_project_commands
  # generate for generate:event
  # Allow generate in case `jets init` has not been called yet and user
  # can generate event classes before `jets init` is called.
  #
  # The delete command is a special case. It is allowed to run without a project
  # in an empty folder. This is because the delete command is used to clean up
  # Jets API deployment record.
  commands = %w[
    delete
    generate
    init
    login
    logout
    projects
    version
  ]
  commands + Jets::Thor::Base.help_flags + Jets::Thor::Base.version_flags
end

#project?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/jets/thor/project_check.rb', line 14

def project?
  File.exist?("config/jets")
end