Class: Gokart::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/gokart/base.rb

Direct Known Subclasses

Environment

Instance Method Summary collapse

Instance Method Details

#app_name_valid?Boolean

Returns:

  • (Boolean)


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/gokart/base.rb', line 9

def app_name_valid?
   unless File.stat(@app_parent_path).readable?
   	@logger.fatal("App parent directory is not readable")
   	return false
   end
   unless File.stat(@app_parent_path).writable?
   	@logger.fatal("App parent directory is not writable")
   	return false
   end
   if Dir.exist?(@app_base_path)
   	@logger.fatal("App #{@app_name} directory already exists")
   	return false
   end
   return true
end

#build_appObject



25
26
27
28
29
30
# File 'lib/gokart/base.rb', line 25

def build_app
   return false unless create_dirs()
   return false unless copy_files()

   return true
end

#copy_filesObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/gokart/base.rb', line 44

def copy_files
    Dir.glob(@assets_path.join("**","*"), File::FNM_DOTMATCH).each() do | inFile |
      begin
        outFile = File.join(@app_base_path.to_s(), inFile.partition(@assets_path.to_s)[2])

        next if FileTest::directory?(inFile)
        FileUtils::mkdir_p(File.dirname(outFile)) if (!FileTest::directory?(File.dirname(outFile)))

        FileUtils::cp inFile, outFile
      rescue Exception => e
        @logger.fatal "Failed to copy #{outFile} to #{@app_base_path}, because #{e}"
        return false
      end
    end

  return true
end

#create_dirsObject



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/gokart/base.rb', line 32

def create_dirs
    directories().each() do |dir|
      begin
        FileUtils::mkdir_p dir
      rescue Exception => e
        @logger.fatal "Failed to create directory #{dir}, because #{e}"
        return false
      end
    end
  return true
end