Class: DTK::Client::Operation::ClientModuleDir
- Inherits:
-
DTK::Client::Operation
show all
- Defined in:
- lib/client/operation/client_module_dir.rb,
lib/client/operation/client_module_dir/git_repo.rb,
lib/client/operation/client_module_dir/service_instance.rb,
lib/client/operation/client_module_dir/git_repo/internal.rb,
lib/client/operation/client_module_dir/service_instance/internal.rb,
lib/client/operation/client_module_dir/service_instance/internal/module_info.rb
Overview
Operations for managing module folders
Defined Under Namespace
Classes: GitRepo, ServiceInstance
Constant Summary
collapse
- NAMESPACE_SEPERATOR =
':'
TYPES
Class Method Summary
collapse
Class Method Details
.create_file_with_content(file_path, content) ⇒ Object
118
119
120
121
|
# File 'lib/client/operation/client_module_dir.rb', line 118
def self.create_file_with_content(file_path, content)
FileUtils.mkdir_p(File.dirname(file_path))
File.open(file_path, 'w') { |f| f << content }
end
|
.create_module_dir(module_type, module_name, opts = {}) ⇒ Object
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
# File 'lib/client/operation/client_module_dir.rb', line 55
def self.create_module_dir(module_type, module_name, opts = {})
path = opts[:path]
unless path
base_module_path = base_path(module_type)
path_parts =
if (module_name.match(/(.*)#{NAMESPACE_SEPERATOR}(.*)/))
[base_module_path, "#{$1}", "#{$2}"]
else
[base_module_path, "#{module_name}"]
end
path = path_parts.compact.join('/')
end
if File.exists?(path)
if opts[:remove_existing]
FileUtils.rm_rf(path)
else
raise Error::Usage, "Directory '#{path}' is not empty; it must be deleted or moved before retrying the command" unless (Dir.entries(path) - %w{ . .. }).empty?
return path
end
end
FileUtils.mkdir_p(path)
path
end
|
.create_module_dir_from_path(path, opts = {}) ⇒ Object
84
85
86
87
88
89
90
91
92
93
94
95
96
|
# File 'lib/client/operation/client_module_dir.rb', line 84
def self.create_module_dir_from_path(path, opts = {})
if File.exists?(path)
if opts[:remove_existing]
FileUtils.rm_rf(path)
else
raise Error::Usage, "Directory '#{path}' is not empty; it must be deleted or moved before retrying the command" unless (Dir.entries(path) - %w{ . .. }).empty?
return path
end
end
FileUtils.mkdir_p(path)
path
end
|
.create_service_dir(service_instance, opts = {}) ⇒ Object
opts can have keys
:backup_if_exist - Boolean (default: false)
:remove_existing - Boolean (default: false)
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/client/operation/client_module_dir.rb', line 31
def self.create_service_dir(service_instance, opts = {})
path = opts[:path]
path = "#{base_path(:service)}/#{service_instance}" if path.nil?
if File.exists?(path)
if opts[:remove_existing]
FileUtils.rm_rf(path)
else
raise Error::Usage, "Directory '#{path}' is not empty; it must be deleted or moved before retrying the command" unless (Dir.entries(path) - %w{ . .. }).empty?
return path
end
end
FileUtils.mkdir_p(path)
path
end
|
.delete_directory_content(path) ⇒ Object
114
115
116
|
# File 'lib/client/operation/client_module_dir.rb', line 114
def self.delete_directory_content(path)
FileUtils.rm_rf(Dir.glob("#{path}/*"))
end
|
.local_dir_exists?(type, name, opts = {}) ⇒ Boolean
98
99
100
|
# File 'lib/client/operation/client_module_dir.rb', line 98
def self.local_dir_exists?(type, name, opts = {})
File.exists?("#{base_path(type)}/#{name}")
end
|
.ret_base_path(type, name) ⇒ Object
102
103
104
|
# File 'lib/client/operation/client_module_dir.rb', line 102
def self.ret_base_path(type, name)
"#{base_path(type)}/#{name}"
end
|
.ret_path_with_current_dir(name) ⇒ Object
106
107
108
|
# File 'lib/client/operation/client_module_dir.rb', line 106
def self.ret_path_with_current_dir(name)
"#{OsUtil.current_dir}/#{name.gsub(':','/')}"
end
|
.rm_f(path) ⇒ Object
110
111
112
|
# File 'lib/client/operation/client_module_dir.rb', line 110
def self.rm_f(path)
FileUtils.rm_rf(path)
end
|