Cross Reference: router_constraints.rb
xref
: /
ontohub
/
lib
/
router_constraints.rb
Home
History
Annotate
Line#
Navigate
Download
Search
only in
./
router_constraints.rb revision 8e47d6ce64ae5a3392b4d92867b2a83bd0dc9bbe
class
RouterConstraint
def
set_path_parameters
(
request
,
new_params
)
params
=
request.send
(:
env
)
[
"
action_dispatch.request.path
_parameters"
]
controller
=
params
[:
controller
]
action
=
params
[:
action
]
params.except
!
(*
params.keys
)
.
merge
!
(
controller
:
controller
,
action
:
action
)
.
merge
!
(
new_params
)
end
end
class
FilesRouterConstraint
<
RouterConstraint
def
matches
?
(
request
)
return
false
if
Repository.find
_by_path
(
request.params
[:
repository_id
])
.
nil
?
result
= !
RepositoryFile.find
_with_path
(
params_path_without_format
(
request
)
)
.
nil
?
set_params_path_without_format
(
request
)
if
result
return
result
end
protected
def
params_path_without_format
(
request
)
@
params
=
request.send
(:
env
)
[
"
action_dispatch.request.path
_parameters"
]
@
path
= @
params
[:
path
]
@
path
+=
".#{@params[:format]}"
if
@
params
[:
format
]
@
params.merge
(
{
path
: @
path
}).
except
(:
format
)
end
def
set_params_path_without_format
(
request
)
params_path_without_format
(
request
)
@
params.merge
!
(
{
path
: @
path
}).
except
!
(:
format
)
end
end
class
IRIRouterConstraint
<
RouterConstraint
def
matches
?
(
request
)
ontology
=
Ontology.find
_with_iri
(
request.original
_url
)
result
= !
ontology.nil
?
if
result
set_path_parameters
(
request
,
repository_id
:
ontology.repository.to
_param
,
id
:
ontology.id
)
end
return
result
end
end