gemlock 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
data/lib/gemlock.rb CHANGED
@@ -4,6 +4,7 @@ require "json"
4
4
  require "yaml"
5
5
 
6
6
  require "gemlock/version"
7
+ require "gemlock/config"
7
8
 
8
9
  module Gemlock
9
10
  require 'gemlock/railtie' if defined?(Rails)
@@ -26,26 +27,6 @@ module Gemlock
26
27
  locked_gemfile_specs.delete_if { |spec| !gemfile_names.include?(spec.name) }
27
28
  end
28
29
 
29
- def config
30
- if defined?(Rails) && File.exists?(Rails.root.join('config', 'gemlock.yml'))
31
- Rails.root.join('config', 'gemlock.yml')
32
- end
33
- end
34
-
35
- def parsed_config
36
- YAML.load_file(config) if config
37
- end
38
-
39
- def email
40
- email = parsed_config['email'] if parsed_config
41
-
42
- if email =~ /^[^@]+@[^@]+$/
43
- email
44
- else
45
- nil
46
- end
47
- end
48
-
49
30
  def lookup_version(name)
50
31
  json_hash = JSON.parse(RestClient.get("http://gemlock.herokuapp.com/ruby_gems/#{name}/latest.json"))
51
32
 
@@ -59,16 +40,16 @@ module Gemlock
59
40
  end
60
41
 
61
42
  begin
62
- types = if parsed_config
63
- parsed_config['releases']
43
+ types = if Config.parsed
44
+ Config.parsed['releases']
64
45
  else
65
46
  nil
66
47
  end
67
48
 
68
49
  params = {:gems => specs.to_json }
69
- params[:types] = types if types
70
- params[:automatic] = automatic if automatic
71
- params[:email] = email if email
50
+ params[:types] = types if types
51
+ params[:automatic] = automatic if automatic
52
+ params[:email] = Config.email if Config.email
72
53
 
73
54
  response = RestClient.get("http://gemlock.herokuapp.com/ruby_gems/updates.json", :params => params)
74
55
  gems = JSON.parse(response)
@@ -100,7 +81,7 @@ module Gemlock
100
81
 
101
82
  # By default, check for updates every 2 weeks
102
83
  def initializer(automatic = true)
103
- update_interval = Gemlock.update_interval
84
+ update_interval = Config.update_interval
104
85
  Thread.new(update_interval) do |interval|
105
86
  loop do
106
87
  puts "Checking for gem updates..."
@@ -123,32 +104,6 @@ module Gemlock
123
104
  end
124
105
  end
125
106
 
126
- def update_interval
127
- if parsed_config
128
- if parsed_config["interval"]
129
- interval = parsed_config["interval"][0]
130
-
131
- num_hours = interval.match(/\d*/)[0].to_i
132
- if interval =~ /hour/
133
- delay = 60*60
134
- elsif interval =~ /day/
135
- delay = 60*60*24
136
- elsif interval =~ /week/
137
- delay = 60*60*24*7
138
- elsif interval =~ /month/
139
- delay = 60*60*24*30
140
- end
141
- if delay && num_hours > 0
142
- delay *= num_hours
143
- return delay
144
- elsif delay
145
- return delay
146
- end
147
- end
148
- end
149
- 60*60*24*7 #Seconds in a week
150
- end
151
-
152
107
  def check_gems_individually(gems)
153
108
  outdated = {}
154
109
 
@@ -156,7 +111,7 @@ module Gemlock
156
111
  latest_version = lookup_version(name)
157
112
  update_type = difference(version, latest_version)
158
113
  if Gem::Version.new(latest_version) > Gem::Version.new(version)
159
- if parsed_config && parsed_config['releases'].include?(update_type)
114
+ if Config.parsed && Config.parsed['releases'].include?(update_type)
160
115
  outdated[name] = latest_version
161
116
  end
162
117
  end
@@ -0,0 +1,51 @@
1
+ module Gemlock
2
+ module Config
3
+ class << self
4
+ def file
5
+ if defined?(Rails) && File.exists?(Rails.root.join('config', 'gemlock.yml'))
6
+ Rails.root.join('config', 'gemlock.yml')
7
+ end
8
+ end
9
+
10
+ def parsed
11
+ parsed = YAML.load_file(file) if file
12
+ end
13
+
14
+ def email
15
+ email = parsed['email'] if parsed
16
+
17
+ if email =~ /^[^@]+@[^@]+$/
18
+ email
19
+ else
20
+ nil
21
+ end
22
+ end
23
+
24
+ def update_interval
25
+ if parsed
26
+ if parsed["interval"]
27
+ interval = parsed["interval"][0]
28
+
29
+ num_hours = interval.match(/\d*/)[0].to_i
30
+ if interval =~ /hour/
31
+ delay = 60*60
32
+ elsif interval =~ /day/
33
+ delay = 60*60*24
34
+ elsif interval =~ /week/
35
+ delay = 60*60*24*7
36
+ elsif interval =~ /month/
37
+ delay = 60*60*24*30
38
+ end
39
+ if delay && num_hours > 0
40
+ delay *= num_hours
41
+ return delay
42
+ elsif delay
43
+ return delay
44
+ end
45
+ end
46
+ end
47
+ 60*60*24*7 #Seconds in a week
48
+ end
49
+ end
50
+ end
51
+ end
@@ -1,3 +1,3 @@
1
1
  module Gemlock
2
- VERSION = "0.2.2"
2
+ VERSION = "0.2.3"
3
3
  end
@@ -0,0 +1,12 @@
1
+ require 'rails/generators'
2
+
3
+ module Gemlock
4
+ class ConfigGenerator < Rails::Generators::Base
5
+ argument :email, :type => :string, :default => 'email@example.com'
6
+ source_root File.expand_path(File.join('..', '..', 'templates'), __FILE__)
7
+
8
+ def generate_config
9
+ template "config.yml.erb", "config/gemlock.yml"
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,6 @@
1
+ releases:
2
+ - major
3
+ - minor
4
+ - patch
5
+ interval: 2 weeks
6
+ email: <%= email %>
@@ -0,0 +1,95 @@
1
+ require 'spec_helper'
2
+
3
+ describe Gemlock::Config do
4
+ describe ".file" do
5
+ it "loads gemlock.yml from the config directory if Rails is defined" do
6
+ module Rails
7
+ def self.root
8
+ Pathname.new(File.dirname(__FILE__))
9
+ end
10
+ end
11
+ expected_path = Pathname.new(File.dirname(__FILE__)).join('config', 'gemlock.yml')
12
+ File.stubs(:exists?).with(expected_path).returns(true)
13
+
14
+ Gemlock::Config.file.should eql expected_path
15
+
16
+ # Undefine Rails module
17
+ Object.send(:remove_const, :Rails)
18
+
19
+ end
20
+
21
+ it "is nil if Rails is defined and the files does not exist" do
22
+ module Rails
23
+ def self.root
24
+ Pathname.new(File.dirname(__FILE__))
25
+ end
26
+ end
27
+
28
+ Gemlock::Config.parsed.should be_nil
29
+
30
+ Object.send(:remove_const, :Rails)
31
+ end
32
+
33
+ it "is nil if Rails is not defined and the file exists" do
34
+ Gemlock::Config.file.should be_nil
35
+ end
36
+ end
37
+
38
+ describe ".parsed" do
39
+ it "returns nil if the config file is not present" do
40
+ Gemlock::Config.stubs(:file).returns(nil)
41
+ Gemlock::Config.parsed.should be_nil
42
+ end
43
+
44
+ it "returns a hash containing the user's email if config file is present" do
45
+ Gemlock::Config.stubs(:file).returns((File.join(File.dirname(__FILE__), '..', 'fixtures', 'gemlock.yml')))
46
+ Gemlock::Config.parsed["email"].should eql "tester@example.com"
47
+ end
48
+ end
49
+
50
+ describe ".email" do
51
+ it "returns the email in the config if present and valid" do
52
+ Gemlock::Config.stubs(:parsed).returns({'email' => 'hi@mikeskalnik.com'})
53
+ Gemlock::Config.email.should eql 'hi@mikeskalnik.com'
54
+ end
55
+
56
+ it "returns nil if the email in the config is invalid" do
57
+ Gemlock::Config.stubs(:parsed).returns({'email' => 'd@er@p.com'})
58
+ Gemlock::Config.email.should be_nil
59
+ end
60
+
61
+ it "returns nil if there is no config" do
62
+ Gemlock::Config.stubs(:parsed).returns(nil)
63
+ Gemlock::Config.email.should be_nil
64
+ end
65
+ end
66
+
67
+ describe ".update_interval" do
68
+ it "returns the number of seconds in a week if config_file is not present, or interval is not specified" do
69
+ Gemlock::Config.update_interval.should eql 60*60*24*7
70
+
71
+ Gemlock::Config.stubs(:parsed).returns({"email"=>"tester@example.com"})
72
+ Gemlock::Config.update_interval.should eql 60*60*24*7
73
+ end
74
+
75
+ it "returns the number of seconds until the next number of hours as given" do
76
+ Gemlock::Config.stubs(:parsed).returns({"interval" => ["8 hours"]})
77
+ Gemlock::Config.update_interval.should eql 60*60*8
78
+ end
79
+
80
+ it "returns the number of seconds until the next number of days as given" do
81
+ Gemlock::Config.stubs(:parsed).returns({"interval" => ["4 days"]})
82
+ Gemlock::Config.update_interval.should eql 60*60*24*4
83
+ end
84
+
85
+ it "returns the number of seconds until the next number of weeks as given" do
86
+ Gemlock::Config.stubs(:parsed).returns({"interval" => ["2 weeks"]})
87
+ Gemlock::Config.update_interval.should eql 60*60*24*7*2
88
+ end
89
+
90
+ it "returns the number of seconds unil the next number of months as given" do
91
+ Gemlock::Config.stubs(:parsed).returns({"interval" => ["3 months"]})
92
+ Gemlock::Config.update_interval.should eql 60*60*24*30*3
93
+ end
94
+ end
95
+ end
data/spec/gemlock_spec.rb CHANGED
@@ -52,7 +52,7 @@ describe Gemlock do
52
52
  use_vcr_cassette
53
53
 
54
54
  it "returns a hash of outdated gems & versions specificed in config" do
55
- Gemlock.stubs(:config).returns((File.join(File.dirname(__FILE__), 'fixtures', 'gemlock.yml')))
55
+ Gemlock::Config.stubs(:file).returns((File.join(File.dirname(__FILE__), 'fixtures', 'gemlock.yml')))
56
56
 
57
57
  gems = Gemlock.locked_gemfile_specs.inject({}) do |hash, spec|
58
58
  hash[spec.name] = spec.version.to_s
@@ -121,7 +121,7 @@ describe Gemlock do
121
121
  end
122
122
 
123
123
  it "sends the email address in config to the server if present" do
124
- Gemlock.stubs(:parsed_config).returns({'email' => 'hi@mikeskalnik.com'})
124
+ Gemlock::Config.stubs(:parsed).returns({'email' => 'hi@mikeskalnik.com'})
125
125
  RestClient.expects(:get).with("http://gemlock.herokuapp.com/ruby_gems/updates.json",
126
126
  {:params => {:gems => in_spec.to_json,
127
127
  :email => 'hi@mikeskalnik.com'}}).returns('{}')
@@ -130,68 +130,6 @@ describe Gemlock do
130
130
  end
131
131
  end
132
132
 
133
- describe ".config" do
134
- it "loads gemlock.yml from the config directory if Rails is defined" do
135
- module Rails
136
- def self.root
137
- Pathname.new(File.dirname(__FILE__))
138
- end
139
- end
140
- expected_path = Pathname.new(File.dirname(__FILE__)).join('config', 'gemlock.yml')
141
- File.stubs(:exists?).with(expected_path).returns(true)
142
-
143
- Gemlock.config.should eql expected_path
144
-
145
- # Undefine Rails module
146
- Object.send(:remove_const, :Rails)
147
-
148
- end
149
-
150
- it "is nil if Rails is defined and the files does not exist" do
151
- module Rails
152
- def self.root
153
- Pathname.new(File.dirname(__FILE__))
154
- end
155
- end
156
-
157
- Gemlock.parsed_config.should be_nil
158
-
159
- Object.send(:remove_const, :Rails)
160
- end
161
-
162
- it "is nil if Rails is not defined and the file exists" do
163
- Gemlock.config.should be_nil
164
- end
165
- end
166
-
167
- describe ".parsed_config" do
168
- it "returns nil if the config file is not present" do
169
- Gemlock.parsed_config.should be_nil
170
- end
171
-
172
- it "returns a hash containing the user's email if config file is present" do
173
- Gemlock.stubs(:config).returns((File.join(File.dirname(__FILE__), 'fixtures', 'gemlock.yml')))
174
-
175
- Gemlock.parsed_config["email"].should eql "tester@example.com"
176
- end
177
- end
178
-
179
- describe ".email" do
180
- it "returns the email in the config if present and valid" do
181
- Gemlock.stubs(:parsed_config).returns({'email' => 'hi@mikeskalnik.com'})
182
- Gemlock.email.should eql 'hi@mikeskalnik.com'
183
- end
184
-
185
- it "returns nil if the email in the config is invalid" do
186
- Gemlock.stubs(:parsed_config).returns({'email' => 'd@er@p.com'})
187
- Gemlock.email.should be_nil
188
- end
189
-
190
- it "returns nil if there is no config" do
191
- Gemlock.stubs(:parsed_config).returns(nil)
192
- Gemlock.email.should be_nil
193
- end
194
- end
195
133
 
196
134
  describe ".difference" do
197
135
  it "returns 'major' if there is a major version difference between the two gem versions" do
@@ -257,35 +195,6 @@ describe Gemlock do
257
195
  end
258
196
  end
259
197
 
260
- describe ".update_interval" do
261
- it "returns the number of seconds in a week if config_file is not present, or interval is not specified" do
262
- Gemlock.update_interval.should eql 60*60*24*7
263
-
264
- Gemlock.stubs(:parsed_config).returns({"email"=>"tester@example.com"})
265
- Gemlock.update_interval.should eql 60*60*24*7
266
- end
267
-
268
- it "returns the number of seconds until the next number of hours as given" do
269
- Gemlock.stubs(:parsed_config).returns({"interval" => ["8 hours"]})
270
- Gemlock.update_interval.should eql 60*60*8
271
- end
272
-
273
- it "returns the number of seconds until the next number of days as given" do
274
- Gemlock.stubs(:parsed_config).returns({"interval" => ["4 days"]})
275
- Gemlock.update_interval.should eql 60*60*24*4
276
- end
277
-
278
- it "returns the number of seconds until the next number of weeks as given" do
279
- Gemlock.stubs(:parsed_config).returns({"interval" => ["2 weeks"]})
280
- Gemlock.update_interval.should eql 60*60*24*7*2
281
- end
282
-
283
- it "returns the number of seconds unil the next number of months as given" do
284
- Gemlock.stubs(:parsed_config).returns({"interval" => ["3 months"]})
285
- Gemlock.update_interval.should eql 60*60*24*30*3
286
- end
287
- end
288
-
289
198
  def capture_stdout
290
199
  io = StringIO.new
291
200
  $stdout = io
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gemlock
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -12,11 +12,11 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2011-11-09 00:00:00.000000000Z
15
+ date: 2011-12-04 00:00:00.000000000Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: rake
19
- requirement: &70123701965360 !ruby/object:Gem::Requirement
19
+ requirement: &70108593442260 !ruby/object:Gem::Requirement
20
20
  none: false
21
21
  requirements:
22
22
  - - ! '>='
@@ -24,10 +24,10 @@ dependencies:
24
24
  version: 0.8.7
25
25
  type: :runtime
26
26
  prerelease: false
27
- version_requirements: *70123701965360
27
+ version_requirements: *70108593442260
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: bundler
30
- requirement: &70123701964760 !ruby/object:Gem::Requirement
30
+ requirement: &70108593441760 !ruby/object:Gem::Requirement
31
31
  none: false
32
32
  requirements:
33
33
  - - ~>
@@ -35,10 +35,10 @@ dependencies:
35
35
  version: 1.0.0
36
36
  type: :runtime
37
37
  prerelease: false
38
- version_requirements: *70123701964760
38
+ version_requirements: *70108593441760
39
39
  - !ruby/object:Gem::Dependency
40
40
  name: rest-client
41
- requirement: &70123701964260 !ruby/object:Gem::Requirement
41
+ requirement: &70108593441300 !ruby/object:Gem::Requirement
42
42
  none: false
43
43
  requirements:
44
44
  - - ! '>='
@@ -46,10 +46,10 @@ dependencies:
46
46
  version: '0'
47
47
  type: :runtime
48
48
  prerelease: false
49
- version_requirements: *70123701964260
49
+ version_requirements: *70108593441300
50
50
  - !ruby/object:Gem::Dependency
51
51
  name: json
52
- requirement: &70123701963700 !ruby/object:Gem::Requirement
52
+ requirement: &70108593440580 !ruby/object:Gem::Requirement
53
53
  none: false
54
54
  requirements:
55
55
  - - ! '>='
@@ -57,10 +57,10 @@ dependencies:
57
57
  version: '0'
58
58
  type: :runtime
59
59
  prerelease: false
60
- version_requirements: *70123701963700
60
+ version_requirements: *70108593440580
61
61
  - !ruby/object:Gem::Dependency
62
62
  name: rspec
63
- requirement: &70123701963080 !ruby/object:Gem::Requirement
63
+ requirement: &70108593439780 !ruby/object:Gem::Requirement
64
64
  none: false
65
65
  requirements:
66
66
  - - ~>
@@ -68,10 +68,10 @@ dependencies:
68
68
  version: 2.7.0
69
69
  type: :development
70
70
  prerelease: false
71
- version_requirements: *70123701963080
71
+ version_requirements: *70108593439780
72
72
  - !ruby/object:Gem::Dependency
73
73
  name: mocha
74
- requirement: &70123701956040 !ruby/object:Gem::Requirement
74
+ requirement: &70108593439040 !ruby/object:Gem::Requirement
75
75
  none: false
76
76
  requirements:
77
77
  - - ~>
@@ -79,10 +79,10 @@ dependencies:
79
79
  version: 0.10.0
80
80
  type: :development
81
81
  prerelease: false
82
- version_requirements: *70123701956040
82
+ version_requirements: *70108593439040
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: pry
85
- requirement: &70123701955440 !ruby/object:Gem::Requirement
85
+ requirement: &70108593438540 !ruby/object:Gem::Requirement
86
86
  none: false
87
87
  requirements:
88
88
  - - ! '>='
@@ -90,10 +90,10 @@ dependencies:
90
90
  version: 0.9.5
91
91
  type: :development
92
92
  prerelease: false
93
- version_requirements: *70123701955440
93
+ version_requirements: *70108593438540
94
94
  - !ruby/object:Gem::Dependency
95
95
  name: vcr
96
- requirement: &70123701954840 !ruby/object:Gem::Requirement
96
+ requirement: &70108593437900 !ruby/object:Gem::Requirement
97
97
  none: false
98
98
  requirements:
99
99
  - - ! '>='
@@ -101,10 +101,10 @@ dependencies:
101
101
  version: 1.11.0
102
102
  type: :development
103
103
  prerelease: false
104
- version_requirements: *70123701954840
104
+ version_requirements: *70108593437900
105
105
  - !ruby/object:Gem::Dependency
106
106
  name: fakeweb
107
- requirement: &70123701954320 !ruby/object:Gem::Requirement
107
+ requirement: &70108593437260 !ruby/object:Gem::Requirement
108
108
  none: false
109
109
  requirements:
110
110
  - - ! '>='
@@ -112,7 +112,7 @@ dependencies:
112
112
  version: 1.3.0
113
113
  type: :development
114
114
  prerelease: false
115
- version_requirements: *70123701954320
115
+ version_requirements: *70108593437260
116
116
  description: When installed, allows a user to check for updates in their Rails application
117
117
  email:
118
118
  - mskalnik@gatech.edu
@@ -130,8 +130,11 @@ files:
130
130
  - Rakefile
131
131
  - gemlock.gemspec
132
132
  - lib/gemlock.rb
133
+ - lib/gemlock/config.rb
133
134
  - lib/gemlock/railtie.rb
134
135
  - lib/gemlock/version.rb
136
+ - lib/generators/gemlock/config_generator.rb
137
+ - lib/generators/templates/config.yml.erb
135
138
  - lib/rake_tasks.rb
136
139
  - lib/tasks/gemlock.rake
137
140
  - spec/fixtures/Gemfile
@@ -140,6 +143,7 @@ files:
140
143
  - spec/fixtures/vcr_cassettes/Gemlock/_check_gems_individually.yml
141
144
  - spec/fixtures/vcr_cassettes/Gemlock/_lookup_version.yml
142
145
  - spec/fixtures/vcr_cassettes/Gemlock/_outdated.yml
146
+ - spec/gemlock/config_spec.rb
143
147
  - spec/gemlock_spec.rb
144
148
  - spec/spec_helper.rb
145
149
  homepage: ''
@@ -173,5 +177,6 @@ test_files:
173
177
  - spec/fixtures/vcr_cassettes/Gemlock/_check_gems_individually.yml
174
178
  - spec/fixtures/vcr_cassettes/Gemlock/_lookup_version.yml
175
179
  - spec/fixtures/vcr_cassettes/Gemlock/_outdated.yml
180
+ - spec/gemlock/config_spec.rb
176
181
  - spec/gemlock_spec.rb
177
182
  - spec/spec_helper.rb