Class: DhEasy::Router::Finisher

Inherits:
Object
  • Object
show all
Includes:
Plugin::Router
Defined in:
lib/dh_easy/router/finisher.rb

Overview

Finisher router designed to execute all finisher classes.

Instance Attribute Summary

Attributes included from Plugin::Router

#local_config

Instance Method Summary collapse

Methods included from Plugin::Router

#class_defined?, #config, #get_class, #initialize, #initialize_hook_router_plugin_router

Instance Method Details

#route(opts = {}) ⇒ Object

Note:

Requires the route class to implement `finish` instance method.

Execute the finisher class with options as described by router

configuration and calling class's instance `finish` method.

Parameters:

  • opts (Hash) (defaults to: {})

    ({}) Finisher initializer options (see DhEasy::Core::Plugin::Finisher).

Raises:

  • (ArgumentError)

    `opts` is `nil`.

  • (ArgumentError)

    `page_type` doesn't exists within routes.

  • (NameError)

    A class with name equal to route's `class` attribute doesn't exists.



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/dh_easy/router/finisher.rb', line 19

def route opts = {}
  context = opts[:context]
  if opts[:context].nil?
    raise ArgumentError.new('Must send a context to the finisher.')
  end

  class_name = nil
  config['finisher']['routes'].each do |item|
    # Validate class name
    executor_class = get_class item['class']
    if executor_class.nil?
      raise NameError.new("Class \"#{item['class']}\" doesn't exists, check your ae_easy config file.")
    end

    executor_class.new(opts).finish
  end
end