prospector 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -0
- data/README.md +21 -1
- data/lib/prospector.rb +24 -9
- data/lib/prospector/background.rb +13 -0
- data/lib/prospector/background/coordinator.rb +37 -0
- data/lib/prospector/background/notify_job.rb +7 -0
- data/lib/prospector/background/notify_worker.rb +9 -0
- data/lib/prospector/client.rb +5 -0
- data/lib/prospector/configuration.rb +44 -1
- data/lib/prospector/error.rb +3 -0
- data/lib/prospector/railtie.rb +9 -0
- data/lib/prospector/version.rb +1 -1
- data/prospector.gemspec +2 -0
- metadata +35 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0eb069f50cbc32b8783bbc6a11a63f819859a12f
|
4
|
+
data.tar.gz: f82b2042f9f51fcdef5d19d7ab5b260d915659ec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 123b0d0306cfc3096b34214c928a8c4af0dfff97e23717fe4cdf0bcac5c0e8d0b9897772e673042db1375a2db58e241f31128ff0e5a5eea41a8538ff2ed1b6cf
|
7
|
+
data.tar.gz: 8d6c93f8f60c9bf4be6ce75ad0a4c1a379d442c6d0ad5519d6b2c3738cef37be5869495b83459b0b004d34eba73602a2396d8b65cc9b10481cf8ab744710779d
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -33,12 +33,32 @@ or:
|
|
33
33
|
Prospector.configure do |config|
|
34
34
|
config.secret_token = 'token from service'
|
35
35
|
config.client_secret = 'secret from service'
|
36
|
+
config.background_adapter = :sidekiq
|
37
|
+
|
38
|
+
config.enabled = Rails.env.production?
|
36
39
|
end
|
37
40
|
```
|
38
41
|
|
39
42
|
## Usage
|
40
43
|
|
41
|
-
|
44
|
+
### Rails
|
45
|
+
|
46
|
+
When the gem is included into a Rails project, you have the option of specifying a background adapter to run the notification service asynchronously on. The default adapter is `ActiveJob` if available in your Rails project, but we also support `Sidekiq` at this time.
|
47
|
+
|
48
|
+
You can choose to enable Prospector in the initializer file, or by the presence of an ENV variable "PROSPECTOR_ENABLED" as shown below.
|
49
|
+
|
50
|
+
```ruby
|
51
|
+
# set the ENV variable
|
52
|
+
# ENV['PROSPECTOR_ENABLED'] = 'true'
|
53
|
+
# or
|
54
|
+
Prospector.configure do |config|
|
55
|
+
config.enabled = Rails.env.production?
|
56
|
+
end
|
57
|
+
```
|
58
|
+
|
59
|
+
### Without Rails
|
60
|
+
|
61
|
+
Without Rails, you need to manually call the method to notify the Prospector service yourself.
|
42
62
|
|
43
63
|
```ruby
|
44
64
|
Prospector.notify!
|
data/lib/prospector.rb
CHANGED
@@ -5,6 +5,9 @@ require "prospector/version"
|
|
5
5
|
require "prospector/client"
|
6
6
|
require "prospector/configuration"
|
7
7
|
require "prospector/error"
|
8
|
+
require "prospector/background"
|
9
|
+
|
10
|
+
require "prospector/railtie" if defined?(Rails)
|
8
11
|
|
9
12
|
begin
|
10
13
|
require "pry"
|
@@ -16,17 +19,29 @@ module Prospector
|
|
16
19
|
attr_writer :configuration
|
17
20
|
end
|
18
21
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
+
module ClassMethods
|
23
|
+
def configuration
|
24
|
+
@configuration ||= Configuration.new
|
25
|
+
end
|
22
26
|
|
23
|
-
|
24
|
-
|
25
|
-
|
27
|
+
def configure
|
28
|
+
yield(configuration)
|
29
|
+
end
|
30
|
+
|
31
|
+
def enabled?
|
32
|
+
configuration.enabled?
|
33
|
+
end
|
26
34
|
|
27
|
-
|
28
|
-
|
35
|
+
def notify!
|
36
|
+
raise NotEnabledError unless enabled?
|
29
37
|
|
30
|
-
|
38
|
+
configuration.notify!
|
39
|
+
|
40
|
+
specifications = Bundler.environment.specs
|
41
|
+
|
42
|
+
Client.deliver(specifications)
|
43
|
+
end
|
31
44
|
end
|
45
|
+
|
46
|
+
extend ClassMethods
|
32
47
|
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require "prospector/background/coordinator"
|
2
|
+
require "prospector/background/notify_job" if defined?(ActiveJob::Base)
|
3
|
+
require "prospector/background/notify_worker" if defined?(Sidekiq::Worker)
|
4
|
+
|
5
|
+
module Prospector
|
6
|
+
module Background
|
7
|
+
def enqueue
|
8
|
+
Coordinator.new.enqueue
|
9
|
+
end
|
10
|
+
|
11
|
+
module_function :enqueue
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Prospector; module Background
|
2
|
+
class Coordinator
|
3
|
+
def enqueue
|
4
|
+
return unless Prospector.enabled?
|
5
|
+
|
6
|
+
case adapter_name
|
7
|
+
when :active_job then enqueue_via_active_job
|
8
|
+
when :sidekiq then enqueue_via_sidekiq
|
9
|
+
when :none then perform_immediately
|
10
|
+
else
|
11
|
+
raise UnsupportedAdapterError.new(adapter_name)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def adapter_name
|
18
|
+
@adapter_name ||= Prospector.configuration.background_adapter
|
19
|
+
end
|
20
|
+
|
21
|
+
def enqueue_via_active_job
|
22
|
+
raise UnsupportedAdapterError unless defined?(NotifyJob)
|
23
|
+
|
24
|
+
NotifyJob.perform_later
|
25
|
+
end
|
26
|
+
|
27
|
+
def enqueue_via_sidekiq
|
28
|
+
raise UnsupportedAdapterError unless defined?(NotifyWorker)
|
29
|
+
|
30
|
+
NotifyWorker.perform_async
|
31
|
+
end
|
32
|
+
|
33
|
+
def perform_immediately
|
34
|
+
Prospector.notify!
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end; end
|
data/lib/prospector/client.rb
CHANGED
@@ -9,6 +9,7 @@ module Prospector
|
|
9
9
|
|
10
10
|
case response.code
|
11
11
|
when "401" then raise AuthenticationError
|
12
|
+
when "402" then raise AccountSubscriptionStatusError, json[:error]
|
12
13
|
when "200" then return true
|
13
14
|
else
|
14
15
|
raise UnknownError
|
@@ -29,6 +30,10 @@ module Prospector
|
|
29
30
|
@endpoint ||= URI('http://api.gemprospector.com/v1/specifications.json')
|
30
31
|
end
|
31
32
|
|
33
|
+
def json
|
34
|
+
@json ||= JSON.parse(response.body)
|
35
|
+
end
|
36
|
+
|
32
37
|
def build_request
|
33
38
|
request = Net::HTTP::Post.new(endpoint)
|
34
39
|
request['X-Auth-Token'] = Prospector.configuration.secret_token
|
@@ -1,6 +1,34 @@
|
|
1
1
|
module Prospector
|
2
2
|
class Configuration
|
3
|
-
attr_writer :
|
3
|
+
attr_writer :client_secret,
|
4
|
+
:enabled,
|
5
|
+
:secret_token
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@notified = false
|
9
|
+
end
|
10
|
+
|
11
|
+
def enabled?
|
12
|
+
return @enabled unless @enabled.nil?
|
13
|
+
|
14
|
+
@enabled = ENV['PROSPECTOR_ENABLED'] == 'true'
|
15
|
+
end
|
16
|
+
|
17
|
+
def notify!
|
18
|
+
@notified = true
|
19
|
+
end
|
20
|
+
|
21
|
+
def notified?
|
22
|
+
@notified == true
|
23
|
+
end
|
24
|
+
|
25
|
+
def background_adapter
|
26
|
+
@background_adapter ||= background_adapter_from_env || determine_default_background_adapater
|
27
|
+
end
|
28
|
+
|
29
|
+
def background_adapter=(value)
|
30
|
+
@background_adapter = value.to_sym
|
31
|
+
end
|
4
32
|
|
5
33
|
def secret_token
|
6
34
|
@secret_token || ENV['PROSPECTOR_SECRET_TOKEN'] || raise(InvalidCredentialsError)
|
@@ -9,5 +37,20 @@ module Prospector
|
|
9
37
|
def client_secret
|
10
38
|
@client_secret || ENV['PROSPECTOR_CLIENT_SECRET'] || raise(InvalidCredentialsError)
|
11
39
|
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def background_adapter_from_env
|
44
|
+
return if ENV['PROSPECTOR_BACKGROUND_ADAPTER'].nil?
|
45
|
+
|
46
|
+
ENV['PROSPECTOR_BACKGROUND_ADAPTER'].to_sym
|
47
|
+
end
|
48
|
+
|
49
|
+
def determine_default_background_adapater
|
50
|
+
return :active_job if defined?(ActiveJob)
|
51
|
+
return :sidekiq if defined?(Sidekiq)
|
52
|
+
|
53
|
+
:none
|
54
|
+
end
|
12
55
|
end
|
13
56
|
end
|
data/lib/prospector/error.rb
CHANGED
@@ -2,5 +2,8 @@ module Prospector
|
|
2
2
|
class Error < StandardError; end
|
3
3
|
class AuthenticationError < Error; end
|
4
4
|
class InvalidCredentialsError < Error; end
|
5
|
+
class AccountSubscriptionStatusError < Error; end
|
6
|
+
class NotEnabledError < Error; end
|
7
|
+
class UnsupportedAdapterError < Error; end
|
5
8
|
class UnknownError < Error; end
|
6
9
|
end
|
data/lib/prospector/version.rb
CHANGED
data/prospector.gemspec
CHANGED
@@ -23,5 +23,7 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.add_dependency "bundler", "~> 1.10"
|
24
24
|
|
25
25
|
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
spec.add_development_dependency "webmock", "~> 1.21"
|
26
27
|
spec.add_development_dependency "vcr", "~> 2.9"
|
28
|
+
spec.add_development_dependency "rspec", "~> 3.3"
|
27
29
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: prospector
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthew Millsaps-Brewer
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-08-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: webmock
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.21'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.21'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: vcr
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,6 +80,20 @@ dependencies:
|
|
66
80
|
- - "~>"
|
67
81
|
- !ruby/object:Gem::Version
|
68
82
|
version: '2.9'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '3.3'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '3.3'
|
69
97
|
description: Gem Prospector allows your team to stay on top of important updates to
|
70
98
|
gems in your Ruby project.
|
71
99
|
email:
|
@@ -85,9 +113,14 @@ files:
|
|
85
113
|
- bin/console
|
86
114
|
- bin/setup
|
87
115
|
- lib/prospector.rb
|
116
|
+
- lib/prospector/background.rb
|
117
|
+
- lib/prospector/background/coordinator.rb
|
118
|
+
- lib/prospector/background/notify_job.rb
|
119
|
+
- lib/prospector/background/notify_worker.rb
|
88
120
|
- lib/prospector/client.rb
|
89
121
|
- lib/prospector/configuration.rb
|
90
122
|
- lib/prospector/error.rb
|
123
|
+
- lib/prospector/railtie.rb
|
91
124
|
- lib/prospector/version.rb
|
92
125
|
- prospector.gemspec
|
93
126
|
homepage: http://www.gemprospector.com
|