class Geny::Actions::Files

Utilities for manipulating files. @see rubydoc.info/github/piotrmurach/tty-file/master/TTY/File TTY::File

Public Class Methods

new(ui:) click to toggle source
# File lib/geny/actions/files.rb, line 11
def initialize(ui:)
  @ui = ui
end

Public Instance Methods

chdir(path, verbose: true, &block) click to toggle source

Change directory @param path [String]

@example

files.chdir "foo" do
  # do something inside foo/
end
# File lib/geny/actions/files.rb, line 111
def chdir(path, verbose: true, &block)
  @ui.status("cd", path) if verbose
  Dir.chdir(path, &block)
ensure
  @ui.status("cd", "-") if verbose
end
chmod(path, mode, *args, **opts) click to toggle source

Change the permissions of a file @see TTY::File.chmod

@example

files.chmod("bin/test", "+x")
# File lib/geny/actions/files.rb, line 123
def chmod(path, mode, *args, **opts)
  TTY::File.chmod(path, mode, *args, **opts)
end
insert_after(path, pattern, content, **opts) click to toggle source

@see insert

# File lib/geny/actions/files.rb, line 133
def insert_after(path, pattern, content, **opts)
  insert(path, content, after: pattern, **opts)
end
insert_before(path, pattern, content, **opts) click to toggle source

@see insert

# File lib/geny/actions/files.rb, line 128
def insert_before(path, pattern, content, **opts)
  insert(path, content, before: pattern, **opts)
end
move(source, dest, force: false, verbose: true) click to toggle source

Move a file @param source [String] @param dest [String]

@example

files.move "Gemfile", "Gemfile.bak"
# File lib/geny/actions/files.rb, line 99
def move(source, dest, force: false, verbose: true)
  @ui.status("move", source) if verbose
  FileUtils.mv(source, dest, force: force)
end