Class: Orats::Common
- Inherits:
-
Object
show all
- Includes:
- UI, Thor::Actions, Thor::Base, Thor::Shell
- Defined in:
- lib/orats/common.rb
Overview
common class that other CLI driven classes subclass
Instance Method Summary
collapse
Methods included from UI
#error, #log, #results, #task
Constructor Details
#initialize(target_path = '', options = {}) ⇒ Common
Returns a new instance of Common.
11
12
13
14
15
16
17
|
# File 'lib/orats/common.rb', line 11
def initialize(target_path = '', options = {})
@target_path = target_path
@options = options
self.destination_root = Dir.pwd
@behavior = :invoke
end
|
Instance Method Details
#base_path ⇒ Object
19
20
21
|
# File 'lib/orats/common.rb', line 19
def base_path
__dir__
end
|
#exit_if_path_exists(extend_path = '') ⇒ Object
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/orats/common.rb', line 32
def exit_if_path_exists(extend_path = '')
task 'Check if path exists'
extended_path = @target_path.dup
unless extend_path.empty?
extended_path = File.join(extended_path, extend_path)
end
return unless Dir.exist?(extended_path) || File.exist?(extended_path)
error 'Path already exists', extended_path
exit 1
end
|
#file_to_string(path) ⇒ Object
23
24
25
26
27
28
29
30
|
# File 'lib/orats/common.rb', line 23
def file_to_string(path)
if File.exist?(path) && File.file?(path)
IO.read path
else
error 'Path not found', path
exit 1
end
end
|