Class: Kozo::DSL
- Inherits:
-
Object
show all
- Defined in:
- lib/kozo/dsl.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(configuration) ⇒ DSL
Returns a new instance of DSL.
7
8
9
|
# File 'lib/kozo/dsl.rb', line 7
def initialize(configuration)
@configuration = configuration
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *arguments, &block) ⇒ Object
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/kozo/dsl.rb', line 48
def method_missing(method_name, *arguments, &block)
resource_class = Kozo
.container
.resolve("resource.#{method_name}")
.class
Reference.new(resource_class: resource_class)
rescue Dinja::Container::DependencyNotRegistered
super
end
|
Instance Attribute Details
#configuration ⇒ Object
Returns the value of attribute configuration.
5
6
7
|
# File 'lib/kozo/dsl.rb', line 5
def configuration
@configuration
end
|
Instance Method Details
#backend(type) {|backend| ... } ⇒ Object
15
16
17
18
19
20
21
|
# File 'lib/kozo/dsl.rb', line 15
def backend(type)
backend = resolve(:backend, type, configuration)
yield backend if block_given?
configuration.backend = backend
end
|
#kozo(&_block) ⇒ Object
11
12
13
|
# File 'lib/kozo/dsl.rb', line 11
def kozo(&_block)
yield
end
|
#provider(type) {|provider| ... } ⇒ Object
23
24
25
26
27
28
29
30
31
|
# File 'lib/kozo/dsl.rb', line 23
def provider(type)
provider = resolve(:provider, type)
yield provider if block_given?
provider.setup
configuration.providers[provider.provider_name] = provider
end
|
#resource(type, state_name) {|resource| ... } ⇒ Object
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/kozo/dsl.rb', line 33
def resource(type, state_name)
resource = resolve(:resource, type)
resource.state_name = state_name
raise InvalidResource, "resource #{resource.address} already defined" if configuration.resources.include?(resource)
resource.provider = configuration.providers[resource.provider_name]
raise InvalidResource, "provider #{resource.provider_name} not configured" unless resource.provider
yield resource if block_given?
configuration.resources << resource
end
|
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
59
60
61
|
# File 'lib/kozo/dsl.rb', line 59
def respond_to_missing?(method_name, include_private = false)
Kozo.container.resolve!("resource.#{method_name}").present? || super
end
|