Class: Absinthe::Plugins::Context
- Inherits:
-
Object
- Object
- Absinthe::Plugins::Context
- Defined in:
- lib/absinthe/plugins/context.rb
Class Method Summary collapse
Instance Method Summary collapse
- #[](name) ⇒ Object
- #boot! ⇒ Object
- #configure(&block) ⇒ Object
- #const(name, value) ⇒ Object
-
#initialize(injector) ⇒ Context
constructor
A new instance of Context.
- #inject(name) ⇒ Object
- #plugin!(name) ⇒ Object
- #register(name, clazz, *args) ⇒ Object
- #run(*args, &block) ⇒ Object
Constructor Details
#initialize(injector) ⇒ Context
Returns a new instance of Context.
8 9 10 11 12 13 |
# File 'lib/absinthe/plugins/context.rb', line 8 def initialize injector @injector = injector @run_blocks = [] self[:namespace].register :context, self instance_exec(&self[:boot_proc]) if self[:boot_proc] end |
Class Method Details
.register(injector) ⇒ Object
4 5 6 |
# File 'lib/absinthe/plugins/context.rb', line 4 def self.register injector injector.register :context, Context, :injector end |
Instance Method Details
#[](name) ⇒ Object
31 32 33 |
# File 'lib/absinthe/plugins/context.rb', line 31 def [] name inject name end |
#boot! ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/absinthe/plugins/context.rb', line 46 def boot! boot_scope = (self[:calling_context] || self[:main_object]) @run_blocks.each do |run| injections = run[:args].map(&method(:inject)) boot_scope.instance_exec(*injections, &run[:block]) end end |
#configure(&block) ⇒ Object
15 16 17 |
# File 'lib/absinthe/plugins/context.rb', line 15 def configure &block self.instance_eval &block end |
#const(name, value) ⇒ Object
19 20 21 |
# File 'lib/absinthe/plugins/context.rb', line 19 def const name, value @injector.register name, value end |
#inject(name) ⇒ Object
27 28 29 |
# File 'lib/absinthe/plugins/context.rb', line 27 def inject name @injector.inject name end |
#plugin!(name) ⇒ Object
35 36 37 |
# File 'lib/absinthe/plugins/context.rb', line 35 def plugin! name self[:plugin].load name end |
#register(name, clazz, *args) ⇒ Object
23 24 25 |
# File 'lib/absinthe/plugins/context.rb', line 23 def register name, clazz, *args @injector.register name, clazz, *args end |
#run(*args, &block) ⇒ Object
39 40 41 42 43 44 |
# File 'lib/absinthe/plugins/context.rb', line 39 def run *args, &block @run_blocks << { :args => args, :block => block } end |