Class: Thm::FileServices

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

Instance Method Summary collapse

Constructor Details

#initializeFileServices

Returns a new instance of FileServices.



15
16
17
# File 'lib/thm/fileservices.rb', line 15

def initialize
  @fdata = String.new
end

Instance Method Details

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



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/thm/fileservices.rb', line 19

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 # So original backup config doesn't change your settings
      require "#{Dir.home}/.thm/#{file}"
    end
  rescue
    puts "Failed to load something went wrong check permissions !"
  end
end

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

Returns:

  • (Boolean)


35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/thm/fileservices.rb', line 35

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