Sha256: af037fe7f7cb55b4076a087b6ec2ead2150eaaf2f5e59950c9e42a9d30471b29
Contents?: true
Size: 1.22 KB
Versions: 1
Compression:
Stored size: 1.22 KB
Contents
# This handles the configuration files of Nutella # It's basically a hash overload that stores into a file require 'json' module Nutella class ConfigHash def initialize(file) @config_file=file end def []=(key,val) hash = loadConfig hash[key]=val storeConfig hash end def [](key) hash = loadConfig hash[key] end def empty? hash = loadConfig hash.empty? end def has_key?(key) hash = loadConfig hash.has_key? key end def to_s hash = loadConfig hash.to_s end def to_h hash = loadConfig hash end private def storeConfig(hash) File.open(@config_file, "w+") do |f| f.write(JSON.pretty_generate(hash)) end File.chmod(0777,@config_file) end def loadConfig begin return JSON.parse IO.read @config_file rescue # File doesn't exist... do nothing Hash.new end end def removeConfigFile File.delete(@config_file) if File.exist?(@config_file) end end def Nutella.config ConfigHash.new(File.dirname(__FILE__)+"/../../config.json") end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
nutella_framework-0.1.2 | lib/config/config.rb |