Class: QAT::Web::PageManager Abstract
- Inherits:
-
Object
- Object
- QAT::Web::PageManager
- Defined in:
- lib/qat/web/page_manager.rb
Overview
Class to represent a Web Site as a collection of Page. These webpages should be all subclasses of a common Page abstract subclass, representing a website’s generic webpage. This abstract class should be used in the manages class definition. Also the initial website’s page should be declared and should be a subclass of the managed domain. To navigate in the website, just call the methods of the current page of the website.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#current_page ⇒ QAT::Web::Page
readonly
Current page object instance.
Class Method Summary collapse
-
.initial_page(page) ⇒ Object
Define the initial page of the chosen managed domain.
-
.manages(page_type) ⇒ Object
Define the domain’s main class to manage.
Instance Method Summary collapse
-
#initialize ⇒ PageManager
constructor
Initialize the page manager.
-
#method_missing(method, *args, &block) ⇒ Object
Forwards all methods to current page.
Constructor Details
#initialize ⇒ PageManager
Initialize the page manager. Will start at the defined initial page.
52 53 54 55 56 57 |
# File 'lib/qat/web/page_manager.rb', line 52 def initialize raise TypeError.new "No page type defined, use class definition 'manages' to define a QAT:Web::Page type to manage" unless @@manages raise TypeError.new "No initial page type defined, use class definition 'initial_page' to define a #{@@manages} type page as initial" unless @@initial_page @current_page = @@initial_page.new end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
Forwards all methods to current page.
64 65 66 67 68 |
# File 'lib/qat/web/page_manager.rb', line 64 def method_missing method, *args, &block result = @current_page.send method, *args, &block @current_page = result if @current_page.class.actions.include? method return result end |
Instance Attribute Details
#current_page ⇒ QAT::Web::Page (readonly)
Returns current page object instance.
60 61 62 |
# File 'lib/qat/web/page_manager.rb', line 60 def current_page @current_page end |
Class Method Details
.initial_page(page) ⇒ Object
Define the initial page of the chosen managed domain.
33 34 35 36 37 38 |
# File 'lib/qat/web/page_manager.rb', line 33 def self.initial_page page raise TypeError.new "Initial page class #{page} is not a QAT::Web::Page subclass" unless page.is_a? Class and page.ancestors.include? QAT::Web::Page raise TypeError.new "Initial page class #{page} is not a #{@@manages} subclass" if @@manages and not page.ancestors.include? @@manages @@initial_page = page end |
.manages(page_type) ⇒ Object
Define the domain’s main class to manage.
44 45 46 47 48 |
# File 'lib/qat/web/page_manager.rb', line 44 def self.manages page_type raise TypeError.new "Manage domain class #{page_type} is not an QAT::Web::Page subclass" unless page_type.is_a? Class and page_type.ancestors.include? QAT::Web::Page @@manages = page_type end |