Module: RText::Frontend::Config
- Defined in:
- lib/rtext/frontend/config.rb
Defined Under Namespace
Classes: ServiceConfig
Class Method Summary collapse
Class Method Details
.file_pattern(file) ⇒ Object
23 24 25 26 27 28 29 30 |
# 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) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/rtext/frontend/config.rb', line 6 def self.find_service_config(file) last_dir = nil dir = File.(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) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# 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 |