Sha256: e91fb5aac78ad45d7de4fdb9a271503e886cae6dbdbea9dfd2bf7e61180fba29

Contents?: true

Size: 1.3 KB

Versions: 8

Compression:

Stored size: 1.3 KB

Contents

module Trackman
  module Components
    module Diffable
      def diff local, remote 
        to_create = local.select{|a| remote.all? { |s| a.path != s.path } }.map{|a| a.to_remote }
        
        { 
          :create => to_create, 
          :update => define_update(local, remote),  
          :delete => define_deleted(local, remote) do |a| 
            to_create.any?{ |c| c.path.basename == a.path.basename }
          end
        }
      end

      private
        # will not delete an html for now. 
        # this behaviour is to avoid the removal of the default templates.
        def define_deleted local, remote
          to_delete = remote.select do |a| 
            local.all? { |s| s.path != a.path } 
          end

          to_delete.reject{|a| a.path.to_s =~ /.html$/ }.to_a
        end

        def define_update local, remote
          to_update = local.select do |l| 
            remote.any? do |r| 
              path_eql = r.path == l.path
              hash_eql = r.file_hash == l.file_hash 
              vp_eql = r.virtual_path == l.virtual_path

              path_eql && (!hash_eql || !vp_eql)
            end
          end

          to_update.map do |a| 
            sibling = remote.select{|x| x.path == a.path }.first
            a.to_remote(sibling.id)
          end
        end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
trackman-0.6.18 lib/trackman/components/diffable.rb
trackman-0.6.17 lib/trackman/components/diffable.rb
trackman-0.6.16 lib/trackman/components/diffable.rb
trackman-0.6.15 lib/trackman/components/diffable.rb
trackman-0.6.14 lib/trackman/components/diffable.rb
trackman-0.6.13 lib/trackman/components/diffable.rb
trackman-0.6.12 lib/trackman/components/diffable.rb
trackman-0.6.11 lib/trackman/components/diffable.rb