Class: DAV4Rack::LockStore

Inherits:
Object
  • Object
show all
Defined in:
lib/dav4rack/lock_store.rb

Class Method Summary collapse

Class Method Details

.add(lock) ⇒ Object



9
10
11
12
# File 'lib/dav4rack/lock_store.rb', line 9

def add(lock)
  @locks_by_path[lock.path] = lock
  @locks_by_token[lock.token] = lock
end

.createObject



5
6
7
8
# File 'lib/dav4rack/lock_store.rb', line 5

def create
  @locks_by_path = {}
  @locks_by_token = {}
end

.explicit_locks(path) ⇒ Object



31
32
33
34
35
# File 'lib/dav4rack/lock_store.rb', line 31

def explicit_locks(path)
  @locks_by_path.map do |lpath, lock|
    lpath == path && lock.remaining_timeout > 0 ? lock : nil
  end.compact
end

.explicitly_locked?(path) ⇒ Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/dav4rack/lock_store.rb', line 43

def explicitly_locked?(path)
  self.explicit_locks(path).size > 0
end

.find_by_path(path) ⇒ Object



19
20
21
22
23
# File 'lib/dav4rack/lock_store.rb', line 19

def find_by_path(path)
  @locks_by_path.map do |lpath, lock|
    lpath == path && lock.remaining_timeout > 0 ? lock : nil
  end.compact.first
end

.find_by_token(token) ⇒ Object



25
26
27
28
29
# File 'lib/dav4rack/lock_store.rb', line 25

def find_by_token(token)
  @locks_by_token.map do |ltoken, lock|
    ltoken == token && lock.remaining_timeout > 0 ? lock : nil
  end.compact.first
end

.generate(path, user, token) ⇒ Object



51
52
53
54
55
56
# File 'lib/dav4rack/lock_store.rb', line 51

def generate(path, user, token)
  l = Lock.new(:path => path, :user => user, :token => token)
  l.store = self
  add(l)
  l
end

.implicit_locks(path) ⇒ Object



37
38
39
40
41
# File 'lib/dav4rack/lock_store.rb', line 37

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

.implicitly_locked?(path) ⇒ Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/dav4rack/lock_store.rb', line 47

def implicitly_locked?(path)
  self.implicit_locks(path).size > 0
end

.remove(lock) ⇒ Object



14
15
16
17
# File 'lib/dav4rack/lock_store.rb', line 14

def remove(lock)
  @locks_by_path.delete(lock.path)
  @locks_by_token.delete(lock.token)
end