Class: RubyClone::RSync
- Inherits:
-
Object
- Object
- RubyClone::RSync
- Defined in:
- lib/ruby_clone/rsync.rb
Instance Attribute Summary collapse
-
#dry_run ⇒ Object
writeonly
Sets the attribute dry_run.
Instance Method Summary collapse
- #exclude_pattern=(path) ⇒ Object
- #include_pattern=(path) ⇒ Object
-
#initialize(output) ⇒ RSync
constructor
A new instance of RSync.
- #last_profile ⇒ Object
- #profiles=(profile) ⇒ Object
- #rsync_command(profile_name) ⇒ Object
- #run(profile_name) ⇒ Object
- #update_configurations(configurations) ⇒ Object
Constructor Details
#initialize(output) ⇒ RSync
Returns a new instance of RSync.
9 10 11 12 13 14 15 |
# File 'lib/ruby_clone/rsync.rb', line 9 def initialize(output) @configurations = { options: '-Cavh --stats --progress', show_command: true, show_output: true } @exclude_patterns = [] @include_patterns = [] @output = output @profiles = {} end |
Instance Attribute Details
#dry_run=(value) ⇒ Object (writeonly)
Sets the attribute dry_run
7 8 9 |
# File 'lib/ruby_clone/rsync.rb', line 7 def dry_run=(value) @dry_run = value end |
Instance Method Details
#exclude_pattern=(path) ⇒ Object
30 31 32 |
# File 'lib/ruby_clone/rsync.rb', line 30 def exclude_pattern=(path) @exclude_patterns << path end |
#include_pattern=(path) ⇒ Object
34 35 36 |
# File 'lib/ruby_clone/rsync.rb', line 34 def include_pattern=(path) @include_patterns << path end |
#last_profile ⇒ Object
22 23 24 |
# File 'lib/ruby_clone/rsync.rb', line 22 def last_profile @last_profile end |
#profiles=(profile) ⇒ Object
17 18 19 20 |
# File 'lib/ruby_clone/rsync.rb', line 17 def profiles=(profile) @profiles[profile.name] = profile @last_profile = profile end |
#rsync_command(profile_name) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/ruby_clone/rsync.rb', line 38 def rsync_command(profile_name) profile = @profiles[profile_name.to_s] if profile raise SyntaxError, "Empty Profile not allowed for profile #{profile} with no 'from folder'" unless profile.from_folder raise SyntaxError, "Empty Profile not allowed for profile #{profile} with no 'to folder'" unless profile.to_folder create_rsync_command profile else raise ArgumentError, "Profile #{profile_name} not found" end end |
#run(profile_name) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/ruby_clone/rsync.rb', line 51 def run(profile_name) command = rsync_command(profile_name) @output.puts "\n#{command}\n\n" if @configurations[:show_command] run_with_pty command unless @dry_run profile = @profiles[profile_name.to_s] profile.to_folder.delete_files end end |
#update_configurations(configurations) ⇒ Object
26 27 28 |
# File 'lib/ruby_clone/rsync.rb', line 26 def update_configurations(configurations) @configurations.merge! configurations end |