Module: Wright::DSL
- Defined in:
- lib/wright/dsl.rb
Overview
Includable Wright script DSL.
Contains resource methods for all registered resources.
Defined Under Namespace
Classes: Util
Class Method Summary collapse
-
.register_resource(resource_class) ⇒ void
Registers a class as a resource.
-
.yield_resource(resource_class, name, args) {|Resource| ... } ⇒ void
private
Instantiates a resource and performs its default action.
Instance Method Summary collapse
-
#util ⇒ Wright::DSL::Util
Supplies access to various useful helper methods.
Class Method Details
.register_resource(resource_class) ⇒ void
This method returns an undefined value.
Registers a class as a resource.
Creates a resource method in the DSL module. Uses the snake-cased class name as method name.
Typically resource_class
is a subclass of Resource. It is initialized with the resource’s name and the attribute hash as arguments.
80 81 82 83 84 85 86 |
# File 'lib/wright/dsl.rb', line 80 def self.register_resource(resource_class) method_name = Wright::Util.class_to_resource_name(resource_class) this_module = self define_method(method_name) do |name, args = {}, &block| this_module.yield_resource(resource_class, name, args, &block) end end |
.yield_resource(resource_class, name, args) {|Resource| ... } ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Instantiates a resource and performs its default action.
Implicitly invoking a block from within another block does not work: blog.sidu.in/2007/11/ruby-blocks-gotchas.html
100 101 102 103 104 105 |
# File 'lib/wright/dsl.rb', line 100 def self.yield_resource(resource_class, name, args) r = resource_class.new(name, args) yield(r) if block_given? r.run_action if r.respond_to?(:run_action) r end |
Instance Method Details
#util ⇒ Wright::DSL::Util
Supplies access to various useful helper methods.
65 66 67 |
# File 'lib/wright/dsl.rb', line 65 def util Wright::DSL::Util.new end |