Class: Thm::FileServices

Inherits:
Object
  • Object
show all
Defined in:
lib/thm/fileservices.rb

Instance Method Summary collapse

Constructor Details

#initializeFileServices



6
7
8
# File 'lib/thm/fileservices.rb', line 6

def initialize
  @fdata = String.new
end

Instance Method Details

#conf_loader(file = "config.rb", loadswitch = true) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/thm/fileservices.rb', line 10

def conf_loader(file="config.rb", loadswitch=true)
  file ||= file
  if !File.exists?("#{Dir.home}/.thm/#{file}")
    File.open("#{Dir.home}/.thm/#{file}", 'w') {|n|
      n.write(@fdata)
    }
  end
  begin
    if loadswitch == true
      require Dir.home+"/.thm/#{file}"
    end
   rescue
    puts "Failed to load something went wrong check permissions !"
  end
end

#thmhome?(file = "config.rb") ⇒ Boolean



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/thm/fileservices.rb', line 26

def thmhome?(file="config.rb")
  file ||= file
  if Dir.exists?("#{Dir.home}/.thm") == false
    Dir.mkdir("#{Dir.home}/.thm")
    puts "Creating .thm home subfolder copying config.rb"
  #puts "#{File.getwd}"
    File.open(File.expand_path(File.join(File.dirname(__FILE__), "../../#{file}")), 'r') {|n|
      n.each_line {|l|
        @fdata << l
      }
    }
  end
  begin
  #puts "FDATA: #{@fdata}"
  #puts "Begin"
    conf_loader("#{file}")
    conf_loader("config-original.rb", false)
  rescue
    puts "Error loading config from home directory"
  end
end