Class: Util::FS

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

Overview

  1. FILE SYSTEM +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Instance Method Summary collapse

Instance Method Details

#clear_directory(path) ⇒ Object

B.2.2. CLEAR THE ENTIRE DIRECTORY



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

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 ""
    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



140
141
142
143
144
145
# File 'lib/utilities/utils.rb', line 140

def delete_files(path)

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

end

#isEmpty(path) ⇒ Object

B.2.1. CHECK FOR EMPTY DIRECTORY



100
101
102
103
104
105
106
107
108
# File 'lib/utilities/utils.rb', line 100

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



151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/utilities/utils.rb', line 151

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



168
169
170
171
172
173
# File 'lib/utilities/utils.rb', line 168

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



179
180
181
182
183
# File 'lib/utilities/utils.rb', line 179

def read_project(path)

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

end