Class: Nginxtra::Config::Extension

Inherits:
Object
  • Object
show all
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

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.



357
358
359
# File 'lib/nginxtra/config.rb', line 357

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.



342
343
344
345
346
347
348
349
350
351
352
353
# File 'lib/nginxtra/config.rb', line 342

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.

Returns:

  • (Boolean)


319
320
321
322
323
# File 'lib/nginxtra/config.rb', line 319

def partial?(file, name)
  file = file.to_sym
  name = name.to_sym
  @extensions && @extensions[file] && @extensions[file][name]
end