module DhEasy::Router::Plugin::Router
Base router providing the basic functionalities from a router.
Attributes
Local configuration (see DhEasy::Core::Config).
Public Class Methods
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
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
Router
configuration.
@return [Hash]
# File lib/dh_easy/router/plugin/router.rb, line 49 def config local_config['router'] end
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
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