Module: Thor::Actions
- Defined in:
- lib/thor-ssh/actions/create_file.rb,
lib/thor-ssh/actions/create_link.rb,
lib/thor-ssh/actions/download_file.rb,
lib/thor-ssh/actions/empty_directory.rb,
lib/thor-ssh/actions/inject_into_file.rb,
lib/thor-ssh/actions/file_manipulation.rb
Defined Under Namespace
Classes: CreateFile, CreateLink, DownloadFile, EmptyDirectory, InjectIntoFile
Instance Method Summary
collapse
-
#chmod(path, mode, config = {}) ⇒ Object
-
#chown(user, group, files) ⇒ Object
-
#chown_R(user, group, files) ⇒ Object
-
#get(source, *args) ⇒ Object
Modifies #get to download files remotely, removes the ability to pass a blcok.
-
#gsub_file(path, flag, *args, &block) ⇒ Object
-
#read_file(path) ⇒ Object
-
#remove_file(path, config = {}) ⇒ Object
(also: #remove_dir)
Instance Method Details
#chmod(path, mode, config = {}) ⇒ Object
29
30
31
32
33
34
35
36
|
# File 'lib/thor-ssh/actions/file_manipulation.rb', line 29
def chmod(path, mode, config={})
return unless behavior == :invoke
path = File.expand_path(path, destination_root)
say_status :chmod, relative_to_original_destination_root(path), config.fetch(:verbose, true)
destination_files.chmod(mode, path) unless options[:pretend]
end
|
#chown(user, group, files) ⇒ Object
38
39
40
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/thor-ssh/actions/file_manipulation.rb', line 38
def chown(user, group, files)
unless options[:pretend]
changed, not_changed = destination_files.chown(user, group, files)
not_changed.each do |file|
say_status :chown, file
end
changed.each do |file|
say_status :chown_identical, file, :blue
end
end
end
|
#chown_R(user, group, files) ⇒ Object
52
53
54
|
# File 'lib/thor-ssh/actions/file_manipulation.rb', line 52
def chown_R(user, group, files)
destination_files.chown_R(user, group, files) unless options[:pretend]
end
|
#get(source, *args) ⇒ Object
Modifies #get to download files remotely, removes the ability to pass a blcok
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/thor-ssh/actions/file_manipulation.rb', line 16
def get(source, *args)
config = args.last.is_a?(Hash) ? args.pop : {}
destination = args.first
source = File.expand_path(find_in_source_paths(source.to_s)) unless source =~ /^https?\:\/\//
render = open(source) {|input| input.binmode.read }
destination ||= File.basename(source)
action DownloadFile.new(self, source, destination, config)
end
|
#gsub_file(path, flag, *args, &block) ⇒ Object
57
58
59
60
61
62
63
64
65
66
67
68
69
|
# File 'lib/thor-ssh/actions/file_manipulation.rb', line 57
def gsub_file(path, flag, *args, &block)
return unless behavior == :invoke
config = args.last.is_a?(Hash) ? args.pop : {}
path = File.expand_path(path, destination_root)
say_status :gsub, relative_to_original_destination_root(path), config.fetch(:verbose, true)
unless options[:pretend]
content = destination_files.binread(path)
content.gsub!(flag, *args, &block)
destination_files.binwrite(path, content)
end
end
|
#read_file(path) ⇒ Object
4
5
6
|
# File 'lib/thor-ssh/actions/create_file.rb', line 4
def read_file(path)
destination_files.binread(path)
end
|
#remove_file(path, config = {}) ⇒ Object
Also known as:
remove_dir
71
72
73
74
75
76
77
|
# File 'lib/thor-ssh/actions/file_manipulation.rb', line 71
def remove_file(path, config={})
return unless behavior == :invoke
path = File.expand_path(path, destination_root)
say_status :remove, relative_to_original_destination_root(path), config.fetch(:verbose, true)
destination_files.rm_rf(path) if !options[:pretend] && destination_files.exists?(path)
end
|