Class: QAT::Web::PageManager Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/qat/web/page_manager.rb

Overview

This class is abstract.

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.

Examples:

Sample Website implementation.

class ExampleWebsite < QAT::Web::PageManager

  manages ExampleWebsitePage #Inherits from QAT::Web::Page

  initial_page ExampleLoginPage #Inherits from ExampleWebsitePage

end

site_controller = ExampleWebsite.new
site_controller.current_page # ExampleLoginPage instance
site_controller.
site_controller.current_page # ExampleAuthenticatedPage instance

Since:

  • 1.0.0

Direct Known Subclasses

ProjectName::Web::PageManager

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePageManager

Initialize the page manager. Will start at the defined initial page.

Raises:

  • (TypeError)

    Invalid definition of #manages or #initial_page

Since:

  • 1.0.0



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.

Since:

  • 1.0.0



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_pageQAT::Web::Page (readonly)

Returns current page object instance.

Returns:

Since:

  • 1.0.0



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.

Parameters:

  • page (Class)

    Initial page class. Must be subclass of the class defined in #manages

Raises:

  • (TypeError)

    Invalid class type defined

Since:

  • 1.0.0



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.

Parameters:

  • page_type (Class)

    Domain’s abstract page class. Must be subclass of QAT::Web::Page

Raises:

  • (TypeError)

    Invalid class type defined

Since:

  • 1.0.0



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