rails_version 0.2.3 → 0.3.0
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.
- checksums.yaml +7 -0
- data/Gemfile +2 -1
- data/README.md +7 -4
- data/lib/rails_version.rb +18 -4
- data/lib/rails_version/pinger.rb +10 -4
- data/lib/rails_version/rails_version_mixin.rb +3 -2
- data/lib/rails_version/railtie.rb +1 -1
- data/lib/rails_version/version.rb +1 -1
- data/test/rails_version_test.rb +22 -4
- metadata +33 -53
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0fdd0f231ea942e352b396618ab67d34fdc86d76
|
4
|
+
data.tar.gz: 9d2b2c820ba19fdadc1d7e9d211bad7ac81bd634
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d640a82922b0dab6796679c1cea309a04f94b93d0cba651f4f05f773ec0a69a55c5864d74032770590f6db334945fe17097265502bcf89d6e012f6da1b6caa1e
|
7
|
+
data.tar.gz: 88900041e381adc15c6ec60a737f9311ef8a0d3d6dd610ea92f2efa685b289e8f43e59f8da7dcb53a0cb95f50382178d466434c8471556178cd3336340809267
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -14,22 +14,25 @@ Sign up and get your API key from http://railsversion.herokuapp.com, then go to
|
|
14
14
|
|
15
15
|
RailsVersion::Config.api_key = "API_KEY_HERE"
|
16
16
|
|
17
|
+
If you have an app that has dynamic subdomains (such as multiple sites running on the same app), you can set a "canonical" App Name, so all the domains will be updated when the gem reports on one of them.
|
18
|
+
|
19
|
+
RailsVersion::Config.app_name = "CANONICAL_APP_NAME"
|
20
|
+
|
17
21
|
## Manual Ping
|
18
22
|
|
19
23
|
If you want to manually trigger a ping, go to:
|
20
24
|
|
21
|
-
http://
|
25
|
+
http://yourdomain.com/?rails_version_ping=API_KEY_HERE
|
22
26
|
|
23
|
-
Just replace
|
27
|
+
Just replace yourdomain.com with your domain name and API_KEY_HERE with your API key.
|
24
28
|
|
25
29
|
## Configuration Options
|
26
30
|
|
27
31
|
We have good defaults, but we do expose some config options:
|
28
32
|
|
29
|
-
* `RailsVersion::Config.server_url = "http://yourserver/ping"` - allows you to ping your own server instead of ours.
|
30
33
|
* `RailsVersion::Config.ping_type = :server | :image | :script` - :server is default and the safest, but you can also inject an image or javascript tag into your HTML if the :server option isn't working for you.
|
31
34
|
* `RailsVersion::Config.frequency = 100` - 100 is a 1% chance on page load of pinging our server (default). Turn this down if you have a lot of traffic or up if you have very little traffic. Your server should ping ours about once every couple days on average.
|
32
|
-
* `RailsVersion::Config.api_key = "API_KEY_HERE"` - *required* API key from http://railsversion.herokuapp.com
|
35
|
+
* `RailsVersion::Config.api_key = "API_KEY_HERE"` - *required* Free API key from http://railsversion.herokuapp.com.
|
33
36
|
|
34
37
|
## Code Climate
|
35
38
|
|
data/lib/rails_version.rb
CHANGED
@@ -9,10 +9,7 @@ module RailsVersion
|
|
9
9
|
# :singleton-method:
|
10
10
|
# Specify what URL this gem will ping with its information.
|
11
11
|
def self.server_url
|
12
|
-
@@server_url
|
13
|
-
end
|
14
|
-
def self.server_url=(v)
|
15
|
-
@@server_url = v
|
12
|
+
@@server_url = "https://railsversion.herokuapp.com/ping"
|
16
13
|
end
|
17
14
|
|
18
15
|
##
|
@@ -49,5 +46,22 @@ module RailsVersion
|
|
49
46
|
def self.api_key=(v)
|
50
47
|
@@api_key = v
|
51
48
|
end
|
49
|
+
|
50
|
+
##
|
51
|
+
# :singleton-method:
|
52
|
+
# Canonical App Name
|
53
|
+
# This allows Apps that work with dynamic subdomains to update all
|
54
|
+
# domains on railsversion.herokuap.com with that canonical name
|
55
|
+
# e.g
|
56
|
+
# Domain 1: example.com
|
57
|
+
# Domain 2: sub.example.com
|
58
|
+
# When app_name is set, it will send it along to the API when it pings
|
59
|
+
# And both domains will be updated
|
60
|
+
def self.app_name
|
61
|
+
@@app_name ||= nil
|
62
|
+
end
|
63
|
+
def self.app_name=(v)
|
64
|
+
@@app_name = v
|
65
|
+
end
|
52
66
|
end
|
53
67
|
end
|
data/lib/rails_version/pinger.rb
CHANGED
@@ -1,10 +1,12 @@
|
|
1
1
|
module RailsVersion
|
2
2
|
class Pinger
|
3
|
-
attr_accessor :body, :version, :host
|
3
|
+
attr_accessor :body, :version, :host, :app_name
|
4
4
|
|
5
5
|
def initialize(request, response)
|
6
|
+
@modified_body = false
|
6
7
|
@body = response.body.to_s
|
7
8
|
@host = request.host.to_s
|
9
|
+
@app_name = RailsVersion::Config.app_name.to_s
|
8
10
|
@version = "Non-Rails"
|
9
11
|
@version = Rails.version.to_s if Object.const_defined?('Rails')
|
10
12
|
end
|
@@ -14,7 +16,6 @@ module RailsVersion
|
|
14
16
|
when :server
|
15
17
|
require 'open-uri'
|
16
18
|
open(ping_url) # Ping the server.
|
17
|
-
return false
|
18
19
|
when :script
|
19
20
|
inject_script_before_end_body_tag(ping_script)
|
20
21
|
else
|
@@ -24,7 +25,12 @@ module RailsVersion
|
|
24
25
|
false
|
25
26
|
end
|
26
27
|
|
28
|
+
def modified_body?
|
29
|
+
@modified_body
|
30
|
+
end
|
31
|
+
|
27
32
|
def inject_script_before_end_body_tag(ping_html)
|
33
|
+
@modified_body = true
|
28
34
|
@body.sub! /<\/[bB][oO][dD][yY]>/, "#{ping_html}</body>" if @body && @body.respond_to?(:sub!)
|
29
35
|
end
|
30
36
|
|
@@ -37,7 +43,7 @@ module RailsVersion
|
|
37
43
|
end
|
38
44
|
|
39
45
|
def ping_url
|
40
|
-
"#{RailsVersion::Config.server_url}/#{RailsVersion::Config.api_key}/?site=#{@host}&rails_version=#{@version}"
|
46
|
+
"#{RailsVersion::Config.server_url}/#{RailsVersion::Config.api_key}/?site=#{@host}&rails_version=#{@version}&app_name=#{@app_name}"
|
41
47
|
end
|
42
48
|
end
|
43
|
-
end
|
49
|
+
end
|
@@ -6,10 +6,11 @@ module RailsVersion
|
|
6
6
|
manual_ping = params[:rails_version_ping] == RailsVersion::Config.api_key
|
7
7
|
if manual_ping || rand(10000) < RailsVersion::Config.frequency
|
8
8
|
pinger = RailsVersion::Pinger.new(request, response)
|
9
|
-
|
9
|
+
pinger.ping!
|
10
|
+
response.body = pinger.body if pinger.modified_body?
|
10
11
|
end
|
11
12
|
rescue OpenURI::HTTPError
|
12
13
|
nil # No HTTPError here! Nuh uh. Nope. Nothing to see here.
|
13
14
|
end
|
14
15
|
end
|
15
|
-
end
|
16
|
+
end
|
data/test/rails_version_test.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'test/unit'
|
2
|
+
require 'webmock/minitest'
|
2
3
|
require 'rails_version'
|
3
4
|
require 'rails_version/pinger'
|
4
5
|
|
@@ -14,33 +15,50 @@ class FakeResponse
|
|
14
15
|
end
|
15
16
|
end
|
16
17
|
|
17
|
-
|
18
18
|
class RailsVersionTest < Test::Unit::TestCase
|
19
|
+
|
19
20
|
def test_pinger_injects_script
|
20
21
|
RailsVersion::Config.ping_type = :script
|
21
22
|
RailsVersion::Config.api_key = "TESTSCRIPT"
|
23
|
+
RailsVersion::Config.app_name = "TESTAPP"
|
22
24
|
pinger = RailsVersion::Pinger.new(FakeRequest.new, FakeResponse.new)
|
23
25
|
pinger.ping!
|
24
26
|
body = pinger.body
|
25
27
|
assert body.include?("</script></body>")
|
26
28
|
assert body.include?("/TESTSCRIPT/")
|
29
|
+
assert body.include?("&app_name=TESTAPP")
|
27
30
|
end
|
31
|
+
|
28
32
|
def test_pinger_injects_image
|
29
33
|
RailsVersion::Config.ping_type = :image
|
30
34
|
RailsVersion::Config.api_key = "TESTIMAGE"
|
35
|
+
RailsVersion::Config.app_name = "TESTAPP"
|
31
36
|
pinger = RailsVersion::Pinger.new(FakeRequest.new, FakeResponse.new)
|
32
37
|
pinger.ping!
|
33
38
|
body = pinger.body
|
34
39
|
assert body.include?("<img src='")
|
35
40
|
assert body.include?("/TESTIMAGE/")
|
41
|
+
assert body.include?("&app_name=TESTAPP")
|
36
42
|
end
|
43
|
+
|
37
44
|
def test_pinger_server
|
38
45
|
RailsVersion::Config.ping_type = :server
|
39
46
|
RailsVersion::Config.api_key = "TESTSERVER"
|
47
|
+
RailsVersion::Config.app_name = "TESTAPP"
|
48
|
+
stub_get = stub_request(:get, "https://railsversion.herokuapp.com/ping/TESTSERVER/").with(
|
49
|
+
query: {
|
50
|
+
"app_name" => "TESTAPP",
|
51
|
+
"rails_version" => "Non-Rails",
|
52
|
+
"site" => "www.example.com"
|
53
|
+
}
|
54
|
+
)
|
55
|
+
|
40
56
|
pinger = RailsVersion::Pinger.new(FakeRequest.new, FakeResponse.new)
|
57
|
+
url = pinger.ping_url
|
41
58
|
pinger.ping!
|
42
|
-
|
43
|
-
|
44
|
-
assert
|
59
|
+
|
60
|
+
assert url.include?("/TESTSERVER/")
|
61
|
+
assert url.include?("&app_name=TESTAPP")
|
62
|
+
assert_requested(stub_get)
|
45
63
|
end
|
46
64
|
end
|
metadata
CHANGED
@@ -1,47 +1,37 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_version
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 2
|
9
|
-
- 3
|
10
|
-
version: 0.2.3
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.0
|
11
5
|
platform: ruby
|
12
|
-
authors:
|
6
|
+
authors:
|
13
7
|
- Jamon Holmgren
|
14
8
|
autorequire:
|
15
9
|
bindir: bin
|
16
10
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
- !ruby/object:Gem::Dependency
|
11
|
+
date: 2014-11-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
21
14
|
name: actionpack
|
22
|
-
|
23
|
-
|
24
|
-
none: false
|
25
|
-
requirements:
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
26
17
|
- - ">="
|
27
|
-
- !ruby/object:Gem::Version
|
28
|
-
|
29
|
-
segments:
|
30
|
-
- 0
|
31
|
-
version: "0"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
32
20
|
type: :development
|
33
|
-
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
34
27
|
description: " Pings a server and reports the current app's Rails version. "
|
35
|
-
email:
|
28
|
+
email:
|
36
29
|
- jamon@clearsightstudio.com
|
37
30
|
executables: []
|
38
|
-
|
39
31
|
extensions: []
|
40
|
-
|
41
32
|
extra_rdoc_files: []
|
42
|
-
|
43
|
-
|
44
|
-
- .gitignore
|
33
|
+
files:
|
34
|
+
- ".gitignore"
|
45
35
|
- Gemfile
|
46
36
|
- LICENSE
|
47
37
|
- README.md
|
@@ -55,37 +45,27 @@ files:
|
|
55
45
|
- test/rails_version_test.rb
|
56
46
|
homepage: https://github.com/clearsightstudio/rails_version
|
57
47
|
licenses: []
|
58
|
-
|
48
|
+
metadata: {}
|
59
49
|
post_install_message:
|
60
50
|
rdoc_options: []
|
61
|
-
|
62
|
-
require_paths:
|
51
|
+
require_paths:
|
63
52
|
- lib
|
64
53
|
- rails
|
65
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
66
|
-
|
67
|
-
requirements:
|
54
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
68
56
|
- - ">="
|
69
|
-
- !ruby/object:Gem::Version
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
version: "0"
|
74
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
|
-
none: false
|
76
|
-
requirements:
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: '0'
|
59
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
77
61
|
- - ">="
|
78
|
-
- !ruby/object:Gem::Version
|
79
|
-
|
80
|
-
segments:
|
81
|
-
- 0
|
82
|
-
version: "0"
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
83
64
|
requirements: []
|
84
|
-
|
85
65
|
rubyforge_project:
|
86
|
-
rubygems_version:
|
66
|
+
rubygems_version: 2.2.2
|
87
67
|
signing_key:
|
88
|
-
specification_version:
|
68
|
+
specification_version: 4
|
89
69
|
summary: Pings a server and reports the current app's Rails version.
|
90
|
-
test_files:
|
70
|
+
test_files:
|
91
71
|
- test/rails_version_test.rb
|