Class: MVCgen::FileManager

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

Overview

File manager class

Class Method Summary collapse

Class Method Details

.copy(from, to) ⇒ Object

Copy a system item to another place



38
39
40
41
42
43
# File 'lib/mvcgen/filemanager.rb', line 38

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, remove_destination = true)	
end

.destination_mvc_path(path, name) ⇒ Object

Returns the destination mvc path

Returns:

  • Destination root path



32
33
34
35
# File 'lib/mvcgen/filemanager.rb', line 32

def self.destination_mvc_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



26
27
28
# File 'lib/mvcgen/filemanager.rb', line 26

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 MVC generator



13
14
15
# File 'lib/mvcgen/filemanager.rb', line 13

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

.is_template_valid(template) ⇒ Object

Returns if the template is valid by the MVC generator



8
9
10
# File 'lib/mvcgen/filemanager.rb', line 8

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

.move(from, to) ⇒ Object

Move a system item to another place



46
47
48
49
50
# File 'lib/mvcgen/filemanager.rb', line 46

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



19
20
21
22
# File 'lib/mvcgen/filemanager.rb', line 19

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