Class: Usmu::Deployment::DirectoryDiff
- Inherits:
-
Object
- Object
- Usmu::Deployment::DirectoryDiff
- Defined in:
- lib/usmu/deployment/directory_diff.rb
Instance Attribute Summary collapse
-
#configuration ⇒ void
readonly
private
Returns the value of attribute configuration.
-
#remote_files ⇒ void
readonly
private
Returns the value of attribute remote_files.
Instance Method Summary collapse
- #check_hash(lhash, rstat) ⇒ void private
- #filter_files(f) ⇒ void private
-
#get_diffs ⇒ Hash
A hash of arrays of filenames:.
-
#initialize(configuration, remote_files) ⇒ DirectoryDiff
constructor
A new instance of DirectoryDiff.
- #local_files_list ⇒ void private
Constructor Details
#initialize(configuration, remote_files) ⇒ DirectoryDiff
Returns a new instance of DirectoryDiff.
8 9 10 11 |
# File 'lib/usmu/deployment/directory_diff.rb', line 8 def initialize(configuration, remote_files) @configuration = configuration @remote_files = remote_files end |
Instance Attribute Details
#configuration ⇒ void (readonly, private)
Returns the value of attribute configuration.
34 35 36 |
# File 'lib/usmu/deployment/directory_diff.rb', line 34 def configuration @configuration end |
#remote_files ⇒ void (readonly, private)
Returns the value of attribute remote_files.
35 36 37 |
# File 'lib/usmu/deployment/directory_diff.rb', line 35 def remote_files @remote_files end |
Instance Method Details
#check_hash(lhash, rstat) ⇒ void (private)
48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/usmu/deployment/directory_diff.rb', line 48 def check_hash(lhash, rstat) if not rstat[:md5].nil? rhash = rstat[:md5] Digest::MD5.hexdigest(lhash).eql? rhash elsif not rstat[:sha1].nil? rhash = rstat[:sha1] Digest::SHA1.hexdigest(lhash).eql? rhash else true end end |
#filter_files(f) ⇒ void (private)
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/usmu/deployment/directory_diff.rb', line 37 def filter_files(f) lstat = File.stat("#{@configuration.destination_path}/#{f}") rstat = @remote_files.stat(f) lhash = File.read("#{@configuration.destination_path}/#{f}") hash_comparison = !check_hash(lhash, rstat) time_comparison = lstat.mtime > rstat[:mtime] time_comparison || hash_comparison end |
#get_diffs ⇒ Hash
Returns A hash of arrays of filenames:
:local
- local-only files:remote
- remote-only files:updated
- files that were updated.
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/usmu/deployment/directory_diff.rb', line 19 def get_diffs local_files = local_files_list remote_files = @remote_files.files_list updated_files = (local_files & remote_files).select &method(:filter_files) { :local => local_files - remote_files, :remote => remote_files - local_files, :updated => updated_files, } end |
#local_files_list ⇒ void (private)
60 61 62 63 64 |
# File 'lib/usmu/deployment/directory_diff.rb', line 60 def local_files_list Dir[@configuration.destination_path + '/**/{*,.??*}']. select {|f| not File.directory? f }. map {|f| f[(@configuration.destination_path.length + 1), f.length]} end |