dev_projects 0.0.4 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -1 +1,39 @@
1
- # dev_projects.gem
1
+ ## dev_projects <img src="https://badge.fury.io/rb/dev_projects.png" alt="Gem Version" />
2
+
3
+ A ruby gem to assist with management of development projects in git and subversion repositories
4
+
5
+ ### Installation
6
+
7
+ The gem can be installed by the single command
8
+
9
+ ```
10
+ gem install dev_projects
11
+ ```
12
+
13
+ ### Usage
14
+
15
+ This is an example of a simple usage
16
+
17
+ ```
18
+ require 'dev_projects'
19
+
20
+ # add a project
21
+ PROJECTS['github/dev_projects.gem'] = 'https://github.com/lou-parslow/dev_projects.gem.git' if(!PROJECTS.has_key?('github/dev_projects.gem'))
22
+ PROJECTS.save
23
+ ```
24
+
25
+ ### License
26
+ Copyright 2014-2015 Lou Parslow
27
+
28
+ Licensed under the Apache License, Version 2.0 (the "License");
29
+ you may not use this file except in compliance with the License.
30
+ You may obtain a copy of the License at
31
+
32
+ http://www.apache.org/licenses/LICENSE-2.0
33
+
34
+ Unless required by applicable law or agreed to in writing, software
35
+ distributed under the License is distributed on an "AS IS" BASIS,
36
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
37
+ See the License for the specific language governing permissions and
38
+ limitations under the License.
39
+
data/lib/dev_projects.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  #require 'dev_environment'
2
- require_relative 'project.rb'
2
+ require_relative 'projects.rb'
3
3
 
4
- PROJECTS=Project.load_projects
4
+ PROJECTS=Projects.new
5
+ PROJECTS.open Projects.user_projects_filename if File.exists? Projects.user_projects_filename
data/lib/project.rb CHANGED
@@ -1,3 +1,5 @@
1
+ require 'json'
2
+
1
3
  class Project < Hash
2
4
  attr_accessor :filename
3
5
  def initialize value=''
@@ -13,53 +15,6 @@ attr_accessor :filename
13
15
  '51ed9c9d45ba3979c808740d75ba1831c85aff5d'
14
16
  end
15
17
 
16
- def self.projects_filename
17
- FileUtils.mkdir("#{Project.dev_root}/data") if(!File.exists?("#{Project.dev_root}/data"))
18
- "#{Project.dev_root}/data/PROJECTS.json"
19
- end
20
-
21
- def self.home
22
- ["USERPROFILE","HOME"].each {|v|
23
- return ENV[v].gsub('\\','/') unless ENV[v].nil?
24
- }
25
- dir="~"
26
- dir=ENV["HOME"] unless ENV["HOME"].nil?
27
- dir=ENV["USERPROFILE"].gsub('\\','/') unless ENV["USERPROFILE"].nil?
28
- return dir
29
- end
30
-
31
- def self.machine
32
- if !ENV['COMPUTERNAME'].nil?
33
- return ENV['COMPUTERNAME']
34
- end
35
-
36
- machine = `hostname`
37
- machine = machine.split('.')[0] if machine.include?('.')
38
- return machine.strip
39
- end
40
-
41
- def self.user
42
- return ENV['USER'] if !ENV['USER'].nil? #on Unix
43
- ENV['USERNAME']
44
- end
45
-
46
- def self.dev_root
47
- ["DEV_HOME","DEV_ROOT"].each {|v|
48
- return ENV[v].gsub('\\','/') unless ENV[v].nil?
49
- }
50
- dir=home
51
- return dir
52
- end
53
-
54
- def self.load_projects
55
- projects=Project.new
56
- if File.exists?(projects_filename)
57
- projects=Project.new(JSON.parse(IO.read(projects_filename)))
58
- @filename=projects_filename
59
- end
60
- projects
61
- end
62
-
63
18
  def save
64
19
  File.open(@filename,'w'){|f|f.write(self.to_json)} if @filename.length > 0
65
20
  end
data/lib/projects.rb ADDED
@@ -0,0 +1,30 @@
1
+ require 'dev_environment'
2
+ require 'json'
3
+
4
+ class Projects < Hash
5
+ attr_accessor :filename
6
+
7
+ def update
8
+ self.each{|k,v|
9
+ self[k]=Project.new(v) if(v.is_a?(String))
10
+ self[k]=Project.new(v) if(!v.is_a?(Project) && v.is_a?(Hash))
11
+ self[k][:name]=k
12
+ }
13
+ end
14
+
15
+ def save filename=''
16
+ @filename=filename if filename.length > 0
17
+ File.open(@filename,'w'){|f|f.write(self.to_json)} if @filename.length > 0
18
+ end
19
+
20
+ def open filename=''
21
+ @filename=filename if filename.length > 0
22
+ JSON.parse(IO.read(@filename)).each{|k,v| self[k]=v}
23
+ update
24
+ end
25
+
26
+ def self.user_projects_filename
27
+ FileUtils.mkdir("#{Environment.dev_root}/data") if(!File.exists?("#{Environment.dev_root}/data"))
28
+ "#{Environment.dev_root}/data/PROJECTS.json"
29
+ end
30
+ end
@@ -0,0 +1,28 @@
1
+ require_relative '../lib/projects.rb'
2
+ require 'fileutils'
3
+ describe Projects do
4
+
5
+ it "should be able to add a new Project" do
6
+ projects=Projects.new
7
+ projects['github/dev_projects.gem'] = 'https://github.com/lou-parslow/dev_projects.gem.git'
8
+ projects.update
9
+ expect(projects['github/dev_projects.gem'].is_a?(Project)).to eq(true)
10
+ expect(projects['github/dev_projects.gem'][:name]).to eq('github/dev_projects.gem')
11
+ end
12
+
13
+ it "should be able to store and load" do
14
+ FileUtils.mkdir('tmp') if(!File.exists?('tmp'))
15
+ FileUtils.rm('tmp/test.project.json') if(File.exists?('tmp/test.project.json'))
16
+ expect(File.exists?('tmp/test.project.json')).to eq(false)
17
+
18
+ projects=Projects.new
19
+ projects['github/dev_projects.gem'] = 'https://github.com/lou-parslow/dev_projects.gem.git'
20
+ projects.save 'tmp/test.project.json'
21
+ expect(File.exists?('tmp/test.project.json')).to eq(true)
22
+
23
+ projects2=Projects.new
24
+ projects2.open 'tmp/test.project.json'
25
+ expect(projects2['github/dev_projects.gem'].is_a?(Project)).to eq(true)
26
+ FileUtils.rm('tmp/test.project.json') if(File.exists?('tmp/test.project.json'))
27
+ end
28
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dev_projects
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-01-13 00:00:00.000000000 Z
12
+ date: 2015-01-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -52,7 +52,9 @@ files:
52
52
  - lib/build.rb
53
53
  - lib/dev_projects.rb
54
54
  - lib/project.rb
55
+ - lib/projects.rb
55
56
  - spec/build_spec.rb
57
+ - spec/projects_spec.rb
56
58
  - spec/project_spec.rb
57
59
  - LICENSE
58
60
  - README.md