rinfo 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 735e0df4987cfe914fa2b9f7db835f9ba40e150c
4
- data.tar.gz: 6714c7823bbf12c1e6f5fcd84ac643d07e78d3e4
3
+ metadata.gz: 97bc7f55b1f7bd7e21f51a51bffaef76a9de9d5c
4
+ data.tar.gz: f51bd8fc84e2f0af9439b0505b367312e1e5301e
5
5
  SHA512:
6
- metadata.gz: ba9767e290e354c7b14cf4018175048f793af1126d9c2d2f65f54fe16a10ced38a531df1d841d602c074099c1d4e0b97bff2d49faa660d6a4c5e38966966048f
7
- data.tar.gz: e84a70886f4ed2566484d10ce3bd1d4be75a31f120ba873ac9c6037f430c4413d071584f5f104f2c4848cc9a9c312a51b78f279ce29f385f0aab9fea2c1e09dc
6
+ metadata.gz: e893b5cfdff8948f6d60de43bae38f4f1cb2b5af042a09a08543d59569c92579f70d62f412d8138ec52654d3255818abc814771314afd8479464f0de517666fd
7
+ data.tar.gz: 2e0a05faa47f7762f2f2298997a27d6c70e04b80164a227c824d23bb066daa6b919cc5662480b5b02a59759f2ec12feb00251c72b3ec66f559dc3243ed1c1294
data/README.md CHANGED
@@ -1,11 +1,67 @@
1
1
  # Rinfo
2
2
 
3
- [![Build Status](https://travis-ci.org/rafecolton/rinfo.png?branch=master)](https://travis-ci.org/rafecolton/rinfo)
3
+ [![Gem Version](https://badge.fury.io/rb/rinfo.png)](http://badge.fury.io/rb/rinfo) [![Build Status](https://travis-ci.org/rafecolton/rinfo.png?branch=master)](https://travis-ci.org/rafecolton/rinfo) [![Dependency Status](https://gemnasium.com/rafecolton/rinfo.png)](https://gemnasium.com/rafecolton/rinfo)
4
4
 
5
- Usage:
5
+ ## Usage
6
6
 
7
- Add the `rinfo` gem to your `Gemfile`:
7
+ Ever wish you could have quick and easy access to release information
8
+ ("rinfo") about your Rails application's latest release? Well now you
9
+ can!
10
+
11
+ Rinfo adds the following route to your application:
12
+
13
+ ```ruby
14
+ get '/rinfo.json'
15
+ ```
16
+
17
+ Accessing your `rinfo.json` page will product something like this:
18
+
19
+ ```javascript
20
+ {
21
+ Deployed By: "Rafe Colton",
22
+ Deployed At: "2014-03-17 15:18:35 -0700",
23
+ Rails Env: "development",
24
+ Branch: "master",
25
+ Rev: "018f44579795167c56066c013b4b18e196142ecb"
26
+ }
27
+ ```
28
+
29
+ It's as easy as that!
30
+
31
+ ## Installation
32
+
33
+ To add `rinfo` to your Rails application, add the `rinfo` gem to your `Gemfile`:
8
34
 
9
35
  ```ruby
10
36
  gem 'rinfo'
11
37
  ```
38
+
39
+ Then, to install the gem:
40
+
41
+ ```bash
42
+ bundle install
43
+ ```
44
+
45
+ ## Configuring
46
+
47
+ Rinfo's functionality is extremely simple, and it doesn't require any
48
+ configuration, but should you desire, it is configurable.
49
+
50
+ Your configuration file `config/initializers/rinfo.rb` would look
51
+ something like this:
52
+
53
+ ```ruby
54
+ # config/initializers/rinfo.rb
55
+ Rinfo.env_blacklist = :staging, :production
56
+ ```
57
+
58
+ The `env_blacklist` attribute is a list of environments such that if it
59
+ includes your `RAILS_ENV`, the `/rinfo.json` route will return a `404`
60
+ response insetad of a `JSON` blob. The arguments provided can be a
61
+ string, an array, or a comma separated list, and each entry can be
62
+ either a string or a symbol. The default blacklist is `[:prod,
63
+ :production]`
64
+
65
+ **NOTE:** There is one special value `:all`, which, if included in your
66
+ list, will prevent `rinfo.json` from showing up entirely, regardless of
67
+ your `RAILS_ENV`
@@ -4,6 +4,8 @@ class RinfoController < ApplicationController
4
4
  include Rails.application.routes.url_helpers
5
5
 
6
6
  def info
7
- render json: Rinfo.info
7
+ render json: Rinfo.inform!
8
+ rescue
9
+ render nothing: true, status: 404
8
10
  end
9
11
  end
data/config.ru CHANGED
@@ -1,4 +1,4 @@
1
1
  # Rails.root/config.ru
2
2
  require ::File.expand_path('../config/environment', __FILE__)
3
3
 
4
- run RinfoApp::Application
4
+ run Rinfo::Application
@@ -2,23 +2,37 @@
2
2
 
3
3
  require 'rinfo/engine'
4
4
  require 'git'
5
+ require 'action_controller'
5
6
 
6
7
  class Rinfo
7
8
  autoload :VERSION, 'rinfo/version'
8
9
 
9
10
  class << self
10
- def info
11
+ def inform!
12
+ fail ActionController::RoutingError 'Not Found' unless should_inform?
11
13
  <<-RINFO.gsub(/^ {6}/, '')
12
14
  {
13
15
  "Deployed By": "#{author}",
14
16
  "Deployed At": "#{date}",
15
- "Rails Env": "#{Rails.env}",
17
+ "Rails Env": "#{env}",
16
18
  "Branch": "#{branch}",
17
19
  "Rev": "#{rev}"
18
20
  }
19
21
  RINFO
20
22
  end
21
23
 
24
+ def should_inform?
25
+ ([:all, env.to_sym] & env_blacklist).empty?
26
+ end
27
+
28
+ def env_blacklist
29
+ @env_blacklist ||= [:prod, :production]
30
+ end
31
+
32
+ def env_blacklist=(args)
33
+ @env_blacklist = [*args].map(&:to_sym)
34
+ end
35
+
22
36
  private
23
37
 
24
38
  def git
@@ -29,6 +43,10 @@ class Rinfo
29
43
  Rails.root
30
44
  end
31
45
 
46
+ def env
47
+ Rails.env
48
+ end
49
+
32
50
  def author
33
51
  git.config('user.name')
34
52
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  unless defined?(Rinfo::VERSION)
4
4
  class Rinfo
5
- VERSION = '0.1.0'
5
+ VERSION = '0.1.1'
6
6
  end
7
7
  end
@@ -4,7 +4,7 @@ require 'tmpdir'
4
4
  require 'git'
5
5
 
6
6
  describe RinfoController, type: :controller do
7
- before :all do
7
+ before(:all) do
8
8
  # create temporary directory
9
9
  @tmpdir = Dir.mktmpdir
10
10
  Dir.chdir(@tmpdir)
@@ -27,7 +27,11 @@ describe RinfoController, type: :controller do
27
27
  @date = git.log.first.date
28
28
  end
29
29
 
30
- after :all do
30
+ before(:each) do
31
+ Rinfo.stub(:root).and_return(@tmpdir)
32
+ end
33
+
34
+ after(:all) do
31
35
  Dir.chdir(Rails.root)
32
36
  FileUtils.rm_rf(@tmpdir)
33
37
  end
@@ -39,11 +43,14 @@ describe RinfoController, type: :controller do
39
43
  let(:rev) { @rev }
40
44
 
41
45
  let(:rinfo) do
46
+ end
47
+
48
+ def rinfo
42
49
  <<-RINFO.gsub(/^ {4}/, '')
43
50
  {
44
51
  "Deployed By": "#{author}",
45
52
  "Deployed At": "#{deploy_time}",
46
- "Rails Env": "#{rails_env}",
53
+ "Rails Env": "#{Rinfo.send(:env)}",
47
54
  "Branch": "#{branch}",
48
55
  "Rev": "#{rev}"
49
56
  }
@@ -51,11 +58,83 @@ describe RinfoController, type: :controller do
51
58
  end
52
59
 
53
60
  describe 'GET #info' do
54
- it 'renders rinfo.json' do
55
- Rinfo.stub(:root).and_return(@tmpdir)
61
+ let(:rails_envs) do
62
+ %w(test development demo stage staging prod production).map(&:to_sym)
63
+ end
64
+ let(:default_blacklist) { [:prod, :production] }
65
+ let(:default_whitelist) do
66
+ %w(test development demo stage staging).map(&:to_sym)
67
+ end
68
+ let(:custom_blacklist) { [:demo, :stage] }
69
+ let(:blacklist_allow_all) { [:none] }
70
+ let(:blacklist_allow_none) { [:all] }
71
+
72
+ context 'default blacklisted envs' do
73
+ it 'does not display rinfo for blacklisted envs' do
74
+ default_blacklist.each do |env|
75
+ Rinfo.stub(:env).and_return(env.to_s)
76
+ get 'info', format: :json
77
+ response.status.should == 404
78
+ end
79
+ end
80
+
81
+ it 'displays rinfo for all envs not on the blacklist' do
82
+ default_whitelist.each do |env|
83
+ Rinfo.stub(:env).and_return(env.to_s)
84
+ get 'info', format: :json
85
+ response.body.should == rinfo
86
+ end
87
+ end
88
+ end
89
+
90
+ context 'all envs enabled' do
91
+ before(:each) do
92
+ Rinfo.stub(:env_blacklist).and_return(blacklist_allow_all)
93
+ end
94
+
95
+ it 'displays rinfo for all envs' do
96
+ rails_envs.each do |env|
97
+ Rinfo.stub(:env).and_return(env.to_s)
98
+ get 'info', format: :json
99
+ response.body.should == rinfo
100
+ end
101
+ end
102
+ end
103
+
104
+ context 'all envs disabled' do
105
+ before(:each) do
106
+ Rinfo.stub(:env_blacklist).and_return blacklist_allow_none
107
+ end
108
+
109
+ it 'does not display rinfo for any envs' do
110
+ rails_envs.each do |env|
111
+ Rinfo.stub(:env).and_return(env.to_s)
112
+ get 'info', format: :json
113
+ response.status.should == 404
114
+ end
115
+ end
116
+ end
117
+
118
+ context 'custom blacklist' do
119
+ before(:each) do
120
+ Rinfo.stub(:env_blacklist).and_return(custom_blacklist)
121
+ end
122
+
123
+ it 'does not display rinfo for blacklisted envs' do
124
+ custom_blacklist.each do |env|
125
+ Rinfo.stub(:env).and_return(env.to_s)
126
+ get 'info', format: :json
127
+ response.status.should == 404
128
+ end
129
+ end
56
130
 
57
- get 'info', format: :json
58
- response.body.should == rinfo
131
+ it 'displays rinfo for non-blacklisted envs' do
132
+ (rails_envs - custom_blacklist).each do |env|
133
+ Rinfo.stub(:env).and_return(env.to_s)
134
+ get 'info', format: :json
135
+ response.body.should == rinfo
136
+ end
137
+ end
59
138
  end
60
139
  end
61
140
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rinfo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rafe Colton