Class: Rails::Hyperdrive::InstallShell

Inherits:
Object
  • Object
show all
Defined in:
lib/rails/hyperdrive/install_shell.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root:, io: nil, pretend: false) ⇒ InstallShell

Returns a new instance of InstallShell.



8
9
10
11
12
# File 'lib/rails/hyperdrive/install_shell.rb', line 8

def initialize(root:, io: nil, pretend: false)
  @root = File.expand_path(root.to_s)
  @io = io
  @pretend = pretend
end

Instance Attribute Details

#rootObject (readonly)

Returns the value of attribute root.



6
7
8
# File 'lib/rails/hyperdrive/install_shell.rb', line 6

def root
  @root
end

Instance Method Details

#append_to_file(path, content) ⇒ Object



28
29
30
31
32
# File 'lib/rails/hyperdrive/install_shell.rb', line 28

def append_to_file(path, content)
  abs = File.join(@root, path)
  File.open(abs, "a") { |f| f.write(content) } unless @pretend
  say_status(:append, path)
end

#create_file(path, content) ⇒ Object



14
15
16
17
18
19
20
21
# File 'lib/rails/hyperdrive/install_shell.rb', line 14

def create_file(path, content)
  abs = File.join(@root, path)
  unless @pretend
    FileUtils.mkdir_p(File.dirname(abs))
    File.write(abs, content)
  end
  say_status(:create, path)
end

#remove_file(path) ⇒ Object



23
24
25
26
# File 'lib/rails/hyperdrive/install_shell.rb', line 23

def remove_file(path)
  FileUtils.rm_rf(File.join(@root, path)) unless @pretend
  say_status(:remove, path)
end

#say(message = "") ⇒ Object



38
39
40
# File 'lib/rails/hyperdrive/install_shell.rb', line 38

def say(message = "")
  @io&.puts(message)
end

#say_status(kind, message, _color = nil) ⇒ Object



34
35
36
# File 'lib/rails/hyperdrive/install_shell.rb', line 34

def say_status(kind, message, _color = nil)
  @io&.puts(format("%12s  %s", kind, message))
end