router_constraints.rb revision 5a102b3c56d4ac75632c7e9244ee0ce5bdbbf13a
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher request.send(:env)["action_dispatch.request.path_parameters"]
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher def set_path_parameters(request, new_params)
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher def add_path_parameters(request, add_params)
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher set_path_parameters(request, params(request).merge(add_params))
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagherclass FilesRouterConstraint < RouterConstraint
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher return false if Repository.find_by_path(request.params[:repository_id]).nil?
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher set_params_path_without_format(request) if result
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher @params = request.send(:env)["action_dispatch.request.path_parameters"]
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher @path += ".#{@params[:format]}" if @params[:format]
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher @params.merge({ path: @path }).except(:format)
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher @params.merge!({ path: @path }).except!(:format)
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagherclass LocIdRouterConstraint < RouterConstraint
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher ELEMENTS_CACHE_CLEARING_INTERVAL = 1.minute
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher @elements_cache_clear_at = Time.now + ELEMENTS_CACHE_CLEARING_INTERVAL
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher # retrieves the hierarchy and member portions of loc/id's
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher hierarchy_member = path.split('?', 2).first.split('///', 2).first
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher LocIdBaseModel.find_with_locid(hierarchy_member)
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher clear_elements_cache if elements_cache_clearing_scheduled?
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher if !elements_cache.key?(hierarchy_member) && element
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher elements_cache[hierarchy_member] = element
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher self.class.instance_variable_get(:@elements_cache)
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher # To keep the memory footprint low in case of unproper removal of cached
07b7b76d7cd494cbd26263503ba2732c21819941Jan Zeleny # elements, we clear the cache periodically. This prevents memory leaks.
e82832a64fd456d1541ce0ea3902bcfb05e69642Stephen Gallagher next_clearing = Time.now + ELEMENTS_CACHE_CLEARING_INTERVAL
14452cd066b51e32ca0ebad6c45ae909a1debe57Jakub Hrozek self.class.instance_variable_set(:@elements_cache_clear_at, next_clearing)
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher self.class.instance_variable_set(:@elements_cache, {})
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher Time.now > self.class.instance_variable_get(:@elements_cache_clear_at)
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher def assign_path_parameters(request, element)
a4cce2c98eedecb5d3b47da62104634cae268434Stephen Gallagher ontology = element.is_a?(Ontology) ? element : element.ontology
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher proof_attempt = element.proof_attempt if @map[:proof_attempt]
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher path_params = {repository_id: ontology.repository.to_param}
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher %i(proof_attempt theorem ontology element).each do |p|
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher path_params[@map[p]] = binding.local_variable_get(p).id if @map[p]
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagherclass RefLocIdRouterConstraint < LocIdRouterConstraint
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher path = Journey::Router::Utils.unescape_uri(request.original_fullpath)
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher result && update_version_id!(request, path.dup)
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher ontology_id = version.try(:ontology).try(:to_param)
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher add_path_parameters(request, id: version_id, ontology_id: ontology_id)
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagherclass MMTRouterConstraint < LocIdRouterConstraint
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher repository_id: ontology.repository.to_param, id: ontology.id)
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagherclass RefIRIRouterConstraint < IRIRouterConstraint
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher # remove the ref/:version_number portion from path
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher path = Journey::Router::Utils.unescape_uri(request.original_fullpath).
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagherclass MIMERouterConstraint < RouterConstraint
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher self.mime_types = mime_types.flatten.map { |m| Mime::Type.lookup(m) }
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher # In some cases request.accepts == [nil] (e.g. cucumber tests),
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher highest_mime ? mime_types.any? { |m| highest_mime == m } : true