rack-app_version 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0ac2759b5e3bbe7fb30e67b993d21bdc0229e285
4
+ data.tar.gz: 2d1a1a3817265648676acd68af429f59243e291b
5
+ SHA512:
6
+ metadata.gz: c0a11cdcb9f3bfab9ba371ce33fc14fccca1309fb2c201c384a7275007270aa906db5e431d6a0f02642be6f27770c5c13cb5ca020ce1a59db65022fd5adbb3b9
7
+ data.tar.gz: 4ae36f1f7a71f28c9957689a57d06ed8c1b6e21dabcc4e9651c4236703ad88b217fd9d3b02a8a2289a44c0671641bdb5432ef6a9352094281fdf20b03fa554fe
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ .idea
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --require spec_helper
2
+ --format documentation
3
+ --color
data/.rubocop.yml ADDED
@@ -0,0 +1,15 @@
1
+ Style/Documentation:
2
+ Exclude:
3
+ - 'spec/**/*'
4
+
5
+ Style/FrozenStringLiteralComment:
6
+ Enabled: false
7
+
8
+ Metrics/LineLength:
9
+ Enabled: false
10
+
11
+ Style/BlockDelimiters:
12
+ Enabled: false
13
+
14
+ Metrics/BlockLength:
15
+ Enabled: false
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at dofreewill22@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rack-app_version.gemspec
4
+ gemspec
5
+
6
+ gem 'activesupport'
7
+
8
+ group :test, :development do
9
+ gem 'byebug'
10
+ gem 'codeclimate-test-reporter', '~> 1.0.0'
11
+ gem 'pry'
12
+ gem 'rubocop', require: false
13
+ gem 'simplecov', require: false
14
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Wilfrido T. Nuqui Jr.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,74 @@
1
+ # Rack::AppVersion Middleware
2
+ [![Build Status](https://semaphoreci.com/api/v1/wnuqui/rack-app_version/branches/master/badge.svg)](https://semaphoreci.com/wnuqui/rack-app_version) [![Ebert](https://ebertapp.io/github/wnuqui/rack-app_version.svg)](https://ebertapp.io/github/wnuqui/rack-app_version) <a href="https://codeclimate.com/github/wnuqui/rack-app_version"><img src="https://codeclimate.com/github/wnuqui/rack-app_version/badges/gpa.svg" /></a> <a href="https://codeclimate.com/github/wnuqui/rack-app_version"><img src="https://codeclimate.com/github/wnuqui/rack-app_version/badges/issue_count.svg" /></a> <a href="https://codeclimate.com/github/wnuqui/rack-app_version/coverage"><img src="https://codeclimate.com/github/wnuqui/rack-app_version/badges/coverage.svg" /></a>
3
+
4
+ `Rack::AppVersion` is a middleware that sets the version of an app (Rack compatible web applications) via response header.
5
+
6
+ ## Setup
7
+
8
+ ### 1. In your Gemfile
9
+
10
+ ```ruby
11
+ gem 'rack-app_version', git: 'git://github.com/wnuqui/rack-app_version.git', branch: 'master'
12
+ ```
13
+
14
+ ### 2. In `config/application.rb` of your Rails application, put the code below.
15
+
16
+ ```ruby
17
+ module YourApp
18
+ class Application < Rails::Application
19
+
20
+ # ...
21
+
22
+ config.middleware.use Rack::AppVersion
23
+
24
+ end
25
+ end
26
+ ```
27
+
28
+ ### 3. In `Rakefile` of your Rails application, put the code below.
29
+
30
+ ```ruby
31
+ module Rack
32
+ class AppVersion
33
+ def self.generate_version
34
+ # Implement logic of getting application version here.
35
+ end
36
+ end
37
+ end
38
+
39
+ require 'rack/app_version/rake_task'
40
+ Rack::AppVersion.load_tasks
41
+ ```
42
+
43
+ Doing `bundle exec rake -T | grep app_version` will give you the following which you can use:
44
+
45
+ ```bash
46
+ rake app_version:generate # generate app version and write it in .app_version file
47
+ rake app_version:init # generate .app_version file that will contain application version
48
+ ```
49
+
50
+ ### 4. Use `have_app_version` matcher to ensure everything is setup (optional).
51
+
52
+ This rspec matcher can be used by the application to ensure that everything is properly configured.
53
+
54
+ ```ruby
55
+ it 'has app version in response headers' do
56
+ expect(env).to have_app_version
57
+ end
58
+ ```
59
+
60
+ ## Common Gotchas
61
+
62
+ To determine where to put the `Rack::AppVersion` middleware in the Rack stack, run the following command:
63
+
64
+ ```bash
65
+ bundle exec rake middleware
66
+ ```
67
+
68
+ In many cases, the Rack stack will be different running in production environment. Run the following command to see the middleware stack in production:
69
+
70
+ ```bash
71
+ RAILS_ENV=production bundle exec rake middleware
72
+ ```
73
+
74
+ See The [Rails Guide to Rack](http://guides.rubyonrails.org/rails_on_rack.html) for more details on rack middlewares or watch the [railscast](http://railscasts.com/episodes/151-rack-middleware).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
data/ebert.yml ADDED
@@ -0,0 +1,27 @@
1
+ # This configuration was used Ebert to review the wnuqui/rack-app_version repository
2
+ # on 64a63492b864a5da9523ce671065efcac9f0e0f1.
3
+ # You can make this the default configuration for future reviews by moving this
4
+ # file to your repository as `.ebert.yml` and pushing it to GitHub, and tweak
5
+ # it as you wish - To know more on how to change this file to better review your
6
+ # repository you can go to https://docs.ebertapp.io/configuration and see the configuration
7
+ # details.
8
+ ---
9
+ styleguide: plataformatec/linters
10
+ engines:
11
+ reek:
12
+ enabled: true
13
+ fixme:
14
+ enabled: true
15
+ rubocop:
16
+ enabled: true
17
+ duplication:
18
+ config:
19
+ languages:
20
+ - ruby
21
+ enabled: true
22
+ remark-lint:
23
+ enabled: true
24
+ exclude_paths:
25
+ - bin
26
+ - spec
27
+
@@ -0,0 +1,23 @@
1
+ require 'rack/app_version/version'
2
+
3
+ module Rack
4
+ # AppVersion
5
+ class AppVersion
6
+ HEADER_KEY = 'X-App-Version'.freeze
7
+ APP_VERSION_PATH = '.app_version'.freeze
8
+
9
+ def initialize(app)
10
+ @app = app
11
+ @app_version = IO.readlines(APP_VERSION_PATH)[0].chomp
12
+ end
13
+
14
+ def call(env)
15
+ dup._call env
16
+ end
17
+
18
+ def _call(env)
19
+ @app.call(env).tap \
20
+ { |_s, headers, _b| headers[HEADER_KEY] = @app_version }
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,23 @@
1
+ # The application that needs to use `Rack::AppVersion` middleware needs to:
2
+ # 1. include this gem in the Gemfile, and
3
+ # 2. add `Rack::AppVersion` middleware in the list of middlewares
4
+ # the application is using
5
+ #
6
+ # The second step is easy to miss. This rspec matcher can be used
7
+ # by the application to ensure that everything is properly configured.
8
+ #
9
+ # Sample use:
10
+ #
11
+ # ```ruby
12
+ # it 'has app version in response headers' do
13
+ # expect(env).to have_app_version
14
+ # end
15
+ # ```
16
+ require 'active_support/core_ext/object/blank'
17
+
18
+ RSpec::Matchers.define :have_app_version do
19
+ match do
20
+ key = Rack::AppVersion::HEADER_KEY
21
+ actual.key?(key) && actual[key].is_a?(String) && actual[key].present?
22
+ end
23
+ end
@@ -0,0 +1,39 @@
1
+ require 'rake'
2
+
3
+ module Rack
4
+ # :nodoc:
5
+ class AppVersion
6
+ class << self
7
+ include ::Rake::DSL if defined?(::Rake::DSL)
8
+
9
+ def load_tasks
10
+ load_init_task
11
+ load_generate_task
12
+ end
13
+
14
+ private
15
+
16
+ def load_init_task
17
+ namespace :app_version do
18
+ desc 'generate .app_version file that will contain application version'
19
+ task :init do
20
+ puts 'Creating file that will contain application version ...'
21
+ puts ' create .app_version'
22
+ FileUtils.touch APP_VERSION_PATH
23
+ end
24
+ end
25
+ end
26
+
27
+ def load_generate_task
28
+ namespace :app_version do
29
+ desc 'generate app version and write it in .app_version file'
30
+ task :generate do
31
+ puts 'Generating app version ...'
32
+ puts ' generate version '
33
+ IO.write APP_VERSION_PATH, Rack::AppVersion.generate_version
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,5 @@
1
+ module Rack
2
+ class AppVersion
3
+ VERSION = '0.1.0'.freeze
4
+ end
5
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+
3
+ lib = File.expand_path('../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'rack/app_version/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'rack-app_version'
9
+ spec.version = Rack::AppVersion::VERSION
10
+ spec.authors = ['Wilfrido T. Nuqui Jr.']
11
+ spec.email = ['dofreewill22@gmail.com']
12
+
13
+ spec.summary = 'Middleware that sets app version in response header.'
14
+ spec.description = 'Middleware that sets app version in response header.'
15
+ spec.homepage = 'https://github.com/wnuqui/rack-app_version'
16
+ spec.license = 'MIT'
17
+
18
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
19
+ f.match(%r{^(test|spec|features)/})
20
+ end
21
+
22
+ spec.require_paths = ['lib']
23
+
24
+ spec.add_development_dependency 'bundler', '~> 1.13'
25
+ spec.add_development_dependency 'rake', '~> 10.0'
26
+ spec.add_development_dependency 'rspec', '~> 3.0'
27
+ end
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rack-app_version
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Wilfrido T. Nuqui Jr.
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-07-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.13'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.13'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description: Middleware that sets app version in response header.
56
+ email:
57
+ - dofreewill22@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rspec"
64
+ - ".rubocop.yml"
65
+ - CODE_OF_CONDUCT.md
66
+ - Gemfile
67
+ - LICENSE.txt
68
+ - README.md
69
+ - Rakefile
70
+ - ebert.yml
71
+ - lib/rack/app_version.rb
72
+ - lib/rack/app_version/have_app_version_matcher.rb
73
+ - lib/rack/app_version/rake_task.rb
74
+ - lib/rack/app_version/version.rb
75
+ - rack-app_version.gemspec
76
+ homepage: https://github.com/wnuqui/rack-app_version
77
+ licenses:
78
+ - MIT
79
+ metadata: {}
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ requirements: []
95
+ rubyforge_project:
96
+ rubygems_version: 2.5.2
97
+ signing_key:
98
+ specification_version: 4
99
+ summary: Middleware that sets app version in response header.
100
+ test_files: []