Class: RackWebDAV::FileResourceLock
- Inherits:
- 
      Object
      
        - Object
- RackWebDAV::FileResourceLock
 
- Defined in:
- lib/rack-webdav/file_resource_lock.rb
Instance Attribute Summary collapse
- 
  
    
      #created_at  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    Returns the value of attribute created_at. 
- 
  
    
      #depth  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    Returns the value of attribute depth. 
- 
  
    
      #kind  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    Returns the value of attribute kind. 
- 
  
    
      #owner  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    Returns the value of attribute owner. 
- 
  
    
      #path  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    Returns the value of attribute path. 
- 
  
    
      #root  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    Returns the value of attribute root. 
- 
  
    
      #scope  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    Returns the value of attribute scope. 
- 
  
    
      #timeout  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    Returns the value of attribute timeout. 
- 
  
    
      #token  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    Returns the value of attribute token. 
- 
  
    
      #user  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    Returns the value of attribute user. 
Class Method Summary collapse
- .explicit_locks(path, croot, args = {}) ⇒ Object
- .explicitly_locked?(path, croot = nil) ⇒ Boolean
- .find_by_path(path, croot = nil) ⇒ Object
- .find_by_token(token, croot = nil) ⇒ Object
- .generate(path, user, token, croot) ⇒ Object
- .implicitly_locked?(path, croot = nil) ⇒ Boolean
- .implict_locks(path) ⇒ Object
- .init_pstore(croot) ⇒ Object
- .root ⇒ Object
- .root=(path) ⇒ Object
Instance Method Summary collapse
- #destroy ⇒ Object
- 
  
    
      #initialize(args = {})  ⇒ FileResourceLock 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    A new instance of FileResourceLock. 
- #owner?(user) ⇒ Boolean
- #reload ⇒ Object
- #remaining_timeout ⇒ Object
- #save ⇒ Object
Constructor Details
#initialize(args = {}) ⇒ FileResourceLock
Returns a new instance of FileResourceLock.
| 95 96 97 98 99 100 101 102 103 104 | # File 'lib/rack-webdav/file_resource_lock.rb', line 95 def initialize(args={}) @path = args[:path] @root = args[:root] @owner = args[:owner] @store = init_pstore(@root) @max_timeout = args[:max_timeout] || 86400 @default_timeout = args[:max_timeout] || 60 load_if_exists! @new_record = true if token.nil? end | 
Instance Attribute Details
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
| 13 14 15 | # File 'lib/rack-webdav/file_resource_lock.rb', line 13 def created_at @created_at end | 
#depth ⇒ Object
Returns the value of attribute depth.
| 8 9 10 | # File 'lib/rack-webdav/file_resource_lock.rb', line 8 def depth @depth end | 
#kind ⇒ Object
Returns the value of attribute kind.
| 11 12 13 | # File 'lib/rack-webdav/file_resource_lock.rb', line 11 def kind @kind end | 
#owner ⇒ Object
Returns the value of attribute owner.
| 12 13 14 | # File 'lib/rack-webdav/file_resource_lock.rb', line 12 def owner @owner end | 
#path ⇒ Object
Returns the value of attribute path.
| 5 6 7 | # File 'lib/rack-webdav/file_resource_lock.rb', line 5 def path @path end | 
#root ⇒ Object (readonly)
Returns the value of attribute root.
| 14 15 16 | # File 'lib/rack-webdav/file_resource_lock.rb', line 14 def root @root end | 
#scope ⇒ Object
Returns the value of attribute scope.
| 10 11 12 | # File 'lib/rack-webdav/file_resource_lock.rb', line 10 def scope @scope end | 
#timeout ⇒ Object
Returns the value of attribute timeout.
| 7 8 9 | # File 'lib/rack-webdav/file_resource_lock.rb', line 7 def timeout @timeout end | 
#token ⇒ Object
Returns the value of attribute token.
| 6 7 8 | # File 'lib/rack-webdav/file_resource_lock.rb', line 6 def token @token end | 
#user ⇒ Object
Returns the value of attribute user.
| 9 10 11 | # File 'lib/rack-webdav/file_resource_lock.rb', line 9 def user @user end | 
Class Method Details
.explicit_locks(path, croot, args = {}) ⇒ Object
| 33 34 | # File 'lib/rack-webdav/file_resource_lock.rb', line 33 def explicit_locks(path, croot, args={}) end | 
.explicitly_locked?(path, croot = nil) ⇒ Boolean
| 17 18 19 20 21 22 | # File 'lib/rack-webdav/file_resource_lock.rb', line 17 def explicitly_locked?(path, croot=nil) store = init_pstore(croot) !!store.transaction(true){ store[:paths][path] } end | 
.find_by_path(path, croot = nil) ⇒ Object
| 39 40 41 42 | # File 'lib/rack-webdav/file_resource_lock.rb', line 39 def find_by_path(path, croot=nil) lock = self.class.new(:path => path, :root => croot) lock.token.nil? ? nil : lock end | 
.find_by_token(token, croot = nil) ⇒ Object
| 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | # File 'lib/rack-webdav/file_resource_lock.rb', line 44 def find_by_token(token, croot=nil) store = init_pstore(croot) struct = store.transaction(true){ store[:tokens][token] } if !struct struct = store.transaction(true) { store[:tokens].keys.each { |k| token = k if k.include?(token) } store[:tokens][token] } end if struct self.new(:path => struct[:path], :root => croot) else nil end end | 
.generate(path, user, token, croot) ⇒ Object
| 63 64 65 66 67 68 69 70 | # File 'lib/rack-webdav/file_resource_lock.rb', line 63 def generate(path, user, token, croot) lock = self.new(:root => croot) lock.user = user lock.path = path lock.token = token lock.save lock end | 
.implicitly_locked?(path, croot = nil) ⇒ Boolean
| 24 25 26 27 28 29 30 31 | # File 'lib/rack-webdav/file_resource_lock.rb', line 24 def implicitly_locked?(path, croot=nil) store = init_pstore(croot) !!store.transaction(true){ store[:paths].keys.detect do |check| check.start_with?(path) end } end | 
.implict_locks(path) ⇒ Object
| 36 37 | # File 'lib/rack-webdav/file_resource_lock.rb', line 36 def implict_locks(path) end | 
.init_pstore(croot) ⇒ Object
| 80 81 82 83 84 85 86 87 88 89 90 91 92 | # File 'lib/rack-webdav/file_resource_lock.rb', line 80 def init_pstore(croot) path = File.join(croot, '.attribs', 'locks.pstore') FileUtils.mkdir_p(File.dirname(path)) unless File.directory?(File.dirname(path)) store = IS_18 ? PStore.new(path) : PStore.new(path, true) store.transaction do unless(store[:paths]) store[:paths] = {} store[:tokens] = {} store.commit end end store end | 
.root ⇒ Object
| 76 77 78 | # File 'lib/rack-webdav/file_resource_lock.rb', line 76 def root @root || '/tmp/rack-webdav' end | 
.root=(path) ⇒ Object
| 72 73 74 | # File 'lib/rack-webdav/file_resource_lock.rb', line 72 def root=(path) @root = path end | 
Instance Method Details
#destroy ⇒ Object
| 138 139 140 141 142 143 144 145 | # File 'lib/rack-webdav/file_resource_lock.rb', line 138 def destroy @store.transaction do @store[:paths].delete(path) @store[:tokens].delete(token) @store.commit end nil end | 
#owner?(user) ⇒ Boolean
| 106 107 108 | # File 'lib/rack-webdav/file_resource_lock.rb', line 106 def owner?(user) user == owner end | 
#reload ⇒ Object
| 110 111 112 113 | # File 'lib/rack-webdav/file_resource_lock.rb', line 110 def reload load_if_exists self end | 
#remaining_timeout ⇒ Object
| 115 116 117 118 | # File 'lib/rack-webdav/file_resource_lock.rb', line 115 def remaining_timeout t = timeout.to_i - (Time.now.to_i - created_at.to_i) t < 0 ? 0 : t end | 
#save ⇒ Object
| 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 | # File 'lib/rack-webdav/file_resource_lock.rb', line 120 def save struct = { :path => path, :token => token, :timeout => timeout, :depth => depth, :created_at => Time.now, :owner => owner } @store.transaction do @store[:paths][path] = struct @store[:tokens][token] = struct @store.commit end @new_record = false self end |