Class: Absinthe::Distillery::RootNamespace

Inherits:
Object
  • Object
show all
Defined in:
lib/absinthe/distillery/context.rb

Defined Under Namespace

Classes: LoadFailed

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#mainObject (readonly)

Returns the value of attribute main.



6
7
8
# File 'lib/absinthe/distillery/context.rb', line 6

def main
  @main
end

#rootObject (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

#require_dir(root, *paths) ⇒ Object



36
37
38
39
40
# File 'lib/absinthe/distillery/context.rb', line 36

def require_dir root, *paths
  @context[:source_loader].source_files(root, paths) do |file|
    eval_in_scope file
  end
end