RText::Frontend::Config

Constants

ServiceConfig

Public Class Methods

file_pattern(file) click to toggle source
# File lib/rtext/frontend/config.rb, line 23
def self.file_pattern(file)
  ext = File.extname(file)
  if ext.size > 0
    "*#{ext}"
  else
    File.basename(file)
  end
end
find_service_config(file) click to toggle source
# File lib/rtext/frontend/config.rb, line 6
def self.find_service_config(file)
  last_dir = nil
  dir = File.expand_path(File.dirname(file))
  search_pattern = file_pattern(file)
  while dir != last_dir
    config_file = "#{dir}/.rtext"
    if File.exist?(config_file)
      configs = parse_config_file(config_file)
      config = configs.find{|s| s.patterns.any?{|p| p == search_pattern}}
      return config if config
    end
    last_dir = dir
    dir = File.dirname(dir)
  end
  nil
end
parse_config_file(file) click to toggle source
# File lib/rtext/frontend/config.rb, line 34
def self.parse_config_file(file)
  configs = []
  File.open(file) do |f|
    lines = f.readlines
    l = lines.shift
    while l
      if l =~ /^(.+):\s*$/
        patterns = $1.split(",").collect{|s| s.strip} 
        l = lines.shift
        if l && l =~ /\S/ && l !~ /:\s*$/
          configs << ServiceConfig.new(file, patterns, l)
          l = lines.shift
        end
      else
        l = lines.shift
      end
    end
  end
  configs
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.