Module: Base

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

Class Method Summary collapse

Class Method Details

.create_directory(directory_name, path = INPUT_PATH) ⇒ Object



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

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



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

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 "create file..."
    File.new(file, "a+")
  end
  file
end

.file(filename, file_path = INPUT_PATH) ⇒ Object



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

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)


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

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



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

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



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

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