gemrage 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/.bundle/config ADDED
@@ -0,0 +1,3 @@
1
+ ---
2
+ BUNDLE_DISABLE_SHARED_GEMS: "1"
3
+ BUNDLE_PATH: vendor
data/Gemfile CHANGED
@@ -4,6 +4,7 @@ gem 'rest-client', '~> 1.6.1'
4
4
  gem 'bundler', '~> 1.0.3'
5
5
  gem 'macaddr', '~> 1.0.0'
6
6
  gem 'rvm', '~> 1.0.14'
7
+ gem 'json_pure', '~> 1.4.6', :require => 'json'
7
8
 
8
9
  group :development do
9
10
  gem 'rspec', '~> 2.0.0'
data/Gemfile.lock CHANGED
@@ -34,6 +34,7 @@ PLATFORMS
34
34
  DEPENDENCIES
35
35
  bundler (~> 1.0.3)
36
36
  jeweler
37
+ json_pure (~> 1.4.6)
37
38
  macaddr (~> 1.0.0)
38
39
  rest-client (~> 1.6.1)
39
40
  rspec (~> 2.0.0)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.3.0
data/gemrage.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{gemrage}
8
- s.version = "0.2.0"
8
+ s.version = "0.3.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Daniel Huckstep"]
@@ -13,7 +13,8 @@ Gem::Specification.new do |s|
13
13
  s.description = %q{Companion gem for gemrage.com}
14
14
  s.email = %q{darkhelmet@darkhelmetlive.com}
15
15
  s.files = [
16
- ".document",
16
+ ".bundle/config",
17
+ ".document",
17
18
  ".gitignore",
18
19
  "Gemfile",
19
20
  "Gemfile.lock",
@@ -16,9 +16,10 @@ class Gem::Commands::ScanCommand < Gem::Command
16
16
  include Gem::GemcutterUtilities
17
17
 
18
18
  GemrageHost = 'http://gemrage.com/'
19
+ # GemrageHost = 'http://localhost:3000/'
19
20
 
20
21
  def initialize
21
- super('scan', description, :dir => '')
22
+ super('scan', description)
22
23
  end
23
24
 
24
25
  def description
@@ -34,11 +35,62 @@ class Gem::Commands::ScanCommand < Gem::Command
34
35
  end
35
36
 
36
37
  def execute
37
- p system_scan
38
+ if dir = get_one_optional_argument
39
+ notify(send_project_to_gemrage(project_scan(File.expand_path(dir))))
40
+ else
41
+ notify(send_system_to_gemrage(system_scan))
42
+ end
38
43
  end
39
44
 
40
45
  private
41
46
 
47
+ def send_system_to_gemrage(gems)
48
+ RestClient.post(URI.join(GemrageHost, '/api/v1/payload/system.json').to_s, :payload => { :header => { :machine_id => mac_hash }, :installed_gems => gems })
49
+ end
50
+
51
+ def send_project_to_gemrage(payload)
52
+ payload.to_json
53
+ end
54
+
55
+ def project_scan(dir)
56
+ Dir[File.join(dir, '**', '{Gemfile}')].map do |gemfile|
57
+ project_name = File.basename(File.dirname(gemfile))
58
+ project_id = Digest::SHA1.hexdigest(File.dirname(gemfile))
59
+ lockfile = parse_lockfile("#{gemfile}.lock")
60
+
61
+ begin
62
+ d = Bundler::Definition.build(gemfile, nil, nil)
63
+ deps = d.current_dependencies
64
+ {
65
+ :name => project_name,
66
+ :identifier => project_id,
67
+ :gems => Hash[*deps.map do |dep|
68
+ [dep.name, lockfile[dep.name] || dep.requirement.to_s]
69
+ end.flatten]
70
+ }
71
+ rescue Exception => boom
72
+ # Maybe it's an old Gemfile
73
+ nil
74
+ end
75
+ end.compact
76
+ end
77
+
78
+ def parse_lockfile(lockfile)
79
+ if File.exists?(lockfile)
80
+ h = {}
81
+ File.readlines(lockfile).each do |line|
82
+ line.strip!
83
+ # Don't care about any lines with range operators on versions
84
+ next if line.match(/[~><=]/)
85
+ name, version = get_name_and_versions!(line) rescue next
86
+ h[name] = version
87
+ end
88
+ h
89
+ else
90
+ {}
91
+ end
92
+ end
93
+
42
94
  def system_scan
43
95
  if windows? && pik?
44
96
  notify("Scanning with pik")
@@ -53,7 +105,7 @@ private
53
105
  end
54
106
 
55
107
  def pik_scan
56
- parse_gem_list(`pik gem list`)
108
+ parse_gem_list(`pik gem list`) rescue {}
57
109
  end
58
110
 
59
111
  def rvm_scan
@@ -140,7 +192,7 @@ private
140
192
  def parse_gem_list(stdout, plat = platform)
141
193
  h = {}
142
194
  stdout.split("\n").each do |line|
143
- name, versions = line.match(/^([\w\-_]+) \((.*)\)$/)[1,2] rescue next
195
+ name, versions = get_name_and_versions!(line) rescue next
144
196
  versions = versions.split(',').map { |version| version.strip.split.first }
145
197
  h[name] ||= {}
146
198
  h[name][plat] = [h[name][plat], versions].compact.uniq.join(',')
@@ -148,6 +200,10 @@ private
148
200
  h
149
201
  end
150
202
 
203
+ def get_name_and_versions!(line)
204
+ line.match(/^([\w\-_]+) \((.*)\)$/)[1,2]
205
+ end
206
+
151
207
  def rvm_platform
152
208
  platform(rvm_const('RUBY_ENGINE'), rvm_const('RUBY_DESCRIPTION'), rvm_const('RUBY_VERSION'))
153
209
  end
@@ -157,7 +213,7 @@ private
157
213
  end
158
214
 
159
215
  def windows?
160
- Config::CONFIG['host_os'] =~ /mswin|mingw/
216
+ Config::CONFIG['host_os'] =~ /msdos|mswin|djgpp|mingw/
161
217
  end
162
218
 
163
219
  def platform(engine = (defined?(RUBY_ENGINE) ? RUBY_ENGINE : nil),
data/spec/spec_helper.rb CHANGED
@@ -6,4 +6,13 @@ require 'spec/autorun'
6
6
 
7
7
  Spec::Runner.configure do |config|
8
8
 
9
+ @valid_user_attr = {
10
+ :email => 'support@gemrage.com',
11
+ :password => 'password',
12
+ :password_confirmation => 'password'
13
+ }
14
+
15
+
16
+
9
17
  end
18
+
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gemrage
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 2
8
+ - 3
9
9
  - 0
10
- version: 0.2.0
10
+ version: 0.3.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Daniel Huckstep
@@ -28,6 +28,7 @@ extensions: []
28
28
  extra_rdoc_files: []
29
29
 
30
30
  files:
31
+ - .bundle/config
31
32
  - .document
32
33
  - .gitignore
33
34
  - Gemfile