Class: Aef::FileTransferMatcher
- Inherits:
-
Object
- Object
- Aef::FileTransferMatcher
- Defined in:
- lib/file_transfer_matchers/file_transfer_matcher.rb
Instance Method Summary (collapse)
- - (Object) failure_message
-
- (FileTransferMatcher) initialize(from, options)
constructor
A new instance of FileTransferMatcher.
- - (Boolean) matches?(event_proc)
- - (Object) negative_failure_message
- - (Object) raise_block_syntax_error
Constructor Details
- (FileTransferMatcher) initialize(from, options)
A new instance of FileTransferMatcher
26 27 28 29 30 31 32 33 |
# File 'lib/file_transfer_matchers/file_transfer_matcher.rb', line 26 def initialize(from, ) @from = from @to = [:to] @copy_mode = [:copy_mode] @overwrite = [:overwrite] raise 'A target must be given in copy mode' if @copy_mode and not @to end |
Instance Method Details
- (Object) failure_message
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/file_transfer_matchers/file_transfer_matcher.rb', line 59 def case @error when SourceNotExistentError if @copy_mode "File #{@from} could not be copied, as it does not exist" elsif @to "File #{@from} could not be moved, as it does not exist" else "File #{@from} could not be deleted, as it does not exist" end when TargetAlreadyExistentError if @copy_mode "File #{@from} could not be copied, as target #{@to} already exists" else "File #{@from} could not be moved, as target #{@to} already exists" end when TargetNotExistentError if @copy_mode "File #{@from} should have been copied to #{@to}, but target wasn't created" else "File #{@from} should have been moved to #{@to}, but target wasn't created" end when SourceStillExistentError if @to "File #{@from} should have been moved, but source file still exists" else "File #{@from} should have been deleted, but source file still exists" end end end |
- (Boolean) matches?(event_proc)
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/file_transfer_matchers/file_transfer_matcher.rb', line 35 def matches?(event_proc) raise_block_syntax_error if block_given? raise SourceNotExistentError unless File.exist?(@from) raise TargetAlreadyExistentError if @to and File.exist?(@to) and not @overwrite event_proc.call raise TargetNotExistentError if @to and not File.exist?(@to) raise SourceStillExistentError if not @copy_mode and File.exist?(@from) true rescue FileTransferMatcherError @error = $! false end |
- (Object) negative_failure_message
90 91 92 93 94 95 96 97 98 |
# File 'lib/file_transfer_matchers/file_transfer_matcher.rb', line 90 def if @copy_mode "File #{@from} was copied to #{@to}" elsif @to "File #{@from} was moved to #{@to}" else "File #{@from} was deleted" end end |
- (Object) raise_block_syntax_error
52 53 54 55 56 57 |
# File 'lib/file_transfer_matchers/file_transfer_matcher.rb', line 52 def raise_block_syntax_error raise MatcherError.new(<<-MESSAGE block passed to should or should_not move/copy/delete must use {} instead of do/end MESSAGE ) end |