ruby_build_info 1.0.1

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 ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ODEwN2I1YjZiMmQ3YzZkOTgwZDE2Mjc0OTgwYzlmYzg1MjliY2EzYw==
5
+ data.tar.gz: !binary |-
6
+ MzlkMzY1OWI3MjM4NDdjOGRkMmIwOTQ0Mzc4MjlhMjJiN2MzYTI5Ng==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ NGI0ZjRlYmUxM2E1NWIwZjM4MmRmNmEzMTFiNGY1NzE1ODVmYjc3OGFhZTFi
10
+ NTNkZTg5NThiN2E5ZmQ2NjZiNzNhMzI1N2YyZWNkNDM5ZTA5MmUyZTFhZDEy
11
+ OGI3YjJlZmFjODg5OTgyZmE0MGEyZDU2MDliNWYxMzRkMTc2NmY=
12
+ data.tar.gz: !binary |-
13
+ ZmFiOWM3YjdmNTVjOTc3NjAzMDA2ZDc4NmRiNWYxNjMyMWI3MTM5ZWU0MjU4
14
+ N2E0ODQxM2U4NmRjZjdiN2MxYjk4MzUyYTg5OWUyMjk4ODc4MzJmYzg4Zjk2
15
+ MzcxZmZiZTIxMTlhYzJjMjZkNmNmNTVhYmVkYjQ0MzM4M2I0YzU=
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ruby_build_info.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Adam Georgeson
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # BuildInfo
2
+
3
+ Rack middleware to output build information such as version control, bundled gems, and specified files to a webpage.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'ruby_build_info'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install ruby_build_info
18
+
19
+ ## Usage
20
+
21
+ In your `config\environment\development.rb` or environment file of your choosing*:
22
+
23
+ config.middleware.use(RubyBuildInfo::Middleware)
24
+
25
+ By default this will output Git revision, and output of `bundle show`.
26
+
27
+ You can specify an array optional file paths, such as version files.
28
+
29
+ config.middleware.use(RubyBuildInfo::Middleware, file_paths: ['../custom_file_1', '../custom_file_2'])
30
+
31
+ *Unless it's production.rb - then I don't condone that.
32
+
33
+ ## Contributing
34
+
35
+ 1. Fork it ( https://github.com/adamgeorgeson/ruby_build_info/fork )
36
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
37
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
38
+ 4. Push to the branch (`git push origin my-new-feature`)
39
+ 5. Create a new Pull Request
data/RELEASENOTES.md ADDED
@@ -0,0 +1,5 @@
1
+ # 1.0.0
2
+
3
+ ### Changes
4
+ * Initial release
5
+ * Output git revision info, bundle show and optional files to a webpage when user goes to `/build_info`.
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,6 @@
1
+ require 'ruby_build_info/version'
2
+ require 'rack'
3
+
4
+ module RubyBuildInfo
5
+ autoload :Middleware, 'ruby_build_info/middleware'
6
+ end
@@ -0,0 +1,50 @@
1
+ module RubyBuildInfo
2
+ class Middleware
3
+ require 'json'
4
+
5
+ def initialize(app, options = {})
6
+ @app = app
7
+ @file_paths = options[:file_paths]
8
+ end
9
+
10
+ def call(env)
11
+ if env['PATH_INFO'] == '/build_info'
12
+ @build_info = {}
13
+ @build_info[:git] = git_revision if git_revision
14
+ read_file_paths
15
+ rails_info
16
+ @build_info[:gems] = bundle_show
17
+ output = JSON.pretty_generate(@build_info)
18
+ [200, {'Content-Type' => 'application/json'}, [output]]
19
+ else
20
+ @app.call(env)
21
+ end
22
+ end
23
+
24
+ private
25
+
26
+ def bundle_show
27
+ `bundle show`.gsub(/\n /, '').gsub(/\n/, '').split(' * ')
28
+ end
29
+
30
+ def git_revision
31
+ `git log --pretty=format:'%ad %h %d' --abbrev-commit --date=short -1`
32
+ end
33
+
34
+ def read_file_paths
35
+ unless @file_paths.nil?
36
+ @file_paths.each do |file|
37
+ raise "File does not exist: #{file}" unless File.exist? file
38
+ @build_info[file] = `less #{file}`
39
+ end
40
+ end
41
+ end
42
+
43
+ def rails_info
44
+ if defined? Rails
45
+ result = Rails::Info.properties
46
+ @build_info['Rails::Info'] = Hash[result]
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,3 @@
1
+ module RubyBuildInfo
2
+ VERSION = "1.0.1"
3
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ruby_build_info/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'ruby_build_info'
8
+ spec.version = RubyBuildInfo::VERSION
9
+ spec.authors = ['Adam Georgeson']
10
+ spec.email = ['adamgeorgeson89@gmail.com']
11
+ spec.summary = %q{Rack middleware to output build information such as version control, bundled gems, and specified files to json.}
12
+ spec.description = %q{Rack middleware to output build information such as version control, bundled gems, and specified files to json.}
13
+ spec.homepage = 'https://github.com/adamgeorgeson/ruby_build_info'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_dependency 'rack'
22
+
23
+ spec.add_development_dependency 'bundler', '~> 1.6'
24
+ spec.add_development_dependency 'rake'
25
+ spec.add_development_dependency 'rspec'
26
+ end
@@ -0,0 +1,91 @@
1
+ require 'spec_helper'
2
+
3
+ describe RubyBuildInfo::Middleware do
4
+ subject{ described_class.new(app) }
5
+
6
+ let(:app) do
7
+ lambda do |env|
8
+ [200, {'Content-Type' => 'text/html'}, 'Foo']
9
+ end
10
+ end
11
+
12
+ let(:server){ Rack::MockRequest.new(subject) }
13
+
14
+ before do
15
+ allow(subject).to receive(:bundle_show).and_return('bundle show')
16
+ allow(subject).to receive(:git_revision).and_return('git revision')
17
+ end
18
+
19
+ describe 'unrecognized path' do
20
+ it 'outputs app content' do
21
+ response = server.get('/foo')
22
+ expect(response.body).to eq 'Foo'
23
+ end
24
+ end
25
+
26
+ describe '/build_info' do
27
+ before do
28
+ @response = server.get('/build_info')
29
+ end
30
+
31
+ it 'outputs build info' do
32
+ expect(@response.body).to_not eq 'Foo'
33
+ expect(@response.body).to eq "{\n \"git\": \"git revision\",\n \"gems\": \"bundle show\"\n}"
34
+ end
35
+
36
+ it 'returns HTTP status 200' do
37
+ expect(@response.status). to eq 200
38
+ end
39
+ end
40
+
41
+ describe 'read_file_paths' do
42
+ context 'when an invalid file path is specified' do
43
+ subject{ described_class.new(app, file_paths: ['./foo']) }
44
+ let(:server){ Rack::MockRequest.new(subject) }
45
+
46
+ it 'raises an exception' do
47
+ expect{ server.get('/build_info') }.to raise_exception
48
+ end
49
+ end
50
+
51
+ context 'when file_paths is not an array' do
52
+ subject{ described_class.new(app, file_paths: './spec/support/platform_version') }
53
+ let(:server){ Rack::MockRequest.new(subject) }
54
+
55
+ it 'raises an exception' do
56
+ expect{ server.get('/build_info') }.to raise_exception
57
+ end
58
+ end
59
+
60
+ context 'when a valid file path is specified' do
61
+ subject{ described_class.new(app, file_paths: ['./spec/support/platform_version']) }
62
+ let(:server){ Rack::MockRequest.new(subject) }
63
+
64
+ it 'returns content of the file' do
65
+ @response = server.get('/build_info')
66
+ expect(@response.body).to eq "{\n \"git\": \"git revision\",\n \"./spec/support/platform_version\": \"1.2.3\\n\",\n \"gems\": \"bundle show\"\n}"
67
+ end
68
+ end
69
+ end
70
+
71
+ describe 'Rails::Info' do
72
+ before do
73
+ @response = server.get('/build_info')
74
+ end
75
+
76
+ context 'when rails is not defined' do
77
+ it 'does not output rails info' do
78
+ expect(@response.body).to_not include "Rails::Info"
79
+ end
80
+ end
81
+
82
+ context 'when rails is defined' do
83
+ xit 'outputs rails info' do
84
+ rails = double('Rails', :env => :production)
85
+ Object.send(:const_set, :Rails, rails)
86
+ expect(Rails).to receive(:env).and_return('production')
87
+ expect(@response.body).to include "Rails::Info"
88
+ end
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,93 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
4
+ # this file to always be loaded, without a need to explicitly require it in any
5
+ # files.
6
+ #
7
+ # Given that it is always loaded, you are encouraged to keep this file as
8
+ # light-weight as possible. Requiring heavyweight dependencies from this file
9
+ # will add to the boot time of your test suite on EVERY test run, even for an
10
+ # individual file that may not need all of that loaded. Instead, consider making
11
+ # a separate helper file that requires the additional dependencies and performs
12
+ # the additional setup, and require it from the spec files that actually need
13
+ # it.
14
+ #
15
+ # The `.rspec` file also contains a few flags that are not defaults but that
16
+ # users commonly want.
17
+ #
18
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
19
+ RSpec.configure do |config|
20
+ config.requires = ['ruby_build_info']
21
+ # rspec-expectations config goes here. You can use an alternate
22
+ # assertion/expectation library such as wrong or the stdlib/minitest
23
+ # assertions if you prefer.
24
+ config.expect_with :rspec do |expectations|
25
+ # This option will default to `true` in RSpec 4. It makes the `description`
26
+ # and `failure_message` of custom matchers include text for helper methods
27
+ # defined using `chain`, e.g.:
28
+ # be_bigger_than(2).and_smaller_than(4).description
29
+ # # => "be bigger than 2 and smaller than 4"
30
+ # ...rather than:
31
+ # # => "be bigger than 2"
32
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
33
+ end
34
+
35
+ # rspec-mocks config goes here. You can use an alternate test double
36
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
37
+ config.mock_with :rspec do |mocks|
38
+ # Prevents you from mocking or stubbing a method that does not exist on
39
+ # a real object. This is generally recommended, and will default to
40
+ # `true` in RSpec 4.
41
+ mocks.verify_partial_doubles = true
42
+ end
43
+
44
+ # The settings below are suggested to provide a good initial experience
45
+ # with RSpec, but feel free to customize to your heart's content.
46
+ =begin
47
+ # These two settings work together to allow you to limit a spec run
48
+ # to individual examples or groups you care about by tagging them with
49
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
50
+ # get run.
51
+ config.filter_run :focus
52
+ config.run_all_when_everything_filtered = true
53
+
54
+ # Limits the available syntax to the non-monkey patched syntax that is
55
+ # recommended. For more details, see:
56
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
57
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
58
+ # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
59
+ config.disable_monkey_patching!
60
+
61
+ # This setting enables warnings. It's recommended, but in some cases may
62
+ # be too noisy due to issues in dependencies.
63
+ config.warnings = true
64
+
65
+ # Many RSpec users commonly either run the entire suite or an individual
66
+ # file, and it's useful to allow more verbose output when running an
67
+ # individual spec file.
68
+ if config.files_to_run.one?
69
+ # Use the documentation formatter for detailed output,
70
+ # unless a formatter has already been configured
71
+ # (e.g. via a command-line flag).
72
+ config.default_formatter = 'doc'
73
+ end
74
+
75
+ # Print the 10 slowest examples and example groups at the
76
+ # end of the spec run, to help surface which specs are running
77
+ # particularly slow.
78
+ config.profile_examples = 10
79
+
80
+ # Run specs in random order to surface order dependencies. If you find an
81
+ # order dependency and want to debug it, you can fix the order by providing
82
+ # the seed, which is printed after each run.
83
+ # --seed 1234
84
+ config.order = :random
85
+
86
+ # Seed global randomization in this process using the `--seed` CLI option.
87
+ # Setting this allows you to use `--seed` to deterministically reproduce
88
+ # test failures related to randomization by passing the same `--seed` value
89
+ # as the one that triggered the failure.
90
+ Kernel.srand config.seed
91
+
92
+ =end
93
+ end
@@ -0,0 +1 @@
1
+ 1.2.3
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruby_build_info
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Adam Georgeson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-02-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rack
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ! '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ! '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.6'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.6'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Rack middleware to output build information such as version control,
70
+ bundled gems, and specified files to json.
71
+ email:
72
+ - adamgeorgeson89@gmail.com
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - .gitignore
78
+ - Gemfile
79
+ - LICENSE.txt
80
+ - README.md
81
+ - RELEASENOTES.md
82
+ - Rakefile
83
+ - lib/ruby_build_info.rb
84
+ - lib/ruby_build_info/middleware.rb
85
+ - lib/ruby_build_info/version.rb
86
+ - ruby_build_info.gemspec
87
+ - spec/middleware_spec.rb
88
+ - spec/spec_helper.rb
89
+ - spec/support/platform_version
90
+ homepage: https://github.com/adamgeorgeson/ruby_build_info
91
+ licenses:
92
+ - MIT
93
+ metadata: {}
94
+ post_install_message:
95
+ rdoc_options: []
96
+ require_paths:
97
+ - lib
98
+ required_ruby_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ! '>='
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ required_rubygems_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ! '>='
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ requirements: []
109
+ rubyforge_project:
110
+ rubygems_version: 2.2.2
111
+ signing_key:
112
+ specification_version: 4
113
+ summary: Rack middleware to output build information such as version control, bundled
114
+ gems, and specified files to json.
115
+ test_files:
116
+ - spec/middleware_spec.rb
117
+ - spec/spec_helper.rb
118
+ - spec/support/platform_version