Module: ActionDispatch::Routing::Mapper::Resources
- Defined in:
- lib/railsdav/routing_extensions.rb
Defined Under Namespace
Classes: WebDAVResource, WebDAVSingletonResource
Instance Method Summary collapse
- #dav_match(*args) ⇒ Object
- #dav_options_response(*allowed_http_verbs) ⇒ Object
-
#resource_scope(resource) ⇒ Object
Rails versions after 3.1 expect two arguments here, the first being :resource, :resources, :webdav_resource etc.so we don’t need the inferring logic anymore in newer versions.
- #resource_scope? ⇒ Boolean
- #webdav_resource(*resources, &block) ⇒ Object
- #webdav_resources(*resources, &block) ⇒ Object
Instance Method Details
#dav_match(*args) ⇒ Object
85 86 87 88 89 90 91 92 93 |
# File 'lib/railsdav/routing_extensions.rb', line 85 def dav_match(*args) get *args if args.last.is_a? Hash # prevents `Invalid route name, already in use` args.last.delete(:as) args.last.delete('as') end dav_propfind *args end |
#dav_options_response(*allowed_http_verbs) ⇒ Object
81 82 83 |
# File 'lib/railsdav/routing_extensions.rb', line 81 def (*allowed_http_verbs) proc { [200, {'Allow' => allowed_http_verbs.flatten.map{|s| s.to_s.upcase}.join(' '), 'DAV' => '1'}, [' ']] } end |
#resource_scope(resource) ⇒ Object
Rails versions after 3.1 expect two arguments here, the first being :resource, :resources, :webdav_resource etc.so we don’t need the inferring logic anymore in newer versions.
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/railsdav/routing_extensions.rb', line 58 def resource_scope(resource) case resource when WebDAVSingletonResource scope_level = :webdav_resource when WebDAVResource scope_level = :webdav_resources when SingletonResource scope_level = :resource when Resource scope_level = :resources end with_scope_level(scope_level, resource) do scope(parent_resource.resource_scope) do yield end end end |
#resource_scope? ⇒ Boolean
76 77 78 |
# File 'lib/railsdav/routing_extensions.rb', line 76 def resource_scope? [:webdav_resource, :webdav_resources, :resource, :resources].include?(@scope[:scope_level] || @scope.scope_level) end |
#webdav_resource(*resources, &block) ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/railsdav/routing_extensions.rb', line 95 def webdav_resource(*resources, &block) = resources..dup if apply_common_behavior_for(:webdav_resource, resources, , &block) return self end sub_block = proc do yield if block_given? if parent_resource.actions.include?(:create) collection do post :create end end if parent_resource.actions.include?(:new) new do get :new end end member do if parent_resource.actions.include?(:show) dav_match :show end get :edit if parent_resource.actions.include?(:edit) put :update if parent_resource.actions.include?(:update) delete :destroy if parent_resource.actions.include?(:destroy) end end if Rails.version < '3.2' resource_scope(WebDAVSingletonResource.new(resources.pop, ), &sub_block) elsif Rails.version < '5.0' resource_scope(:webdav_resource, WebDAVSingletonResource.new(resources.pop, ), &sub_block) else with_scope_level :webdav_resource do resource_scope WebDAVResource.new(resources.pop, api_only?, ), &sub_block end end self end |
#webdav_resources(*resources, &block) ⇒ Object
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 |
# File 'lib/railsdav/routing_extensions.rb', line 140 def webdav_resources(*resources, &block) = resources. if apply_common_behavior_for(:webdav_resources, resources, , &block) return self end sub_block = proc do yield if block_given? opts = [] collection do if parent_resource.actions.include?(:index) dav_match :index opts << [:get, :propfind] end if parent_resource.actions.include?(:create) post :create opts << :post end if parent_resource.actions.include?(:update_all) put :index, :action => :update_all opts << :put end :index, :to => (opts) end if parent_resource.actions.include?(:new) new do dav_match :new put :new, :action => :create :new, :to => (:get, :put, :propfind, :options) end end member do opts = [] if parent_resource.actions.include?(:show) dav_match :show opts << :get opts << :propfind end if parent_resource.actions.include?(:update) put :update opts << :put end if parent_resource.actions.include?(:destroy) delete :destroy opts << :delete end :show, :to => (opts) if parent_resource.actions.include?(:edit) dav_match :edit :edit, :to => (:get, :propfind) end end end if Rails.version < '3.2' resource_scope(WebDAVResource.new(resources.pop, ), &sub_block) elsif Rails.version < '5.0' resource_scope(:webdav_resources, WebDAVResource.new(resources.pop, ), &sub_block) else with_scope_level :webdav_resources do resource_scope WebDAVResource.new(resources.pop, api_only?, ), &sub_block end end self end |