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

Instance Method Details

#chmod(path, mode, config = {}) ⇒ Object



29
30
31
32
33
34
35
# 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

#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



38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/thor-ssh/actions/file_manipulation.rb', line 38

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



52
53
54
55
56
57
58
# File 'lib/thor-ssh/actions/file_manipulation.rb', line 52

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