module DhEasy::Router::Plugin::Router

Base router providing the basic functionalities from a router.

Attributes

local_config[R]

Local configuration (see DhEasy::Core::Config).

Public Class Methods

new(opts = {}) click to toggle source

Initialize router and hooks.

@param [Hash] opts ({}) Configuration options.

@see initialize_hook_router_plugin_router

# File lib/dh_easy/router/plugin/router.rb, line 42
def initialize opts = {}
  initialize_hooks opts
end

Public Instance Methods

class_defined?(name) click to toggle source

Validates when a class name exists

@param [String] name Class name to validate.

@return [Boolean] `true` when exists, else `false`.

# File lib/dh_easy/router/plugin/router.rb, line 58
def class_defined? name
  Object.const_defined? name
end
config() click to toggle source

Router configuration.

@return [Hash]

# File lib/dh_easy/router/plugin/router.rb, line 49
def config
  local_config['router']
end
get_class(name) click to toggle source

Get a class from a class name.

@param [String] name Class name to validate.

@return [Class,nil] `nil` when class doesn't exists.

# File lib/dh_easy/router/plugin/router.rb, line 67
def get_class name
  return nil unless class_defined? name
  Object.const_get name
end
initialize_hook_router_plugin_router(opts = {}) click to toggle source

Hook to initialize router configuration.

@param [Hash] opts ({}) Configuration options. @option opts [DhEasy::Config::Local,nil] :config (nil) Configuration to

use.

@option opts [String] :config_file_path (nil) Configuration file to

load when no +:config+ was provided (see
DhEasy::Core::Config#file_path for default file).

@option opts [Boolean] :force (false) Will reload configuration file

when `true`.

@note `opts` will be prioritize over

`opts[:config_file_path]` and `opts[:force]`.
# File lib/dh_easy/router/plugin/router.rb, line 24
def initialize_hook_router_plugin_router opts = {}
  opts = {
    config: nil,
    config_file_path: nil,
    force: false
  }.merge opts
  @local_config = opts[:config]
  @local_config ||= DhEasy::Config::Local.new(
    file_path: opts[:config_file_path],
    force: opts[:force]
  )
end