Class: Vipergen::FileManager

Inherits:
Object
  • Object
show all
Defined in:
lib/vipergen/filemanager.rb

Overview

File manager class

Class Method Summary collapse

Class Method Details

.copy(from, to) ⇒ Object

Copy a system item to another place



36
37
38
39
40
41
# File 'lib/vipergen/filemanager.rb', line 36

def self.copy(from, to)
	to_expand_path = File.expand_path(to)
	from_expand_path = File.expand_path(from)
	FileUtils.mkdir_p (to_expand_path)
	FileUtils.copy_entry(from_expand_path, to_expand_path)	
end

.destination_viper_path(path, name) ⇒ Object

Returns the destination viper path

Returns:

  • Destination root path



30
31
32
33
# File 'lib/vipergen/filemanager.rb', line 30

def self.destination_viper_path(path, name)
	expand_path = File.expand_path(path)
	return File.join(expand_path,name)
end

.files_in_path(path) ⇒ Object

Returns an array with files in a given path

Returns:

  • Array with the files in a given path



24
25
26
# File 'lib/vipergen/filemanager.rb', line 24

def self.files_in_path(path)
	return Dir[File.join("#{path}","/**/*")].select {|f| File.file?(f)}
end

.is_language_valid(language) ⇒ Object

Returns if the language is valid by the VIPER generator



11
12
13
# File 'lib/vipergen/filemanager.rb', line 11

def self.is_language_valid(language)
	return (Vipergen::Generator::LANGUAGES).include? language
end

.is_template_valid(template) ⇒ Object

Returns if the template is valid by the VIPER generator



6
7
8
# File 'lib/vipergen/filemanager.rb', line 6

def self.is_template_valid(template)
	return Vipergen::TemplateManager.templates.include? template
end

.move(from, to) ⇒ Object

Move a system item to another place



44
45
46
47
48
# File 'lib/vipergen/filemanager.rb', line 44

def self.move(from, to)
	to_expand_path = File.expand_path(to)
	from_expand_path = File.expand_path(from)
	FileUtils.move(from_expand_path, to_expand_path)
end

.path_from(template, language) ⇒ Object

Return the path if valid template and language

Returns:

  • String with valid path



17
18
19
20
# File 'lib/vipergen/filemanager.rb', line 17

def self.path_from(template, language)
	return nil if !is_language_valid(language) || !is_template_valid(template)
	return File.join(Vipergen::TemplateManager.templates_dir, template, language)
end