Class: Peacock::Engine::Ignorer

Inherits:
Object
  • Object
show all
Includes:
Engine
Defined in:
lib/peacock/engine/ignorer.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Engine

#check_and_return_hash, #determine_git_ignore_path, #determine_root_dir, #git_ignore_exists?

Constructor Details

#initialize(opt_hash) ⇒ Ignorer

Returns a new instance of Ignorer.



13
14
15
16
17
18
# File 'lib/peacock/engine/ignorer.rb', line 13

def initialize(opt_hash)
  @hash = check_and_return_hash(opt_hash)
  @logger = Peacock::Logger.new(@hash.verbose?)
  path = determine_git_ignore_path
  @git_ignore = File.open(path, 'a+')
end

Class Method Details

.start_engine(opt_hash) ⇒ Object



8
9
10
11
# File 'lib/peacock/engine/ignorer.rb', line 8

def self.start_engine(opt_hash)
  ignorer = Ignorer.new(opt_hash)
  ignorer.workflow
end

Instance Method Details

#check_and_write(str) ⇒ Object



45
46
47
48
49
50
51
52
# File 'lib/peacock/engine/ignorer.rb', line 45

def check_and_write(str)
  unless entry_exists?(str)
    @git_ignore.write(str + "\n")
    @logger.ignore(str)
  end

  @git_ignore.rewind
end

#entry_exists?(entry) ⇒ Boolean

Returns:

  • (Boolean)


54
55
56
57
58
59
# File 'lib/peacock/engine/ignorer.rb', line 54

def entry_exists?(entry)
  @git_ignore.each do |line|
    return true if line.chomp == entry
  end
  false
end

#ignore_directoriesObject



33
34
35
36
37
# File 'lib/peacock/engine/ignorer.rb', line 33

def ignore_directories
  @hash.dirs.each do |dir|
    check_and_write(dir)
  end
end

#ignore_filesObject



39
40
41
42
43
# File 'lib/peacock/engine/ignorer.rb', line 39

def ignore_files
  @hash.files.each do |file|
    check_and_write(file)
  end
end

#ignore_files_and_directoriesObject



28
29
30
31
# File 'lib/peacock/engine/ignorer.rb', line 28

def ignore_files_and_directories
  ignore_files
  ignore_directories
end

#workflowObject



20
21
22
23
24
25
26
# File 'lib/peacock/engine/ignorer.rb', line 20

def workflow
  Git.commit_all('peacock: before .gitignore commit')
  ignore_files_and_directories
  Git.clear_cache
  Git.commit_all('peacock: after .gitignore commit')
  @git_ignore.close
end