Class: Rails::Hyperdrive::InstallShell
- Inherits:
-
Object
- Object
- Rails::Hyperdrive::InstallShell
- Defined in:
- lib/rails/hyperdrive/install_shell.rb
Instance Attribute Summary collapse
-
#root ⇒ Object
readonly
Returns the value of attribute root.
Instance Method Summary collapse
- #append_to_file(path, content) ⇒ Object
- #create_file(path, content) ⇒ Object
-
#initialize(root:, io: nil, pretend: false) ⇒ InstallShell
constructor
A new instance of InstallShell.
- #remove_file(path) ⇒ Object
- #say(message = "") ⇒ Object
- #say_status(kind, message, _color = nil) ⇒ Object
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.(root.to_s) @io = io @pretend = pretend end |
Instance Attribute Details
#root ⇒ Object (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( = "") @io&.puts() end |
#say_status(kind, message, _color = nil) ⇒ Object
34 35 36 |
# File 'lib/rails/hyperdrive/install_shell.rb', line 34 def say_status(kind, , _color = nil) @io&.puts(format("%12s %s", kind, )) end |