Class: PageMagic::Transitions
- Defined in:
- lib/page_magic/transitions.rb
Overview
class Transitions - used for registering the page classes that should be used against particular paths
Constant Summary collapse
- REGEXP_MAPPING_MSG =
'URL could not be derived because mapping contains Regexps'
Instance Method Summary collapse
-
#initialize(transitions) ⇒ Transitions
constructor
Create a new transitions object.
-
#mapped_page(url) ⇒ PageMagic
get the page class mapped to the given url.
-
#url_for(page, base_url:) ⇒ Object
get the url to be used when visiting the path mapped against the given page.
Methods inherited from Hash
Constructor Details
#initialize(transitions) ⇒ Transitions
Create a new transitions object.
15 16 17 18 19 20 21 |
# 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 |
Instance Method Details
#mapped_page(url) ⇒ PageMagic
get the page class mapped to the given url
39 40 41 |
# File 'lib/page_magic/transitions.rb', line 39 def mapped_page(url) matches(url).first end |
#url_for(page, base_url:) ⇒ Object
get the url to be used when visiting the path mapped against the given page
29 30 31 32 33 34 |
# 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 |