Class: Statistrano::Remote::File
- Inherits:
-
Object
- Object
- Statistrano::Remote::File
- Defined in:
- lib/statistrano/remote/file.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#permissions ⇒ Object
readonly
Returns the value of attribute permissions.
-
#remote ⇒ Object
readonly
Returns the value of attribute remote.
Instance Method Summary collapse
- #append_content!(new_content) ⇒ Object
- #content ⇒ Object
- #destroy! ⇒ Object
-
#initialize(path, remote, permissions = 644) ⇒ File
constructor
A new instance of File.
- #update_content!(new_content) ⇒ Object
Constructor Details
#initialize(path, remote, permissions = 644) ⇒ File
Returns a new instance of File.
8 9 10 11 12 |
# File 'lib/statistrano/remote/file.rb', line 8 def initialize path, remote, =644 @path = path @remote = remote @permissions = end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
6 7 8 |
# File 'lib/statistrano/remote/file.rb', line 6 def path @path end |
#permissions ⇒ Object (readonly)
Returns the value of attribute permissions.
6 7 8 |
# File 'lib/statistrano/remote/file.rb', line 6 def @permissions end |
#remote ⇒ Object (readonly)
Returns the value of attribute remote.
6 7 8 |
# File 'lib/statistrano/remote/file.rb', line 6 def remote @remote end |
Instance Method Details
#append_content!(new_content) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/statistrano/remote/file.rb', line 35 def append_content! new_content create_remote_file unless remote_file_exists? resp = remote.run "echo '#{new_content}' >> #{path}" if resp.success? Log.info :success, "appended content to file at #{path} on #{remote.config.hostname}" else Log.error "problem appending content to file at #{path} on #{remote.config.hostname}", resp.stderr end end |
#content ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/statistrano/remote/file.rb', line 14 def content resp = remote.run "cat #{path}" if resp.success? resp.stdout else "" end end |
#destroy! ⇒ Object
47 48 49 50 51 52 53 54 55 |
# File 'lib/statistrano/remote/file.rb', line 47 def destroy! resp = remote.run "rm #{path}" if resp.success? Log.info :success, "file at #{path} on #{remote.config.hostname} removed" else Log.error "failed to remove #{path} on #{remote.config.hostname}", resp.stderr end end |
#update_content!(new_content) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/statistrano/remote/file.rb', line 23 def update_content! new_content create_remote_file unless remote_file_exists? resp = remote.run "echo '#{new_content}' > #{path}" if resp.success? Log.info :success, "file at #{path} on #{remote.config.hostname} saved" else Log.error "problem saving the file #{path} on #{remote.config.hostname}", resp.stderr end end |