Class: Nginxtra::Config::SimpleConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/nginxtra/config.rb

Overview

A class for encapsulating simple configuration.

Instance Method Summary collapse

Constructor Details

#initialize(config, options = {}, &block) ⇒ SimpleConfig

Returns a new instance of SimpleConfig.



580
581
582
583
584
# File 'lib/nginxtra/config.rb', line 580

def initialize(config, options = {}, &block)
  @config = config
  @options = options
  @block = block
end

Instance Method Details

#find_config_files!(path) ⇒ Object

Find all the config files at the given path directory. The result will be a hash of hashes. The key on the outer hash is the output config file name, while the value is a hash of :path to the original file path, and :config_file to the output config file name.



606
607
608
609
610
611
612
613
614
615
616
# File 'lib/nginxtra/config.rb', line 606

def find_config_files!(path)
  files_hash = {}

  Dir["#{path}/**/*.rb"].each do |x|
    next unless File.file? x
    file_name = x.sub %r{^#{Regexp.quote path.to_s}/(.*)\.rb$}, "\\1"
    files_hash[file_name] = { path: x, config_file: file_name }
  end

  files_hash
end

#process!Object

Process the simple config.



587
588
589
590
591
592
593
594
595
596
597
598
599
# File 'lib/nginxtra/config.rb', line 587

def process!
  file_options = @config.file_paths.map do |path|
    find_config_files! path
  end

  config_files = file_options.map(&:keys).inject([], &:+).uniq.map do |x|
    file_options.find do |option|
      option.include? x
    end[x]
  end

  process_files! config_files
end

#process_files!(files) ⇒ Object

Process all config files passed in, where each is a hash with :path to the original path of the file, and :config_file to the output config file name.



621
622
623
624
625
626
627
628
629
630
631
632
# File 'lib/nginxtra/config.rb', line 621

def process_files!(files)
  files.each do |x|
    path = x[:path]
    filename = x[:config_file]
    options = @options
    block = @block

    @config.file filename do
      process_template! path, options, block
    end
  end
end