Class: AddFile

Inherits:
Object
  • Object
show all
Defined in:
lib/envGen/add_file.rb

Class Method Summary collapse

Class Method Details

.dir(dir) ⇒ Object

takes in dir name, adds all Ruby files in dir



88
89
90
91
92
93
94
95
96
# File 'lib/envGen/add_file.rb', line 88

def self.dir(dir) # takes in dir name, adds all Ruby files in dir
  files = self.findRuby(dir)
  # binding.pry
  files.each do |file|
    if file.include?(".rb") && File.file?(file)
      self.single(file)
    end
  end
end

.findRuby(dir) ⇒ Object

find all of the Ruby files in the current dir/sub dirs



78
79
80
81
82
83
84
85
86
# File 'lib/envGen/add_file.rb', line 78

def self.findRuby(dir) # find all of the Ruby files in the current dir/sub dirs
  rubyFiles = []
  Find.find(dir) do |path|
    if File.extname(path) == ".rb"
      rubyFiles << path # and compile a list
    end
  end
  rubyFiles
end

.multiple(*input) ⇒ Object

handles writing files



72
73
74
75
76
# File 'lib/envGen/add_file.rb', line 72

def self.multiple(*input) # handles writing files
  input.flatten.each do |f|
    single(f)
  end
end

.single(input) ⇒ Object

handles writing files



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/envGen/add_file.rb', line 55

def self.single(input) # handles writing files
  # binding.pry
  new_file = PrepareFile.createIfNotInConfig(input)
  if new_file # if not nil
    # binding.pry
    if File.file?(new_file.file) # check if file with full path of new_file
      if new_file.isRuby?
        new_file.write
      else
        new_file.notRuby
      end
    else
      puts "'#{new_file.fileName}' not found"
    end
  end
end