Class: DAV4Rack::InterceptorResource

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

Constant Summary

Constants included from HTTPStatus

HTTPStatus::StatusMessage

Instance Attribute Summary collapse

Attributes inherited from Resource

#propstat_relative_path, #public_path, #request, #response, #root_xml_attributes, #user

Instance Method Summary collapse

Methods inherited from Resource

#allows_redirect?, #get_property, #index_page, #is_ms_client?, #lock, #lock_check, #method_missing, method_missing, #parent, #parent_collection?, #parent_exists?, #properties, #remove_property, #resource_type, #set_property, #supports_locking?, #unlock, #use_compat_mkcol_response?, #use_ms_compat_creationdate?

Constructor Details

#initialize(*args) ⇒ InterceptorResource

Returns a new instance of InterceptorResource.



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

def initialize(*args)
  super
  @root_paths = @options[:mappings].keys
  @mappings = @options[:mappings]
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class DAV4Rack::Resource

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



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

def options
  @options
end

#pathObject (readonly)

Returns the value of attribute path.



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

def path
  @path
end

Instance Method Details

#==(other) ⇒ Object



79
80
81
# File 'lib/dav4rack/interceptor_resource.rb', line 79

def ==(other)
  path == other.path
end

#child(name, option = {}) ⇒ Object



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/dav4rack/interceptor_resource.rb', line 91

def child(name, option={})
  new_path = path.dup
  new_path = '/' + new_path unless new_path[0,1] == '/'
  new_path.slice!(-1) if new_path[-1,1] == '/'
  name = '/' + name unless name[-1,1] == '/'
  new_path = "#{new_path}#{name}"
  new_public = public_path.dup
  new_public = '/' + new_public unless new_public[0,1] == '/'
  new_public.slice!(-1) if new_public[-1,1] == '/'
  new_public = "#{new_public}#{name}"
  if(key = @root_paths.find{|x| new_path =~ /^#{Regexp.escape(x.downcase)}\/?/})
    @mappings[key][:resource_class].new(new_public, new_path.gsub(key, ''), request, response, {:root_uri_path => key, :user => @user}.merge(options).merge(@mappings[key]))
  else
    self.class.new(new_public, new_path, request, response, {:user => @user}.merge(options))
  end
end

#childrenObject



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

def children
  childs = @root_paths.find_all{|x|x =~ /^#{Regexp.escape(@path)}/}
  childs = childs.map{|a| child a.gsub(/^#{Regexp.escape(@path)}/, '').split('/').delete_if{|x|x.empty?}.first }.flatten
end

#collection?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/dav4rack/interceptor_resource.rb', line 19

def collection?
  true if exist?
end

#content_lengthObject



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

def content_length
  0
end

#content_typeObject



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

def content_type
  'text/html'
end

#copy(dest) ⇒ Object

Raises:

  • (Forbidden)


67
68
69
# File 'lib/dav4rack/interceptor_resource.rb', line 67

def copy(dest)
  raise Forbidden
end

#creation_dateObject



27
28
29
# File 'lib/dav4rack/interceptor_resource.rb', line 27

def creation_date
  Time.now
end

#deleteObject

Raises:

  • (Forbidden)


63
64
65
# File 'lib/dav4rack/interceptor_resource.rb', line 63

def delete
  raise Forbidden
end

#descendantsObject



108
109
110
111
112
113
114
115
# File 'lib/dav4rack/interceptor_resource.rb', line 108

def descendants
  list = []
  children.each do |child|
    list << child
    list.concat(child.descendants)
  end
  list
end

#display_nameObject



87
88
89
# File 'lib/dav4rack/interceptor_resource.rb', line 87

def display_name
  ::File.basename(path.to_s)
end

#etagObject



39
40
41
# File 'lib/dav4rack/interceptor_resource.rb', line 39

def etag
  Digest::SHA1.hexdigest(@path)
end

#exist?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/dav4rack/interceptor_resource.rb', line 23

def exist?
  !@root_paths.find_all{|x| x =~ /^#{Regexp.escape(@path)}/}.empty?
end

#get(request, response) ⇒ Object

Raises:

  • (Forbidden)


51
52
53
# File 'lib/dav4rack/interceptor_resource.rb', line 51

def get(request, response)
  raise Forbidden
end

#last_modifiedObject



31
32
33
# File 'lib/dav4rack/interceptor_resource.rb', line 31

def last_modified
  Time.now
end

#last_modified=(time) ⇒ Object



35
36
37
# File 'lib/dav4rack/interceptor_resource.rb', line 35

def last_modified=(time)
  Time.now
end

#make_collectionObject

Raises:

  • (Forbidden)


75
76
77
# File 'lib/dav4rack/interceptor_resource.rb', line 75

def make_collection
  raise Forbidden
end

#move(dest) ⇒ Object

Raises:

  • (Forbidden)


71
72
73
# File 'lib/dav4rack/interceptor_resource.rb', line 71

def move(dest)
  raise Forbidden
end

#nameObject



83
84
85
# File 'lib/dav4rack/interceptor_resource.rb', line 83

def name
  ::File.basename(path)
end

#post(request, response) ⇒ Object

Raises:

  • (Forbidden)


59
60
61
# File 'lib/dav4rack/interceptor_resource.rb', line 59

def post(request, response)
  raise Forbidden
end

#put(request, response) ⇒ Object

Raises:

  • (Forbidden)


55
56
57
# File 'lib/dav4rack/interceptor_resource.rb', line 55

def put(request, response)
  raise Forbidden
end