Class: Util::FS

Inherits:
Object
  • Object
show all
Defined in:
lib/utilities/utils.rb

Overview

B.2. FILE SYSTEM ————————————————————————————————–

Instance Method Summary collapse

Instance Method Details

#clear_directory(path) ⇒ Object

B.2.2. CLEAR THE ENTIRE DIRECTORY



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/utilities/utils.rb', line 111

def clear_directory(path)

  msg = Util::Message.new()

  if isEmpty(path)

    msg.warning("Your directory isn't empty! Konstruct can only be installed in an empty directory.");
    puts Paint["----------------------------------------------------------------------------", :yellow]
    puts ""
    puts Paint["DIRECTORY LISTING: #{path}", :yellow]
    puts ""
    puts Paint[Dir.entries(path), :yellow]
    puts ""
    puts Paint["----------------------------------------------------------------------------", :yellow]
    puts ""
    choice = choose("Do you want to clear your working directory?", :yes, :no)

    if choice == :yes
      `rm -rf *`
      msg.success("Working directory cleared: #{path}")
    else
      msg.error("Konstruct can only be installed in an empty directory.")
      exit(1)
    end

  end

end

#delete_files(path) ⇒ Object

B.2.3. CLEAN DIRECTORY



144
145
146
147
148
149
# File 'lib/utilities/utils.rb', line 144

def delete_files(path)

  msg = Util::Message.new()
  FileUtils.rm_rf(path)

end

#isEmpty(path) ⇒ Object

B.2.1. CHECK FOR EMPTY DIRECTORY



97
98
99
100
101
102
103
104
105
# File 'lib/utilities/utils.rb', line 97

def isEmpty(path)

  if Dir.entries(path).length > 2
    result = true
  else
    result = false
  end

end

#make_dir(dir) ⇒ Object

B.2.3. MAKE DIRECTORY



155
156
157
158
159
160
161
162
163
164
165
166
# File 'lib/utilities/utils.rb', line 155

def make_dir(dir)

  msg = Util::Message.new()

  unless Dir[dir].length > 0

    FileUtils.mkdir(dir)
    msg.success("Created #{dir}")

  end

end

#read_configObject

B.2.4. READ JSON FILE



172
173
174
175
176
177
# File 'lib/utilities/utils.rb', line 172

def read_config

  config_dir = File.expand_path('~/.konstruct')
  YAML.load_file("#{config_dir}/config.yml")

end

#read_project(path) ⇒ Object

B.2.4. READ JSON FILE



183
184
185
186
187
# File 'lib/utilities/utils.rb', line 183

def read_project(path)

  YAML.load_file("#{path}/.konstruct.yml")

end