Class: Absinthe::Distillery::Context
- Inherits:
-
Object
- Object
- Absinthe::Distillery::Context
- Includes:
- Dsl
- Defined in:
- lib/absinthe/distillery/context.rb
Defined Under Namespace
Modules: Dsl
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#parameters ⇒ Object
readonly
Returns the value of attribute parameters.
Instance Method Summary collapse
- #boot! ⇒ Object
-
#initialize ⇒ Context
constructor
A new instance of Context.
- #inject(name, *args) ⇒ Object
- #plugin!(name) ⇒ Object
- #register(name, clazz, *args) ⇒ Object
Methods included from Dsl
Constructor Details
#initialize ⇒ Context
Returns a new instance of Context.
70 71 72 73 |
# File 'lib/absinthe/distillery/context.rb', line 70 def initialize @parameters = { } @args = { } end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
69 70 71 |
# File 'lib/absinthe/distillery/context.rb', line 69 def args @args end |
#parameters ⇒ Object (readonly)
Returns the value of attribute parameters.
69 70 71 |
# File 'lib/absinthe/distillery/context.rb', line 69 def parameters @parameters end |
Instance Method Details
#boot! ⇒ Object
75 76 77 |
# File 'lib/absinthe/distillery/context.rb', line 75 def boot! inject(:namespace).boot! self end |
#inject(name, *args) ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/absinthe/distillery/context.rb', line 84 def inject name, *args return @parameters[name] unless @parameters[name].is_a?(Class) injections = (@args[name] + args).map do |injection| injection.is_a?(Symbol) ? inject(injection) : injection end @parameters[name].new(*injections).tap do |obj| if obj.respond_to?(:boot!) # anything responding to boot is treated as a singleton service. @parameters[name] = obj case obj.method(:boot!).arity when 0 obj.boot! when 1 obj.boot! self else raise "Invalid boot method for #{name}" end end end end |
#plugin!(name) ⇒ Object
105 106 107 108 109 |
# File 'lib/absinthe/distillery/context.rb', line 105 def plugin! name plugin = inject(:namespace).load_plugin name plugin.register self if plugin.respond_to? :register inject name end |
#register(name, clazz, *args) ⇒ Object
79 80 81 82 |
# File 'lib/absinthe/distillery/context.rb', line 79 def register name, clazz, *args @parameters[name] = clazz @args[name] = args if @parameters[name].is_a?(Class) end |