Cross Reference: router_constraints.rb
xref
: /
ontohub
/
lib
/
router_constraints.rb
Home
History
Annotate
Line#
Navigate
Download
Search
only in
./
router_constraints.rb revision d9a3935fa80ce492e782d17ec22825d1708dea97
50
N/A
class
RouterConstraint
50
N/A
def
set_path_parameters
(
request
,
new_params
)
50
N/A
params
=
request.send
(:
env
)
[
"
action_dispatch.request.path
_parameters"
]
50
N/A
controller
=
params
[:
controller
]
50
N/A
action
=
params
[:
action
]
50
N/A
50
N/A
params.except
!
(*
params.keys
)
.
merge
!
(
50
N/A
controller
:
controller
,
50
N/A
action
:
action
)
.
merge
!
(
new_params
)
50
N/A
end
50
N/A
end
50
N/A
50
N/A
50
N/A
class
FilesRouterConstraint
<
RouterConstraint
50
N/A
def
matches
?
(
request
)
50
N/A
return
false
if
Repository.find
_by_path
(
request.params
[:
repository_id
])
.
nil
?
50
N/A
50
N/A
result
= !
RepositoryFile.find
_with_path
(
50
N/A
params_path_without_format
(
request
)
)
.
nil
?
50
N/A
50
N/A
set_params_path_without_format
(
request
)
if
result
50
N/A
50
N/A
return
result
50
N/A
end
50
N/A
60
N/A
protected
202
N/A
def
params_path_without_format
(
request
)
50
N/A
@
params
=
request.send
(:
env
)
[
"
action_dispatch.request.path
_parameters"
]
50
N/A
@
path
= @
params
[:
path
]
235
N/A
@
path
+=
".#{@params[:format]}"
if
@
params
[:
format
]
72
N/A
119
N/A
@
params.merge
(
{
path
: @
path
}).
except
(:
format
)
235
N/A
end
50
N/A
50
N/A
def
set_params_path_without_format
(
request
)
50
N/A
params_path_without_format
(
request
)
50
N/A
@
params.merge
!
(
{
path
: @
path
}).
except
!
(:
format
)
66
N/A
end
135
N/A
end
66
N/A
66
N/A
50
N/A
class
IRIRouterConstraint
<
RouterConstraint
235
N/A
def
matches
?
(
request
)
50
N/A
ontology
=
Ontology.find
_with_iri
(
request.original
_url
)
50
N/A
result
= !
ontology.nil
?
72
N/A
72
N/A
if
result
50
N/A
set_path_parameters
(
request
,
50
N/A
repository_id
:
ontology.repository.to
_param
,
id
:
ontology.id
)
235
N/A
end
50
N/A
50
N/A
return
result
50
N/A
end
235
N/A
end
235
N/A
235
N/A
class
MIMERouterConstraint
<
RouterConstraint
63
N/A
attr_accessor
:
mime_types
72
N/A
72
N/A
def
initialize
(*
mime_types
)
202
N/A
self.mime
_types
=
mime_types.flatten.map
{ |m|
Mime
::
Type.lookup
(m)
}
72
N/A
super
()
72
N/A
end
72
N/A
63
N/A
def
matches
?
(
request
)
50
N/A
mime_types.any
?
{ |m|
request.accepts.first
== m }
50
N/A
end
50
N/A
end
50
N/A
50
N/A
class
GroupedConstraint
50
N/A
attr_accessor
:
constraints
50
N/A
50
N/A
def
initialize
(*
args
)
195
N/A
self.constraints
=
args.flatten
59
N/A
end
59
N/A
66
N/A
def
matches
?
(
request
)
66
N/A
constraints.all
?
{ |c|
c.matches
?
(
request
)
}
66
N/A
end
66
N/A
end
195
N/A