Class: Syntropy::Module

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**env) ⇒ void

Initializes a module with the given environment hash.

Parameters:

  • 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!

Returns:



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.

Parameters:

  • directory reference

Returns:

  • array of pages found in directory



196
197
198
# File 'lib/syntropy/module.rb', line 196

def page_list(ref)
  Syntropy.page_list(@env, ref)
end