Sha256: 3bf9a064bd114970fc1e4e9402c73c21057cf0bf406ecfb33a82d3112884ff44
Contents?: true
Size: 1.57 KB
Versions: 8
Compression:
Stored size: 1.57 KB
Contents
#!/usr/bin/env ruby @root = Pathname.new(File.dirname(__FILE__)).parent.parent.parent.expand_path require @root.join('lib/visage-app/config') require 'yaml' module Visage class Config class File @@config_directories = [] @@config_directories << Pathname.new(::File.dirname(__FILE__)).expand_path @@config_directories << Pathname.new(ENV["CONFIG_PATH"]).expand_path if ENV["CONFIG_PATH"] @@config_directories.reverse! def self.find(filename, opts={}) range = opts[:ignore_bundled] ? (0..-2) : (0..-1) potential_filenames = @@config_directories[range].map {|d| d.join(filename)} potential_filenames.find { |f| ::File.exists?(f) } end def self.load(filename, opts={}) unless path = self.find(filename, opts) if opts[:create] path = @@config_directories.first.join(filename) begin FileUtils.touch(path) rescue Errno::EACCES => e raise Errno::EACCES, "Couldn't write #{path}. Do you have CONFIG_PATH set?" end end end YAML::load_file(path) end def self.open(filename, &block) path = self.find(filename) ::File.open(path, 'r+') do |f| block.call(f) end end def initialize(filename, opts={}) unless ::File.exists?(filename) path = @@config_directories.first.join(filename) FileUtils.touch(path) end @file = ::File.open(filename, 'r+') end def to_s @file.path end end end end
Version data entries
8 entries across 8 versions & 1 rubygems