class Externals::Configuration::Configuration
Attributes
file_string[RW]
Public Class Methods
new(file_string = nil, empty = false)
click to toggle source
# File lib/externals/configuration/configuration.rb, line 149 def initialize file_string = nil, empty = false self.file_string = file_string return if empty raise "I was given no file_string" unless file_string titles = [] file_string.each_line {|line| titles << line if line =~ SECTION_TITLE_REGEX} bodies = file_string.split SECTION_TITLE_REGEX_NO_GROUPS if titles.size > 0 && bodies.size > 0 if titles.size + 1 != bodies.size raise "bodies and sections do not match up" end bodies = bodies[1..(bodies.size - 1)] (0...(bodies.size)).each do |index| sections << Section.new(titles[index], bodies[index]) end end end
new_empty()
click to toggle source
# File lib/externals/configuration/configuration.rb, line 145 def self.new_empty new nil, true end
Public Instance Methods
[](title)
click to toggle source
# File lib/externals/configuration/configuration.rb, line 112 def [] title title = title.to_s sections.detect {|section| section.title == title} end
[]=(title, hash)
click to toggle source
# File lib/externals/configuration/configuration.rb, line 117 def []= title, hash add_empty_section title section = self[title] hash.each_pair do |key,value| section[key] = value end end
add_empty_section(title)
click to toggle source
# File lib/externals/configuration/configuration.rb, line 132 def add_empty_section title raise "Section already exists" if self[title] sections << Section.new("[#{title.to_s}]", "") end
all_paths()
click to toggle source
# File lib/externals/configuration/configuration.rb, line 141 def all_paths sections.map(&:title) end
remove_section(sec)
click to toggle source
# File lib/externals/configuration/configuration.rb, line 125 def remove_section sec sec = sections.detect{|section| section.title == sec} raise "No section found in config file for #{sec}" unless sec sections.delete(sec) end
removed_project_paths(other_config)
click to toggle source
# File lib/externals/configuration/configuration.rb, line 137 def removed_project_paths other_config all_paths - other_config.all_paths end
sections()
click to toggle source
# File lib/externals/configuration/configuration.rb, line 108 def sections @sections ||= [] end
to_s()
click to toggle source
# File lib/externals/configuration/configuration.rb, line 179 def to_s sections.map(&:to_s).join("\n\n") end
write(path = ".externals")
click to toggle source
# File lib/externals/configuration/configuration.rb, line 172 def write path = ".externals" raise "no path given" unless path open(path, 'w') do |f| f.write to_s end end