Class: Intranet::Core
- Inherits:
-
Object
- Object
- Intranet::Core
- Defined in:
- lib/intranet/core.rb,
lib/intranet/core/builder.rb,
lib/intranet/core/locales.rb,
lib/intranet/core/servlet.rb,
lib/intranet/core/version.rb,
lib/intranet/core/haml_wrapper.rb
Overview
The core of the Intranet.
Defined Under Namespace
Modules: HamlWrapper
Constant Summary collapse
- NAME =
The name of the gem.
'intranet-core'
- VERSION =
The version of the gem, according to semantic versionning.
'2.5.0'
- HOMEPAGE_URL =
The URL of the gem homepage.
'https://rubygems.org/gems/intranet-core'
- SOURCES_URL =
The URL of the gem source code.
'https://bitbucket.org/ebling-mis/intranet-core'
Instance Attribute Summary collapse
-
#port ⇒ Integer
readonly
The port currently used by the Intranet.
Instance Method Summary collapse
-
#home_url=(url) ⇒ Object
Defines the URL of the home page.
-
#initialize(logger, preferred_port = 80) ⇒ Core
constructor
Initializes a new Intranet core instance.
-
#register_module(responder, path, resources_dir = responder.resources_dir) ⇒ Object
Registers a new module to the core.
-
#start ⇒ Object
Starts the web server.
-
#stop ⇒ Object
Stops the web server and finalizes all registered module responders.
Constructor Details
#initialize(logger, preferred_port = 80) ⇒ Core
Initializes a new Intranet core instance. The first available port will be used, starting at preferred_port
. If preferred_port
port is 80 and the user has not enough priviledges to use that port, port 8080 (or one of the following ports) will be used.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/intranet/core.rb', line 25 def initialize(logger, preferred_port = 80) @logger = logger # Initialize translation module Intranet::Core::Locales.initialize # Initialize HAML wrapper Intranet::Core::HamlWrapper.initialize # Instanciate Intranet Builder and register page builders @builder = Intranet::Core::Builder.new(@logger) # Instanciate WebRick HTTP server @server = load_http_server(preferred_port) www_dir = File.join(__dir__, 'resources', 'www') mount_default_servlets(www_dir) end |
Instance Attribute Details
#port ⇒ Integer (readonly)
The port currently used by the Intranet.
18 19 20 |
# File 'lib/intranet/core.rb', line 18 def port @port end |
Instance Method Details
#home_url=(url) ⇒ Object
Defines the URL of the home page.
67 68 69 |
# File 'lib/intranet/core.rb', line 67 def home_url=(url) @builder.home_url = url end |
#register_module(responder, path, resources_dir = responder.resources_dir) ⇒ Object
Registers a new module to the core. The server must not be running. The module will then be accessible through the given path
under the web server root.
55 56 57 58 59 60 61 62 |
# File 'lib/intranet/core.rb', line 55 def register_module(responder, path, resources_dir = responder.resources_dir) raise Errno::EALREADY if @server.status != :Stop @builder.register(responder, path) module_add_servlet(path, resources_dir) module_add_locales(resources_dir) module_add_haml_templates(resources_dir) end |
#start ⇒ Object
Starts the web server.
72 73 74 75 76 77 |
# File 'lib/intranet/core.rb', line 72 def start @logger.info("Intranet::Core: using locale '#{I18n.default_locale}'") @logger.info("Intranet::Core: running Intranet version #{VERSION}") # Start serving HTTP requests @server.start end |
#stop ⇒ Object
Stops the web server and finalizes all registered module responders.
80 81 82 83 84 85 86 87 |
# File 'lib/intranet/core.rb', line 80 def stop @logger.info('Intranet::Runner: requesting system shutdown...') @server.shutdown while @server.status != :Stop end @builder.finalize @logger.close end |