Class: Syntropy::Module
- Inherits:
-
Object
- Object
- Syntropy::Module
- Defined in:
- lib/syntropy/module.rb
Overview
The Syntropy::Module class implements a reloadable module. A module is a .rb source file that implements a route endpoint, a template, utility methods or any other functionality needed by the web app.
The following instance variables are available to modules:
-
‘@env`: the app environment hash
-
‘@machine`: a reference to the UringMachine instance
-
‘@module_loader`: a reference to the module loader
-
‘@app`: a reference to the app
-
‘@ref`: the module’s logical path (path relative to the app root)
-
‘@logger`: a reference to the app’s logger
In addition, the module code also has access to the MODULE constant which is set to self, and may be used to refer to various methods defined in the module.
Instance Attribute Summary collapse
-
#__dependencies__ ⇒ Object
readonly
Returns the value of attribute __dependencies__.
-
#__export_value__ ⇒ Object
readonly
Returns the value of attribute export_value.
Class Method Summary collapse
-
.load(env, code, fn) ⇒ Object
Loads a module, returning the module instance.
Instance Method Summary collapse
-
#initialize(**env) ⇒ void
constructor
Initializes a module with the given environment hash.
-
#is_collection_module? ⇒ bool
Returns true if the module is a collection module.
-
#page_list(ref) ⇒ Array
Returns a list of pages found at the given ref.
Constructor Details
#initialize(**env) ⇒ void
Initializes a module with the given environment hash.
179 180 181 182 183 184 185 186 187 188 |
# File 'lib/syntropy/module.rb', line 179 def initialize(**env) @env = env @machine = env[:machine] @module_loader = env[:module_loader] @app = env[:app] @ref = env[:ref] @logger = env[:logger] @__dependencies__ = [] singleton_class.const_set(:MODULE, self) end |
Instance Attribute Details
#__dependencies__ ⇒ Object (readonly)
Returns the value of attribute __dependencies__.
190 191 192 |
# File 'lib/syntropy/module.rb', line 190 def __dependencies__ @__dependencies__ end |
#__export_value__ ⇒ Object (readonly)
Returns the value of attribute export_value.
190 191 192 |
# File 'lib/syntropy/module.rb', line 190 def __export_value__ @__export_value__ end |
Class Method Details
.load(env, code, fn) ⇒ Object
Loads a module, returning the module instance
168 169 170 171 172 173 |
# File 'lib/syntropy/module.rb', line 168 def self.load(env, code, fn) m = new(**env) m.instance_eval(code, fn) env[:logger]&.info(message: "Loaded module at #{fn}") m end |
Instance Method Details
#is_collection_module? ⇒ bool
Returns true if the module is a collection module. See also #collection_module!
204 205 206 |
# File 'lib/syntropy/module.rb', line 204 def is_collection_module? @collection_module_p end |
#page_list(ref) ⇒ Array
Returns a list of pages found at the given ref.
196 197 198 |
# File 'lib/syntropy/module.rb', line 196 def page_list(ref) Syntropy.page_list(@env, ref) end |