Class: Nginxtra::Config::SimpleConfig
- Inherits:
-
Object
- Object
- Nginxtra::Config::SimpleConfig
- Defined in:
- lib/nginxtra/config.rb
Overview
A class for encapsulating simple configuration.
Instance Method Summary collapse
-
#find_config_files!(path) ⇒ Object
Find all the config files at the given path directory.
-
#initialize(config, options = {}, &block) ⇒ SimpleConfig
constructor
A new instance of SimpleConfig.
-
#process! ⇒ Object
Process the simple config.
-
#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.
Constructor Details
#initialize(config, options = {}, &block) ⇒ SimpleConfig
Returns a new instance of SimpleConfig.
582 583 584 585 586 |
# File 'lib/nginxtra/config.rb', line 582 def initialize(config, = {}, &block) @config = config @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.
608 609 610 611 612 613 614 615 616 617 618 619 620 621 |
# File 'lib/nginxtra/config.rb', line 608 def find_config_files!(path) files_hash = {} Dir["#{path}/**/*.rb"].select do |x| File.file? x end.map do |x| file_name = x.sub /^#{Regexp.quote "#{path}"}\/(.*)\.rb$/, "\\1" { :path => x, :config_file => file_name } end.each do |x| files_hash[x[:config_file]] = x end files_hash end |
#process! ⇒ Object
Process the simple config.
589 590 591 592 593 594 595 596 597 598 599 600 601 |
# File 'lib/nginxtra/config.rb', line 589 def process! = @config.file_paths.map do |path| find_config_files! path end config_files = .map(&:keys).inject([], &:+).uniq.map do |x| .select do |option| option.include? x end.first[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.
626 627 628 629 630 631 632 633 634 635 636 637 |
# File 'lib/nginxtra/config.rb', line 626 def process_files!(files) files.each do |x| path = x[:path] filename = x[:config_file] = @options block = @block @config.file filename do process_template! path, , block end end end |