Class: Vidibus::Permalink::Dispatcher
- Inherits:
-
Object
- Object
- Vidibus::Permalink::Dispatcher
- Defined in:
- lib/vidibus/permalink/dispatcher.rb
Defined Under Namespace
Classes: PathError
Instance Method Summary collapse
-
#found? ⇒ Boolean
Returns true if all parts could be resolved.
-
#initialize(path, options = {}) ⇒ Dispatcher
constructor
Initialize a new Dispatcher instance.
-
#objects ⇒ Object
Returns permalink objects matching the parts.
-
#parts ⇒ Object
Returns parts of the path.
-
#path ⇒ Object
Returns the path to dispatch.
-
#path=(value) ⇒ Object
Sets path to dispatch.
-
#redirect? ⇒ Boolean
Returns true if any part does not reflect the current permalink of the underlying linkable.
-
#redirect_path ⇒ Object
Returns the path to redirect to, if any.
Constructor Details
#initialize(path, options = {}) ⇒ Dispatcher
Initialize a new Dispatcher instance. Provide an absolute path to be dispatched.
9 10 11 12 |
# File 'lib/vidibus/permalink/dispatcher.rb', line 9 def initialize(path, = {}) self.path = path @scope = [:scope] end |
Instance Method Details
#found? ⇒ Boolean
Returns true if all parts could be resolved.
37 38 39 40 41 |
# File 'lib/vidibus/permalink/dispatcher.rb', line 37 def found? @is_found ||= begin !objects.include?(nil) end end |
#objects ⇒ Object
Returns permalink objects matching the parts.
32 33 34 |
# File 'lib/vidibus/permalink/dispatcher.rb', line 32 def objects @objects ||= resolve_path end |
#parts ⇒ Object
Returns parts of the path. Ignores file extension and request params
27 28 29 |
# File 'lib/vidibus/permalink/dispatcher.rb', line 27 def parts @parts ||= path.gsub(/(\.[^\/]+)?(\?.*)?$/, "").scan(/[^?\/]+/) end |
#path ⇒ Object
Returns the path to dispatch.
15 16 17 |
# File 'lib/vidibus/permalink/dispatcher.rb', line 15 def path @path end |
#path=(value) ⇒ Object
Sets path to dispatch
20 21 22 23 |
# File 'lib/vidibus/permalink/dispatcher.rb', line 20 def path=(value) raise PathError.new("Path must be absolute.") unless value.match(/^\//) @path = value end |
#redirect? ⇒ Boolean
Returns true if any part does not reflect the current permalink of the underlying linkable.
45 46 47 48 49 50 |
# File 'lib/vidibus/permalink/dispatcher.rb', line 45 def redirect? @is_redirect ||= begin return unless found? redirectables.any? end end |
#redirect_path ⇒ Object
Returns the path to redirect to, if any.
53 54 55 56 57 58 |
# File 'lib/vidibus/permalink/dispatcher.rb', line 53 def redirect_path @redirect_path ||= begin return unless redirect? "/" << current_parts.join("/") end end |