Class: Corindon::DependencyInjection::Dsl
- Inherits:
-
Object
- Object
- Corindon::DependencyInjection::Dsl
- Defined in:
- lib/corindon/dependency_injection/dsl.rb
Instance Method Summary collapse
- #anonymous! ⇒ Object
- #args(*arguments, **kv_arguments) ⇒ Object
- #call(name, *arguments, **kv_arguments) ⇒ Object
- #exec(context: {}, &block) ⇒ Definition
- #id(id) ⇒ Object
-
#initialize(klass, args: [], kwargs: {}, id: nil, anonymous: false) ⇒ Dsl
constructor
A new instance of Dsl.
- #on(id) ⇒ Token::ServiceCallToken
- #param(key) ⇒ Token::ParameterToken
- #tag(tag) ⇒ Object
- #tagged(tag) ⇒ Token::TaggedToken
- #value(val) ⇒ Token::ValueToken
Constructor Details
#initialize(klass, args: [], kwargs: {}, id: nil, anonymous: false) ⇒ Dsl
Returns a new instance of Dsl.
7 8 9 10 11 12 13 14 15 |
# File 'lib/corindon/dependency_injection/dsl.rb', line 7 def initialize(klass, args: [], kwargs: {}, id: nil, anonymous: false) @klass = klass @args = args @kwargs = kwargs @calls = [] = [] @id = id @anonymous = anonymous end |
Instance Method Details
#anonymous! ⇒ Object
45 46 47 48 |
# File 'lib/corindon/dependency_injection/dsl.rb', line 45 def anonymous! @anonymous = true @id = nil end |
#args(*arguments, **kv_arguments) ⇒ Object
29 30 31 32 |
# File 'lib/corindon/dependency_injection/dsl.rb', line 29 def args(*arguments, **kv_arguments) @args = arguments @kwargs = kv_arguments end |
#call(name, *arguments, **kv_arguments) ⇒ Object
35 36 37 |
# File 'lib/corindon/dependency_injection/dsl.rb', line 35 def call(name, *arguments, **kv_arguments) @calls << [name, arguments, kv_arguments] end |
#exec(context: {}, &block) ⇒ Definition
19 20 21 22 23 24 25 26 27 |
# File 'lib/corindon/dependency_injection/dsl.rb', line 19 def exec(context: {}, &block) if context.is_a?(Hash) context = OpenStruct.new(context) end instance_exec(context, &block) Definition.new(@klass, args: @args, kwargs: @kwargs, calls: @calls, tags: , id: @id, anonymous: @anonymous) end |
#id(id) ⇒ Object
40 41 42 43 |
# File 'lib/corindon/dependency_injection/dsl.rb', line 40 def id(id) @anonymous = false @id = id end |
#on(id) ⇒ Token::ServiceCallToken
62 63 64 |
# File 'lib/corindon/dependency_injection/dsl.rb', line 62 def on(id) Token::ServiceCallToken.new(service: id) end |
#param(key) ⇒ Token::ParameterToken
52 53 54 |
# File 'lib/corindon/dependency_injection/dsl.rb', line 52 def param(key) Token::ParameterToken.new(key: key) end |
#tag(tag) ⇒ Object
57 58 59 |
# File 'lib/corindon/dependency_injection/dsl.rb', line 57 def tag(tag) << tag end |
#tagged(tag) ⇒ Token::TaggedToken
73 74 75 |
# File 'lib/corindon/dependency_injection/dsl.rb', line 73 def tagged(tag) Token::TaggedToken.new(tag) end |
#value(val) ⇒ Token::ValueToken
67 68 69 |
# File 'lib/corindon/dependency_injection/dsl.rb', line 67 def value(val) Token::ValueToken.new(value: val) end |