Sha256: 8d78720a310f0671896020d8aac1422693b41058fceafbcbb1d418efa5b344c3

Contents?: true

Size: 1.53 KB

Versions: 22

Compression:

Stored size: 1.53 KB

Contents

require 'dav4rack/lock'
module DAV4Rack
  class LockStore
    class << self
      def create
        @locks_by_path = {}
        @locks_by_token = {}
      end
      def add(lock)
        @locks_by_path[lock.path] = lock
        @locks_by_token[lock.token] = lock
      end
      
      def remove(lock)
        @locks_by_path.delete(lock.path)
        @locks_by_token.delete(lock.token)
      end
    
      def find_by_path(path)
        @locks_by_path.map do |lpath, lock|
          lpath == path && lock.remaining_timeout > 0 ? lock : nil
        end.compact.first
      end
      
      def find_by_token(token)
        @locks_by_token.map do |ltoken, lock|
          ltoken == token && lock.remaining_timeout > 0 ? lock : nil
        end.compact.first
      end
      
      def explicit_locks(path)
        @locks_by_path.map do |lpath, lock|
          lpath == path && lock.remaining_timeout > 0 ? lock : nil
        end.compact
      end
      
      def implicit_locks(path)
        @locks_by_path.map do |lpath, lock|
          lpath =~ /^#{Regexp.escape(path)}/ && lock.remaining_timeout > 0 && lock.depth > 0 ? lock : nil
        end.compact
      end
      
      def explicitly_locked?(path)
        self.explicit_locks(path).size > 0
      end
      
      def implicitly_locked?(path)
        self.implicit_locks(path).size > 0
      end
      
      def generate(path, user, token)
        l = Lock.new(:path => path, :user => user, :token => token)
        l.store = self
        add(l)
        l
      end
    end
  end
end

DAV4Rack::LockStore.create

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
dav4rack-0.3.0 lib/dav4rack/lock_store.rb
dav4rack-0.2.11 lib/dav4rack/lock_store.rb
dav4rack-0.2.10 lib/dav4rack/lock_store.rb
dav4rack-0.2.9 lib/dav4rack/lock_store.rb
dav4rack-0.2.8 lib/dav4rack/lock_store.rb
dav4rack-0.2.7 lib/dav4rack/lock_store.rb
dav4rack-0.2.6 lib/dav4rack/lock_store.rb
dav4rack-0.2.5 lib/dav4rack/lock_store.rb
dav4rack-0.2.4 lib/dav4rack/lock_store.rb
dav4rack-0.2.3 lib/dav4rack/lock_store.rb
dav4rack-0.2.2 lib/dav4rack/lock_store.rb
dav4rack-0.2.1 lib/dav4rack/lock_store.rb
dav4rack-0.2.0 lib/dav4rack/lock_store.rb
dav4rack-0.1.8 lib/dav4rack/lock_store.rb
dav4rack-0.1.7 lib/dav4rack/lock_store.rb
dav4rack-0.1.6 lib/dav4rack/lock_store.rb
dav4rack-0.1.5 lib/dav4rack/lock_store.rb
dav4rack-0.1.4 lib/dav4rack/lock_store.rb
dav4rack-0.1.3 lib/dav4rack/lock_store.rb
dav4rack-0.1.2 lib/dav4rack/lock_store.rb