lib/project.rb in dev_projects-0.0.4 vs lib/project.rb in dev_projects-0.0.5
- old
+ new
@@ -1,5 +1,7 @@
+require 'json'
+
class Project < Hash
attr_accessor :filename
def initialize value=''
@filename=''
self[:url]=''
@@ -9,56 +11,9 @@
end
end
def get_latest_unique_id
'51ed9c9d45ba3979c808740d75ba1831c85aff5d'
- end
-
- def self.projects_filename
- FileUtils.mkdir("#{Project.dev_root}/data") if(!File.exists?("#{Project.dev_root}/data"))
- "#{Project.dev_root}/data/PROJECTS.json"
- end
-
- def self.home
- ["USERPROFILE","HOME"].each {|v|
- return ENV[v].gsub('\\','/') unless ENV[v].nil?
- }
- dir="~"
- dir=ENV["HOME"] unless ENV["HOME"].nil?
- dir=ENV["USERPROFILE"].gsub('\\','/') unless ENV["USERPROFILE"].nil?
- return dir
- end
-
- def self.machine
- if !ENV['COMPUTERNAME'].nil?
- return ENV['COMPUTERNAME']
- end
-
- machine = `hostname`
- machine = machine.split('.')[0] if machine.include?('.')
- return machine.strip
- end
-
- def self.user
- return ENV['USER'] if !ENV['USER'].nil? #on Unix
- ENV['USERNAME']
- end
-
- def self.dev_root
- ["DEV_HOME","DEV_ROOT"].each {|v|
- return ENV[v].gsub('\\','/') unless ENV[v].nil?
- }
- dir=home
- return dir
- end
-
- def self.load_projects
- projects=Project.new
- if File.exists?(projects_filename)
- projects=Project.new(JSON.parse(IO.read(projects_filename)))
- @filename=projects_filename
- end
- projects
end
def save
File.open(@filename,'w'){|f|f.write(self.to_json)} if @filename.length > 0
end
\ No newline at end of file