Sha256: 69398e0ce4ccdd42ffb9f2b8183764958df30ce0ec310b66eabe8c065625f4a3

Contents?: true

Size: 1.72 KB

Versions: 5

Compression:

Stored size: 1.72 KB

Contents

require 'json'
require 'rake'
require 'dev_git'
require 'dev_svn'
require 'dev_msbuild'
require 'dev_environment'
require_relative 'project.rb'

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
    		#self[k].update if self[k].respond_to?("update".to_sym)
    	}
    end

	def save filename=''
		@filename=filename if !filename.nil? && filename.length > 0
		File.open(@filename,'w'){|f|f.write(JSON.pretty_generate(self))} 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
		url=Git.remote_origin
		url=Svn.url if url.length==0
		if(Rake.application.original_dir.include?('/wrk/') &&
			   url.length > 0)
			project=Project.new(url)
			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			
		project
	end

	def pull
		self.each{|k,v| v.pull if v.respond_to?("pull".to_sym)}
	end
	def rake
		self.each{|k,v| v.rake if v.respond_to?("rake".to_sym)}
	end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
dev_projects-0.0.26 lib/projects.rb
dev_projects-0.0.25 lib/projects.rb
dev_projects-0.0.24 lib/projects.rb
dev_projects-0.0.23 lib/projects.rb
dev_projects-0.0.22 lib/projects.rb