Class: Nginxtra::Config::Extension
- Inherits:
-
Object
- Object
- Nginxtra::Config::Extension
- Defined in:
- lib/nginxtra/config.rb
Overview
Extension point for other gems or libraries that want to define inline partials. Please see the partial method for usage.
Class Method Summary collapse
-
.clear_partials! ⇒ Object
Clear all partials so far defined.
-
.partial(file, name, &block) ⇒ Object
Define or retrieve the partial for the given nginx config file and partial name.
-
.partial?(file, name) ⇒ Boolean
Determine if there has been a partial defined for the given nginx config file, with the given partial name.
Class Method Details
.clear_partials! ⇒ Object
Clear all partials so far defined. This is mainly for test, but could be called if resetting is so desired.
360 361 362 |
# File 'lib/nginxtra/config.rb', line 360 def clear_partials! @extensions = {} end |
.partial(file, name, &block) ⇒ Object
Define or retrieve the partial for the given nginx config file and partial name. If a block is provided, it is set as the partial, otherwise the partial currently defined for it will be retrieved. The block is expected to take 2 arguments… the arguments hash, and then the block passed in to this definition. Either may be ignored if so desired.
Example usage:
Nginxtra::Config::Extension.partial "nginx.conf", "my_app" do |args, block|
my_app(args[:port] || 80)
some_other_setting "on"
block.call
end
The partial will only be valid for the given config file. It is completely nestable, and other partials may be invoked as well.
345 346 347 348 349 350 351 352 353 354 355 356 |
# File 'lib/nginxtra/config.rb', line 345 def partial(file, name, &block) file = file.to_sym name = name.to_sym @extensions ||= {} @extensions[file] ||= {} if block @extensions[file][name] = block else @extensions[file][name] end end |
.partial?(file, name) ⇒ Boolean
Determine if there has been a partial defined for the given nginx config file, with the given partial name.
322 323 324 325 326 |
# File 'lib/nginxtra/config.rb', line 322 def partial?(file, name) file = file.to_sym name = name.to_sym @extensions && @extensions[file] && @extensions[file][name] end |