Class: Workarea::Navigation::Redirect
- Inherits:
-
Object
- Object
- Workarea::Navigation::Redirect
show all
- Includes:
- ApplicationDocument
- Defined in:
- app/models/workarea/navigation/redirect.rb
Class Method Summary
collapse
#releasable?
assert_valid_config!, async, disable, enable, inline, #run_callbacks
#embedded_children
Class Method Details
.find_by_path(path) ⇒ Object
17
18
19
|
# File 'app/models/workarea/navigation/redirect.rb', line 17
def self.find_by_path(path)
find_by(path: sanitize_path(path)) rescue nil
end
|
.find_destination(path) ⇒ Object
21
22
23
|
# File 'app/models/workarea/navigation/redirect.rb', line 21
def self.find_destination(path)
find_by_path(path).try(:destination)
end
|
.sanitize_path(path) ⇒ Object
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'app/models/workarea/navigation/redirect.rb', line 35
def self.sanitize_path(path)
encoded_path = if path =~ URI::ESCAPED
path
else
URI.encode(path)
end
uri = URI.parse(encoded_path)
result = uri.path
result = "/#{result}" unless result.starts_with?('/')
result = result[0..-2] if result.ends_with?('/')
result = "#{result}?#{uri.query}" if uri.query.present?
result
end
|
.search(query) ⇒ Object
25
26
27
28
29
30
31
32
33
|
# File 'app/models/workarea/navigation/redirect.rb', line 25
def self.search(query)
return all unless query.present?
regex = /^\/?#{::Regexp.quote(query)}/
any_of(
{ path: regex },
{ destination: regex }
)
end
|