router_constraints.rb revision d9a3935fa80ce492e782d17ec22825d1708dea97
50N/Aclass RouterConstraint
50N/A def set_path_parameters(request, new_params)
50N/A params = request.send(:env)["action_dispatch.request.path_parameters"]
50N/A controller = params[:controller]
50N/A action = params[:action]
50N/A
50N/A params.except!(*params.keys).merge!(
50N/A controller: controller,
50N/A action: action).merge!(new_params)
50N/A end
50N/Aend
50N/A
50N/A
50N/Aclass FilesRouterConstraint < RouterConstraint
50N/A def matches?(request)
50N/A return false if Repository.find_by_path(request.params[:repository_id]).nil?
50N/A
50N/A result = !RepositoryFile.find_with_path(
50N/A params_path_without_format(request)).nil?
50N/A
50N/A set_params_path_without_format(request) if result
50N/A
50N/A return result
50N/A end
50N/A
60N/A protected
202N/A def params_path_without_format(request)
50N/A @params = request.send(:env)["action_dispatch.request.path_parameters"]
50N/A @path = @params[:path]
235N/A @path += ".#{@params[:format]}" if @params[:format]
72N/A
119N/A @params.merge({ path: @path }).except(:format)
235N/A end
50N/A
50N/A def set_params_path_without_format(request)
50N/A params_path_without_format(request)
50N/A @params.merge!({ path: @path }).except!(:format)
66N/A end
135N/Aend
66N/A
66N/A
50N/Aclass IRIRouterConstraint < RouterConstraint
235N/A def matches?(request)
50N/A ontology = Ontology.find_with_iri(request.original_url)
50N/A result = !ontology.nil?
72N/A
72N/A if result
50N/A set_path_parameters(request,
50N/A repository_id: ontology.repository.to_param, id: ontology.id)
235N/A end
50N/A
50N/A return result
50N/A end
235N/Aend
235N/A
235N/Aclass MIMERouterConstraint < RouterConstraint
63N/A attr_accessor :mime_types
72N/A
72N/A def initialize(*mime_types)
202N/A self.mime_types = mime_types.flatten.map { |m| Mime::Type.lookup(m) }
72N/A super()
72N/A end
72N/A
63N/A def matches?(request)
50N/A mime_types.any? { |m| request.accepts.first == m }
50N/A end
50N/Aend
50N/A
50N/Aclass GroupedConstraint
50N/A attr_accessor :constraints
50N/A
50N/A def initialize(*args)
195N/A self.constraints = args.flatten
59N/A end
59N/A
66N/A def matches?(request)
66N/A constraints.all? { |c| c.matches?(request) }
66N/A end
66N/Aend
195N/A