Class: Syntropy::ModuleContext

Inherits:
Object
  • Object
show all
Defined in:
lib/syntropy/module_loader.rb

Overview

The Syntropy::ModuleContext class provides a context for loading a 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

Instance Method Summary collapse

Constructor Details

#initialize(env, code, fn, extensions) ⇒ void

Initializes a module with the given environment hash.

Parameters:

  • env (Hash)

    environment hash

  • code (String)

    module source code

  • fn (String)

    module filename

  • extensions (Array<Module>, Module)


254
255
256
257
258
259
260
261
262
263
264
265
266
# File 'lib/syntropy/module_loader.rb', line 254

def initialize(env, code, fn, extensions)
  @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)

  apply_extensions(extensions)
  instance_eval(code, fn)
end

Instance Attribute Details

#__dependencies__Object (readonly)

Returns the value of attribute __dependencies__.



268
269
270
# File 'lib/syntropy/module_loader.rb', line 268

def __dependencies__
  @__dependencies__
end

#__export_value__Object (readonly)

Returns the value of attribute export_value.



268
269
270
# File 'lib/syntropy/module_loader.rb', line 268

def __export_value__
  @__export_value__
end

Instance Method Details

#collection_module?bool

Returns true if the module is a collection module. See also #collection_module!

Returns:

  • (bool)


274
275
276
# File 'lib/syntropy/module_loader.rb', line 274

def collection_module?
  @collection_module_p
end