class PageMagic::Transitions
class Transitions
- used for registering the page classes that should be used against particular paths
Constants
- REGEXP_MAPPING_MSG
Public Class Methods
new(transitions)
click to toggle source
Create a new transitions object. @param [Hash{String,PageMagic::Mapping => PageMagic}] transitions a map of paths to pages @example
Transitions.new('/path1' => Page1, Matcher.new('/another_*') => AnotherPageClass )
Calls superclass method
# File lib/page_magic/transitions.rb, line 15 def initialize(transitions) super transitions.each do |key, value| key = key.is_a?(Mapping) ? key : Mapping.new(key) self[key] = value end end
Public Instance Methods
mapped_page(url)
click to toggle source
get the page class mapped to the given url @param [String] url - the url to search against @return [PageMagic]
# File lib/page_magic/transitions.rb, line 39 def mapped_page(url) matches(url).first end
url_for(page, base_url:)
click to toggle source
get the url to be used when visiting the path mapped against the given page @param [PageMagic] page - the page class to get the mapped path from @param [String] base_url - the base url of the site to be joined to the mapped path @return String @raise InvalidURLException
- Raised if it is not possible to generate the url for the mapped page
i.e. if the mapping is a regular expression.
# File lib/page_magic/transitions.rb, line 29 def url_for(page, base_url:) return unless (mapping = key(page)) raise InvalidURLException, REGEXP_MAPPING_MSG unless mapping.can_compute_uri? PageMagic::Utils::URL.concat(base_url, mapping.compute_uri) end
Private Instance Methods
matches(url)
click to toggle source
# File lib/page_magic/transitions.rb, line 45 def matches(url) keys.find_all { |matcher| matcher.match?(url) }.sort.collect { |match| self[match] } end