Class: Absinthe::Distillery::RootNamespace
- Inherits:
-
Object
- Object
- Absinthe::Distillery::RootNamespace
- Defined in:
- lib/absinthe/distillery/context.rb
Defined Under Namespace
Classes: LoadFailed
Instance Attribute Summary collapse
-
#main ⇒ Object
readonly
Returns the value of attribute main.
-
#root ⇒ Object
readonly
Returns the value of attribute root.
Instance Method Summary collapse
- #boot!(ctx) ⇒ Object
-
#initialize(main_object) ⇒ RootNamespace
constructor
A new instance of RootNamespace.
- #load_plugin(name) ⇒ Object
- #require_dir(root, *paths) ⇒ Object
Constructor Details
#initialize(main_object) ⇒ RootNamespace
Returns a new instance of RootNamespace.
7 8 9 10 |
# File 'lib/absinthe/distillery/context.rb', line 7 def initialize main_object @main = main_object @plugins = [] end |
Instance Attribute Details
#main ⇒ Object (readonly)
Returns the value of attribute main.
6 7 8 |
# File 'lib/absinthe/distillery/context.rb', line 6 def main @main end |
#root ⇒ Object (readonly)
Returns the value of attribute root.
6 7 8 |
# File 'lib/absinthe/distillery/context.rb', line 6 def root @root end |
Instance Method Details
#boot!(ctx) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/absinthe/distillery/context.rb', line 12 def boot! ctx @context = ctx @root = Module.new { extend self } # Import ourselves into the new namespace, and remove ourselves from main. @root.const_set :Absinthe, ::Absinthe Object.send :remove_const, :Absinthe root.send(:define_method, :context) { ctx } main.include root (ctx[:calling_context] || main).instance_eval { ctx[:boot_proc].call ctx if ctx[:boot_proc] } end |
#load_plugin(name) ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/absinthe/distillery/context.rb', line 27 def load_plugin name require_dir :plugins, name # HACK not like this! plugin_name = Absinthe::Plugins.constants.grep(/#{name.to_s.gsub('_', '')}/i).first plugin = Absinthe::Plugins.const_get plugin_name plugin end |