Class: DotfileGroup

Inherits:
Object
  • Object
show all
Defined in:
lib/polka/dotfile_group.rb

Constant Summary collapse

@@all_files =
[]
@@grouped_files =
[]
@@all_other_files_added =
false

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(operation = nil, setup_msg = nil) ⇒ DotfileGroup

Returns a new instance of DotfileGroup.



19
20
21
22
23
24
# File 'lib/polka/dotfile_group.rb', line 19

def initialize(operation=nil, setup_msg=nil)
  @operation = operation
  @setup_message = setup_msg
  @files = []
  @all_other_files = false
end

Class Method Details

.all_files=(files) ⇒ Object



9
10
11
12
13
# File 'lib/polka/dotfile_group.rb', line 9

def self.all_files=(files)
  @@all_files = files
  @@grouped_files = []
  @@all_other_files_added = false
end

.remaining_filesObject



15
16
17
# File 'lib/polka/dotfile_group.rb', line 15

def self.remaining_files
  @@all_files - @@grouped_files
end

Instance Method Details

#add(new_files) ⇒ Object



26
27
28
29
30
# File 'lib/polka/dotfile_group.rb', line 26

def add(new_files)
  raise FileAlreadyAddedError if new_files.any? { |f| @@grouped_files.include?(f) }
  @@grouped_files += new_files
  @files += new_files
end

#add_all_other_filesObject



32
33
34
35
36
# File 'lib/polka/dotfile_group.rb', line 32

def add_all_other_files
  raise AllOtherFilesAlreadyAdded if @@all_other_files_added
  @@all_other_files_added = true
  @all_other_files = true
end

#filesObject



38
39
40
41
42
43
44
# File 'lib/polka/dotfile_group.rb', line 38

def files
  if @all_other_files
    DotfileGroup.remaining_files + @files
  else
    @files
  end
end

#setupObject



46
47
48
49
# File 'lib/polka/dotfile_group.rb', line 46

def setup
  Polka.log @setup_message.light_blue unless files.empty?
  files.each { |f| f.setup(@operation) }
end