Module: Base

Defined in:
lib/tabbyx/core/base.rb

Class Method Summary collapse

Class Method Details

.create_directory(directory_name, path = INPUT_PATH) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/tabbyx/core/base.rb', line 23

def Base::create_directory(directory_name, path= INPUT_PATH)
  path = File.absolute_path(path)
  directory = File.join(path,"#{directory_name}")
  unless File.directory?(directory)
    Dir.mkdir(directory)
  end
end

.create_file(file_name, file_path = INPUT_PATH) ⇒ Object



31
32
33
34
35
36
37
38
39
# File 'lib/tabbyx/core/base.rb', line 31

def self.create_file(file_name, file_path= INPUT_PATH)
  path = File.absolute_path(file_path)
  file = File.join(path,file_name)
  unless File.exist?(file)
    puts "TABBYX: create file..."
    File.new(file, "a+")
  end
  file
end

.file(filename, file_path = INPUT_PATH) ⇒ Object



47
48
49
50
# File 'lib/tabbyx/core/base.rb', line 47

def self.file(filename,file_path= INPUT_PATH)
  path = File.absolute_path(file_path)
  File.join(path, filename)
end

.file_exists?(filename, file_path = INPUT_PATH) ⇒ Boolean

Returns:

  • (Boolean)


41
42
43
44
45
# File 'lib/tabbyx/core/base.rb', line 41

def self.file_exists?(filename, file_path= INPUT_PATH)
  path = File.absolute_path(file_path)
  file = File.join(path, filename)
  File.exist?(file) ? file : nil
end

.load_yamlsObject

load all yaml files in config folder



7
8
9
10
# File 'lib/tabbyx/core/base.rb', line 7

def Base::load_yamls
  config = File.absolute_path(CONFIG_PATH)
  Dir[File.join(config, '*.yml')].map {|file| [File.basename(file, '.yml').to_s, YAML.load_file(file)]}
end

.read_yaml(filename) ⇒ Object



12
13
14
15
16
17
18
19
20
21
# File 'lib/tabbyx/core/base.rb', line 12

def Base::read_yaml(filename)
  path = File.absolute_path(CONFIG_PATH)
  file = File.join(path,"config","#{filename}.yml")
  if File.exist?(file)
    YAML.load_file(file)
  else
    warn('TABBYX: cannot find the yaml file '+ filename)
    return nil
  end
end