Module: RubyJS::Helper

Defined in:
lib/ruby_js/helper.rb

Class Method Summary collapse

Class Method Details

.absolute_path(path_f, path_options, prefix) ⇒ Object



38
39
40
41
42
# File 'lib/ruby_js/helper.rb', line 38

def self.absolute_path path_f, path_options, prefix
  path_ffr = path_f.sub("#{Dir.pwd}/", '').sub(path_options[:path_s], '').sub(Constants::FILE_TYPE, prefix)
  path_ffa = File.join(path_options[:path_o], path_ffr)
  path_ffa
end

.create_dir(path) ⇒ Object



44
45
46
47
48
# File 'lib/ruby_js/helper.rb', line 44

def self.create_dir path
  unless Dir.exist? path
    FileUtils.mkdir_p path
  end
end

.event_p(event, path_f = "") ⇒ Object



34
35
36
# File 'lib/ruby_js/helper.rb', line 34

def self.event_p event, path_f = ""
  "#{Time.now.strftime("%l:%M:%S %p").lstrip} [#{Constants::APP_NAME}] #{event} #{path_f}"
end

.free(path_fro) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/ruby_js/helper.rb', line 26

def self.free path_fro
  # File
  File.delete(path_fro) if File.exist? path_fro
  # Dir
  path_dro = File.dirname(path_fro)
  Dir.delete(path_dro) if Dir.empty? path_dro
end

.open(path) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/ruby_js/helper.rb', line 5

def self.open path
  result = ""

  if File.exist? path
    File.open path do |f|
      result = f.read
    end
  end

  result
end

.write(path_o, content) ⇒ Object



17
18
19
20
21
22
23
24
# File 'lib/ruby_js/helper.rb', line 17

def self.write path_o, content
  path_od = File.dirname(path_o)
  create_dir(path_od)

  file = File.new(path_o, "w+")
  file.write content
  file.close
end