Class: DAV4Rack::Lock

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

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Lock

Returns a new instance of Lock.



4
5
6
7
8
9
# File 'lib/dav4rack/lock.rb', line 4

def initialize(args={})
  @args = args
  @store = nil
  @args[:created_at] = Time.now
  @args[:updated_at] = Time.now
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(*args) ⇒ Object



30
31
32
33
34
35
36
37
38
# File 'lib/dav4rack/lock.rb', line 30

def method_missing(*args)
  if(@args.has_key?(args.first.to_sym))
    @args[args.first.to_sym]
  elsif(args.first.to_s[-1,1] == '=')
    @args[args.first.to_s[0, args.first.to_s.length - 1].to_sym] = args[1]
  else
    raise NoMethodError.new "Undefined method #{args.first} for #{self}"
  end
end

Instance Method Details

#destroyObject



20
21
22
23
24
# File 'lib/dav4rack/lock.rb', line 20

def destroy
  if(@store)
    @store.remove(self)
  end
end

#remaining_timeoutObject



26
27
28
# File 'lib/dav4rack/lock.rb', line 26

def remaining_timeout
  @args[:timeout].to_i - (Time.now.to_i - @args[:created_at].to_i)
end

#storeObject



11
12
13
# File 'lib/dav4rack/lock.rb', line 11

def store
  @store
end

#store=(s) ⇒ Object



15
16
17
18
# File 'lib/dav4rack/lock.rb', line 15

def store=(s)
  raise TypeError.new 'Expecting LockStore' unless s.respond_to? :remove
  @store = s
end