require 'dev_environment' require 'dev_git' require 'json' require 'rake' class Projects < Hash attr_accessor :filename def initialize @filename='' end def update self.each{|k,v| self[k]=Project.new(v) if(v.is_a?(String)) self[k]=Project.new(v) if(!v.is_a?(Project) && v.is_a?(Hash)) self[k][:name]=k } end def save filename='' @filename=filename if !filename.nil? && filename.length > 0 File.open(@filename,'w'){|f|f.write(self.to_json)} if @filename.length > 0 end def open filename='' @filename=filename if filename.length > 0 JSON.parse(IO.read(@filename)).each{|k,v| self[k]=v} update end def self.user_projects_filename FileUtils.mkdir("#{Environment.dev_root}/data") if(!File.exists?("#{Environment.dev_root}/data")) "#{Environment.dev_root}/data/PROJECTS.json" end def self.current project=nil if(File.exists?('.git')) if(Rake.application.original_dir.include?('/wrk/') && Git.remote_origin.length > 0) project=Project.new(Git.remote_origin) name=Rake.application.original_dir.gsub("#{Environment.dev_root}/wrk/",'') project[:name] = name if(name.length>0 && !name.include?(Environment.dev_root)) if(defined?(PROJECTS)) PROJECTS[name]=project if(!PROJECTS.has_key?(name)) project.each{|k,v|PROJECTS[name][k]=v} PROJECTS.save else project[:name]=name end end end project end end