nxt_heroku_env 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 9a8450a7f5bbe64c1bca7f2faa670aa5c276e0dab5efe739db5558a3271ebca8
4
+ data.tar.gz: 53571d3b549d73a0dead62ef5bb69d8b6a375621f28def7ba12bde2a9331eb97
5
+ SHA512:
6
+ metadata.gz: c384e9f395a10b433e89fdb566bc8998628b5aef8343ee90b625ce9e98962d4b46fb48d341bed188dcc3012f0441f8aeb0d199e99c00d702cb75f24bd656da54
7
+ data.tar.gz: '06039311521b1566f7253de3afa19d1127348e7d4d66e4cd5796f6fffb030f7a2261555b65d7a4267945b7af13ff013aaf26b39f3a6ec9271a336cf279399e30'
@@ -0,0 +1,57 @@
1
+ # Ruby CircleCI 2.0 configuration file
2
+ #
3
+ # Check https://circleci.com/docs/2.0/language-ruby/ for more details
4
+ #
5
+ version: 2
6
+ jobs:
7
+ build:
8
+ docker:
9
+ # specify the version you desire here
10
+ - image: circleci/ruby:2.6.3-node
11
+
12
+ working_directory: ~/repo
13
+
14
+ steps:
15
+ - checkout
16
+
17
+ # Download and cache dependencies
18
+ - restore_cache:
19
+ keys:
20
+ - v1-dependencies-{{ checksum "Gemfile.lock" }}
21
+
22
+ - run:
23
+ name: install dependencies
24
+ command: |
25
+ bundle install --jobs=4 --retry=3 --path vendor/bundle
26
+
27
+ - save_cache:
28
+ paths:
29
+ - ./vendor/bundle
30
+ key: v1-dependencies-{{ checksum "Gemfile.lock" }}
31
+
32
+ # Run code style linter!
33
+ - run:
34
+ name: run code style linter
35
+ command: bundle exec standardrb
36
+
37
+ # run tests!
38
+ - run:
39
+ name: run tests
40
+ command: |
41
+ mkdir /tmp/test-results
42
+ TEST_FILES="$(circleci tests glob "spec/**/*_spec.rb" | \
43
+ circleci tests split --split-by=timings)"
44
+
45
+ bundle exec rspec \
46
+ --format progress \
47
+ --format RspecJunitFormatter \
48
+ --out /tmp/test-results/rspec.xml \
49
+ --format progress \
50
+ $TEST_FILES
51
+
52
+ # collect reports
53
+ - store_test_results:
54
+ path: /tmp/test-results
55
+ - store_artifacts:
56
+ path: /tmp/test-results
57
+ destination: test-results
@@ -0,0 +1,15 @@
1
+ # EditorConfig is awesome: http://EditorConfig.org
2
+
3
+ # top-most EditorConfig file
4
+ root = true
5
+
6
+ # Unix-style newlines with a newline ending every file
7
+ [*]
8
+ end_of_line = lf
9
+ insert_final_newline = true
10
+ charset = utf-8
11
+
12
+ [*.{rb,yml,json,rake}]
13
+ indent_style = space
14
+ indent_size = 2
15
+ trim_trailing_whitespace = true
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --require spec_helper
@@ -0,0 +1 @@
1
+ 2.6.3
@@ -0,0 +1,7 @@
1
+ ## Unreleased
2
+
3
+ ## nxt_heroku_env 0.1.0 (April 23, 2019)
4
+
5
+ * Initial release.
6
+
7
+ *Nils Sommer*
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in nxt_heroku_env.gemspec
6
+ gemspec
7
+
8
+ group :test do
9
+ gem "rspec_junit_formatter" # for CircleCI
10
+ end
@@ -0,0 +1,80 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ nxt_heroku_env (0.1.0)
5
+ activesupport
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ activesupport (5.2.3)
11
+ concurrent-ruby (~> 1.0, >= 1.0.2)
12
+ i18n (>= 0.7, < 2)
13
+ minitest (~> 5.1)
14
+ tzinfo (~> 1.1)
15
+ ast (2.4.0)
16
+ coderay (1.1.2)
17
+ concurrent-ruby (1.1.5)
18
+ diff-lcs (1.3)
19
+ i18n (1.6.0)
20
+ concurrent-ruby (~> 1.0)
21
+ jaro_winkler (1.5.2)
22
+ method_source (0.9.2)
23
+ minitest (5.11.3)
24
+ parallel (1.17.0)
25
+ parser (2.6.2.1)
26
+ ast (~> 2.4.0)
27
+ pry (0.12.2)
28
+ coderay (~> 1.1.0)
29
+ method_source (~> 0.9.0)
30
+ psych (3.1.0)
31
+ rainbow (3.0.0)
32
+ rake (10.5.0)
33
+ rspec (3.8.0)
34
+ rspec-core (~> 3.8.0)
35
+ rspec-expectations (~> 3.8.0)
36
+ rspec-mocks (~> 3.8.0)
37
+ rspec-core (3.8.0)
38
+ rspec-support (~> 3.8.0)
39
+ rspec-expectations (3.8.2)
40
+ diff-lcs (>= 1.2.0, < 2.0)
41
+ rspec-support (~> 3.8.0)
42
+ rspec-mocks (3.8.0)
43
+ diff-lcs (>= 1.2.0, < 2.0)
44
+ rspec-support (~> 3.8.0)
45
+ rspec-support (3.8.0)
46
+ rspec_junit_formatter (0.4.1)
47
+ rspec-core (>= 2, < 4, != 2.12.0)
48
+ rubocop (0.67.2)
49
+ jaro_winkler (~> 1.5.1)
50
+ parallel (~> 1.10)
51
+ parser (>= 2.5, != 2.5.1.1)
52
+ psych (>= 3.1.0)
53
+ rainbow (>= 2.2.2, < 4.0)
54
+ ruby-progressbar (~> 1.7)
55
+ unicode-display_width (>= 1.4.0, < 1.6)
56
+ ruby-progressbar (1.10.0)
57
+ standard (0.0.39)
58
+ rubocop (~> 0.67.1)
59
+ stub_env (1.0.4)
60
+ rspec (>= 2.0, < 4.0)
61
+ thread_safe (0.3.6)
62
+ tzinfo (1.2.5)
63
+ thread_safe (~> 0.1)
64
+ unicode-display_width (1.5.0)
65
+
66
+ PLATFORMS
67
+ ruby
68
+
69
+ DEPENDENCIES
70
+ bundler (~> 1.17)
71
+ nxt_heroku_env!
72
+ pry
73
+ rake (~> 10.0)
74
+ rspec (~> 3.0)
75
+ rspec_junit_formatter
76
+ standard
77
+ stub_env
78
+
79
+ BUNDLED WITH
80
+ 1.17.2
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Nils Sommer
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.
@@ -0,0 +1,79 @@
1
+ [![CircleCI](https://circleci.com/gh/nxt-insurance/nxt_heroku_env.svg?style=svg)](https://circleci.com/gh/nxt-insurance/nxt_heroku_env)
2
+
3
+ # NxtHerokuEnv
4
+
5
+ This gem checks the `HEROKU_APP_NAME` environment variable that is set by Heroku for any app that runs on Heroku. You can ask the helpers which environment you run in and even draw different routes depending on it. This is useful if your application should behave differently depending on whether it runs in some environment, typically production and staging for example.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'nxt_heroku_env'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install nxt_heroku_env
22
+
23
+ ## Usage
24
+
25
+ A typical application setup on heroku might have a *staging* and a *production* environment. You can set `HerokuEnv` up like this (assuming your heroku app pipelines are named something like `myapp-p` and `myapp-s` for production and staging environments respectively).
26
+
27
+ ```ruby
28
+ HerokuEnv.configure do |config|
29
+ config.add_env production: /myapp-p/
30
+ config.add_env staging: /myapp-s/
31
+ end
32
+ ```
33
+
34
+ If you use rails, you might want to add an initializer with this content to your project (`config/initializers/heroku_env.rb`).
35
+
36
+ Now you can use the DSL methods to ask for the heroku environment your app instance runs in.
37
+
38
+ ```ruby
39
+ HerokuEnv.env
40
+ # => :staging
41
+
42
+ HerokuEnv.staging?
43
+ # => true
44
+
45
+ HerokuEnv.production?
46
+ # => false
47
+ ```
48
+
49
+ There's also a method for each environment that yields a block if the environment matches the one the app runs in. This can be useful e.g. in views when a part of markup should only be rendered when the app runs in a given environment.
50
+
51
+ ```ruby
52
+ HerokuEnv.staging do
53
+ puts "Hello world from staging"
54
+ end
55
+
56
+ # => "Hello world from staging"
57
+
58
+ HerokuEnv.production do
59
+ puts "Hello world from production"
60
+ end
61
+
62
+ # => nil
63
+ ```
64
+
65
+ ## Development
66
+
67
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
68
+
69
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
70
+
71
+ We use the [standard](https://github.com/testdouble/standard) gem to ensure consistent code formatting. Please run `bundle exec standardrb --fix` before commiting to apply the code styles to your changes.
72
+
73
+ ## Contributing
74
+
75
+ Bug reports and pull requests are welcome on GitHub at https://github.com/nxt-insurance/nxt_heroku_env.
76
+
77
+ ## License
78
+
79
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
9
+
10
+ task default: :test
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "nxt_heroku_env"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'rspec' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require "pathname"
12
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
+ Pathname.new(__FILE__).realpath)
14
+
15
+ bundle_binstub = File.expand_path("../bundle", __FILE__)
16
+
17
+ if File.file?(bundle_binstub)
18
+ if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19
+ load(bundle_binstub)
20
+ else
21
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
+ end
24
+ end
25
+
26
+ require "rubygems"
27
+ require "bundler/setup"
28
+
29
+ load Gem.bin_path("rspec-core", "rspec")
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,3 @@
1
+ require "active_support/core_ext/string"
2
+ require "nxt_heroku_env/version"
3
+ require "nxt_heroku_env/heroku_env"
@@ -0,0 +1,40 @@
1
+ module HerokuEnv
2
+ extend self
3
+
4
+ def app_name
5
+ ENV["HEROKU_APP_NAME"].presence
6
+ end
7
+
8
+ def heroku_app_name_to_env_mappings
9
+ @heroku_app_name_to_env_mappings ||= {}
10
+ end
11
+
12
+ def add_env(**args)
13
+ args.each do |env_name, heroku_app_name|
14
+ app_name_pattern = heroku_app_name.is_a?(Regexp) ? heroku_app_name : Regexp.new(heroku_app_name.to_s)
15
+ heroku_app_name_to_env_mappings[app_name_pattern] = env_name.to_sym
16
+
17
+ define_method("#{env_name}?") do
18
+ env == env_name.to_sym
19
+ end
20
+
21
+ define_method(env_name) do |&block|
22
+ block.call if env == env_name.to_sym
23
+ end
24
+ end
25
+ end
26
+
27
+ def env
28
+ @env ||= begin
29
+ env_name = heroku_app_name_to_env_mappings.keys.find { |heroku_app_name_pattern|
30
+ heroku_app_name_pattern.match?(app_name)
31
+ }
32
+
33
+ heroku_app_name_to_env_mappings[env_name]
34
+ end
35
+ end
36
+
37
+ def configure(&block)
38
+ block.call(self)
39
+ end
40
+ end
@@ -0,0 +1,3 @@
1
+ module NxtHerokuEnv
2
+ VERSION = "0.1.0".freeze
3
+ end
@@ -0,0 +1,45 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "nxt_heroku_env/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "nxt_heroku_env"
7
+ spec.version = NxtHerokuEnv::VERSION
8
+ spec.authors = ["Nils Sommer", "Andreas Robecke", "Raphael Kallensee"]
9
+ spec.email = ["mail@nilssommer.de"]
10
+
11
+ spec.summary = "Helpers to ask which heroku environment an app runs in."
12
+ spec.homepage = "https://github.com/nxt-insurance/nxt_heroku_env"
13
+ spec.license = "MIT"
14
+
15
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
16
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
17
+ if spec.respond_to?(:metadata)
18
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
19
+
20
+ spec.metadata["homepage_uri"] = spec.homepage
21
+ spec.metadata["source_code_uri"] = "https://github.com/nxt-insurance/nxt_heroku_env"
22
+ spec.metadata["changelog_uri"] = "https://github.com/nxt-insurance/nxt_heroku_env/CHANGELOG.md"
23
+ else
24
+ raise "RubyGems 2.0 or newer is required to protect against " \
25
+ "public gem pushes."
26
+ end
27
+
28
+ # Specify which files should be added to the gem when it is released.
29
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
30
+ spec.files = Dir.chdir(File.expand_path("..", __FILE__)) do
31
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
32
+ end
33
+ spec.bindir = "exe"
34
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
35
+ spec.require_paths = ["lib"]
36
+
37
+ spec.add_development_dependency "bundler", "~> 1.17"
38
+ spec.add_development_dependency "rake", "~> 10.0"
39
+ spec.add_development_dependency "pry"
40
+ spec.add_development_dependency "rspec", "~> 3.0"
41
+ spec.add_development_dependency "stub_env"
42
+ spec.add_development_dependency "standard"
43
+
44
+ spec.add_dependency "activesupport"
45
+ end
metadata ADDED
@@ -0,0 +1,165 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nxt_heroku_env
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Nils Sommer
8
+ - Andreas Robecke
9
+ - Raphael Kallensee
10
+ autorequire:
11
+ bindir: exe
12
+ cert_chain: []
13
+ date: 2019-04-23 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: bundler
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - "~>"
20
+ - !ruby/object:Gem::Version
21
+ version: '1.17'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - "~>"
27
+ - !ruby/object:Gem::Version
28
+ version: '1.17'
29
+ - !ruby/object:Gem::Dependency
30
+ name: rake
31
+ requirement: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - "~>"
34
+ - !ruby/object:Gem::Version
35
+ version: '10.0'
36
+ type: :development
37
+ prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - "~>"
41
+ - !ruby/object:Gem::Version
42
+ version: '10.0'
43
+ - !ruby/object:Gem::Dependency
44
+ name: pry
45
+ requirement: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ type: :development
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ - !ruby/object:Gem::Dependency
58
+ name: rspec
59
+ requirement: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - "~>"
62
+ - !ruby/object:Gem::Version
63
+ version: '3.0'
64
+ type: :development
65
+ prerelease: false
66
+ version_requirements: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - "~>"
69
+ - !ruby/object:Gem::Version
70
+ version: '3.0'
71
+ - !ruby/object:Gem::Dependency
72
+ name: stub_env
73
+ requirement: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ type: :development
79
+ prerelease: false
80
+ version_requirements: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ - !ruby/object:Gem::Dependency
86
+ name: standard
87
+ requirement: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ type: :development
93
+ prerelease: false
94
+ version_requirements: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ - !ruby/object:Gem::Dependency
100
+ name: activesupport
101
+ requirement: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ type: :runtime
107
+ prerelease: false
108
+ version_requirements: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ description:
114
+ email:
115
+ - mail@nilssommer.de
116
+ executables: []
117
+ extensions: []
118
+ extra_rdoc_files: []
119
+ files:
120
+ - ".circleci/config.yml"
121
+ - ".editorconfig"
122
+ - ".gitignore"
123
+ - ".rspec"
124
+ - ".ruby-version"
125
+ - CHANGELOG.md
126
+ - Gemfile
127
+ - Gemfile.lock
128
+ - LICENSE.txt
129
+ - README.md
130
+ - Rakefile
131
+ - bin/console
132
+ - bin/rspec
133
+ - bin/setup
134
+ - lib/nxt_heroku_env.rb
135
+ - lib/nxt_heroku_env/heroku_env.rb
136
+ - lib/nxt_heroku_env/version.rb
137
+ - nxt_heroku_env.gemspec
138
+ homepage: https://github.com/nxt-insurance/nxt_heroku_env
139
+ licenses:
140
+ - MIT
141
+ metadata:
142
+ allowed_push_host: https://rubygems.org
143
+ homepage_uri: https://github.com/nxt-insurance/nxt_heroku_env
144
+ source_code_uri: https://github.com/nxt-insurance/nxt_heroku_env
145
+ changelog_uri: https://github.com/nxt-insurance/nxt_heroku_env/CHANGELOG.md
146
+ post_install_message:
147
+ rdoc_options: []
148
+ require_paths:
149
+ - lib
150
+ required_ruby_version: !ruby/object:Gem::Requirement
151
+ requirements:
152
+ - - ">="
153
+ - !ruby/object:Gem::Version
154
+ version: '0'
155
+ required_rubygems_version: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ requirements: []
161
+ rubygems_version: 3.0.3
162
+ signing_key:
163
+ specification_version: 4
164
+ summary: Helpers to ask which heroku environment an app runs in.
165
+ test_files: []