Class: Configuration

Inherits:
Object
  • Object
show all
Includes:
PathCommon
Defined in:
lib/configuration.rb

Constant Summary

Constants included from PathCommon

PathCommon::CONFIG_FILE, PathCommon::PROJECT_DIR

Instance Method Summary collapse

Methods included from PathCommon

#absolute_path, #get_path, #join, #parse_string, #require_p

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



9
10
# File 'lib/configuration.rb', line 9

def initialize
end

Instance Method Details

#add_path(path) ⇒ Object



11
12
13
14
15
16
# File 'lib/configuration.rb', line 11

def add_path(path)
	File.open(CONFIG_FILE,"a") do |file|
	  path.each { |p| file.puts absolute_path(p) }
	end
	list_templates_path
end

#execute(argv) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/configuration.rb', line 31

def execute(argv)
	parameters = argv[1..100] || [Dir.pwd]   	
	action = argv[0]
	add_path(parameters) if action=="add"
	remove_path(parameters) if action == "remove"
	get_default if action == "default"
end

#get_defaultObject



38
39
40
41
42
# File 'lib/configuration.rb', line 38

def get_default
	File.open(CONFIG_FILE,"w") do |file|
	  file.puts "../templates"
	end
end

#listObject



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

def list
	list = []
	get_path.uniq.each do |path|
	  list += Dir.entries(path)
	end
	puts list-[".",".."]
end

#list_templates_pathObject



43
44
45
46
# File 'lib/configuration.rb', line 43

def list_templates_path
	puts "\nNow you get templates path:"
	puts get_path
end

#remove_path(path) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/configuration.rb', line 17

def remove_path(path)
	path_set = get_path - path.collect { |p| p= absolute_path(p) }
  File.open(CONFIG_FILE,"w") do |file|
    path_set.each { |p| file.puts p }
  end
  list_templates_path	
end