Class: Noir::Command::New::GitIgnore

Inherits:
Base::TerminalCommand show all
Defined in:
lib/noir/command/new/gitignore.rb

Defined Under Namespace

Modules: GitIgnoreTexts

Constant Summary collapse

GitIgnoreName =
'.gitignore'
SupportedKinds =
GitIgnoreTexts.constants.map{|c| c.to_s.downcase}.join(' ')

Class Method Summary collapse

Methods inherited from Base::TerminalCommand

sub_commands

Methods inherited from Base::Command

check_command_not_found, description, sub_commands

Class Method Details

.createGitIgnore(text) ⇒ Object



44
45
46
# File 'lib/noir/command/new/gitignore.rb', line 44

def self.createGitIgnore text
  Noir::Command::New.createFile(GitIgnoreName, text)
end

.execute(*args) ⇒ Object



51
52
53
# File 'lib/noir/command/new/gitignore.rb', line 51

def self.execute *args
  createGitIgnore ignore_texts_from_kinds(args)
end

.ignore_texts_from_kinds(kinds) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/noir/command/new/gitignore.rb', line 32

def self.ignore_texts_from_kinds kinds
  kinds = kinds.map(&:downcase).map(&:to_sym)
  if kinds.empty?
    raise "Please input some kinds of ignore\n supported: #{SupportedKinds}"
  end
  unless kinds.all?{|k| GitIgnoreTexts.constants.map(&:downcase).include?(k)}
    raise 'Unsupported kinds'
  end

  kinds.map{|k| GitIgnoreTexts.const_get(GitIgnoreTexts.constants.find{|c| c.downcase == k})}.join("\n")
end