Module: DhEasy::Router::Plugin::Router

Includes:
Core::Plugin::InitializeHook
Included in:
Finisher, DhEasy::Router::Parser, Seeder
Defined in:
lib/dh_easy/router/plugin/router.rb

Overview

Base router providing the basic functionalities from a router.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#local_configObject (readonly)

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



9
10
11
# File 'lib/dh_easy/router/plugin/router.rb', line 9

def local_config
  @local_config
end

Instance Method Details

#class_defined?(name) ⇒ Boolean

Validates when a class name exists

Parameters:

  • name (String)

    Class name to validate.

Returns:

  • (Boolean)

    `true` when exists, else `false`.



58
59
60
# File 'lib/dh_easy/router/plugin/router.rb', line 58

def class_defined? name
  Object.const_defined? name
end

#configHash

Router configuration.

Returns:

  • (Hash)


49
50
51
# File 'lib/dh_easy/router/plugin/router.rb', line 49

def config
  local_config['router']
end

#get_class(name) ⇒ Class?

Get a class from a class name.

Parameters:

  • name (String)

    Class name to validate.

Returns:

  • (Class, nil)

    `nil` when class doesn't exists.



67
68
69
70
# 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(opts = {}) ⇒ Object

Initialize router and hooks.

Parameters:

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

    ({}) Configuration options.

See Also:



42
43
44
# File 'lib/dh_easy/router/plugin/router.rb', line 42

def initialize opts = {}
  initialize_hooks opts
end

#initialize_hook_router_plugin_router(opts = {}) ⇒ Object

Note:

`opts` will be prioritize over `opts` and `opts`.

Hook to initialize router configuration.

Parameters:

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

    ({}) Configuration options.

Options Hash (opts):

  • :config (DhEasy::Config::Local, nil) — default: nil

    Configuration to use.

  • :config_file_path (String) — default: nil

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

  • :force (Boolean) — default: false

    Will reload configuration file when `true`.



24
25
26
27
28
29
30
31
32
33
34
35
# 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