env-checker 0.1.0 → 0.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ba5dc70e0bb1caa59a590c04462c078179acac60
4
- data.tar.gz: 82f2e65694f42693073a6e883717d280c23a17df
3
+ metadata.gz: bcca1afc9d8e9b643130ad0acc664d52628187c6
4
+ data.tar.gz: dfd883610347cdfac5112599fa332c8671dcc7b4
5
5
  SHA512:
6
- metadata.gz: fb5eed10a632c846d3b63ffbf17f11525e879e0a945c8b7aa0406dedc2eaa5aee32bdd0a2d5c87b3f54ba432d1589e0154752ca907722b792eaf9224256ebddb
7
- data.tar.gz: 4e44a55a95f37fef15099574350a979a9de7ce375d903c1dacbdfe6ef39a3e0f4b5f681bb4d99631082b050b015f8fb555412298873b2bef0cfb5319c85f5cc4
6
+ metadata.gz: 1fea0979d2f9412ee81e4eca2251ec6cca3b3ae32aec6f5602265f426880a10d183ed6ca94a3d8c0c30eb8f8ca3a8b805c9ad41fb8d76b9681872a3e0e0cc272
7
+ data.tar.gz: 99a3af47a75a5635155be3671b1cd05075e46548389096334ab12479822116209257fb185b413550f210c16532cc2db0aeace7c604dc9e76546825c39090d09a
@@ -1,5 +1,7 @@
1
- require: rubocop-rspec
2
1
  inherit_from: .rubocop_todo.yml
3
2
 
3
+ AllCops:
4
+ TargetRubyVersion: 2.3
5
+
4
6
  Style/Documentation:
5
7
  Enabled: false
@@ -1,26 +1,18 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2016-11-05 18:58:49 +0100 using RuboCop version 0.45.0.
3
+ # on 2016-11-05 22:54:49 +0100 using RuboCop version 0.45.0.
4
4
  # The point is for the user to remove these configuration records
5
5
  # one by one as the offenses are removed from the code base.
6
6
  # Note that changes in the inspected code, or installation of new
7
7
  # versions of RuboCop, may require this file to be generated again.
8
8
 
9
- # Offense count: 7
9
+ # Offense count: 2
10
10
  # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives.
11
11
  # URISchemes: http, https
12
12
  Metrics/LineLength:
13
- Max: 96
14
-
15
- # Offense count: 2
16
- Style/Documentation:
17
- Exclude:
18
- - 'spec/**/*'
19
- - 'test/**/*'
20
- - 'lib/env_checker.rb'
21
- - 'lib/env_checker/configuration.rb'
13
+ Max: 84
22
14
 
23
- # Offense count: 10
15
+ # Offense count: 13
24
16
  # Cop supports --auto-correct.
25
17
  # Configuration parameters: EnforcedStyle, SupportedStyles.
26
18
  # SupportedStyles: when_needed, always
@@ -34,15 +26,12 @@ Style/FrozenStringLiteralComment:
34
26
  - 'lib/env_checker/configuration.rb'
35
27
  - 'lib/env_checker/missing_keys_error.rb'
36
28
  - 'lib/env_checker/version.rb'
29
+ - 'spec/env_checker/configuration_spec.rb'
30
+ - 'spec/env_checker/missing_keys_error_spec.rb'
31
+ - 'spec/env_checker/version_spec.rb'
37
32
  - 'spec/env_checker_spec.rb'
38
33
  - 'spec/spec_helper.rb'
39
34
 
40
- # Offense count: 1
41
- # Configuration parameters: MinBodyLength.
42
- Style/GuardClause:
43
- Exclude:
44
- - 'lib/env_checker.rb'
45
-
46
35
  # Offense count: 1
47
36
  # Cop supports --auto-correct.
48
37
  # Configuration parameters: SupportedStyles, UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols.
@@ -50,12 +39,6 @@ Style/GuardClause:
50
39
  Style/HashSyntax:
51
40
  EnforcedStyle: hash_rockets
52
41
 
53
- # Offense count: 3
54
- # Cop supports --auto-correct.
55
- Style/LeadingCommentSpace:
56
- Exclude:
57
- - 'env-checker.gemspec'
58
-
59
42
  # Offense count: 1
60
43
  # Cop supports --auto-correct.
61
44
  Style/MutableConstant:
@@ -76,20 +59,6 @@ Style/PercentLiteralDelimiters:
76
59
  Style/RaiseArgs:
77
60
  EnforcedStyle: compact
78
61
 
79
- # Offense count: 28
80
- # Cop supports --auto-correct.
81
- # Configuration parameters: EnforcedStyle, SupportedStyles, ConsistentQuotesInMultiline.
82
- # SupportedStyles: single_quotes, double_quotes
83
- Style/StringLiterals:
84
- Exclude:
85
- - 'Rakefile'
86
- - 'bin/console'
87
- - 'env-checker.gemspec'
88
- - 'lib/env_checker.rb'
89
- - 'lib/env_checker/version.rb'
90
- - 'spec/env_checker_spec.rb'
91
- - 'spec/spec_helper.rb'
92
-
93
62
  # Offense count: 2
94
63
  # Cop supports --auto-correct.
95
64
  Style/UnneededPercentQ:
@@ -1,13 +1,21 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- env-checker (0.1.0)
4
+ env-checker (0.1.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
9
  ast (2.3.0)
10
+ coveralls (0.8.15)
11
+ json (>= 1.8, < 3)
12
+ simplecov (~> 0.12.0)
13
+ term-ansicolor (~> 1.3)
14
+ thor (~> 0.19.1)
15
+ tins (>= 1.6.0, < 2)
10
16
  diff-lcs (1.2.5)
17
+ docile (1.1.5)
18
+ json (2.0.2)
11
19
  parser (2.3.1.4)
12
20
  ast (~> 2.2)
13
21
  powerpack (0.1.1)
@@ -32,9 +40,16 @@ GEM
32
40
  rainbow (>= 1.99.1, < 3.0)
33
41
  ruby-progressbar (~> 1.7)
34
42
  unicode-display_width (~> 1.0, >= 1.0.1)
35
- rubocop-rspec (1.8.0)
36
- rubocop (>= 0.42.0)
37
43
  ruby-progressbar (1.8.1)
44
+ simplecov (0.12.0)
45
+ docile (~> 1.1.0)
46
+ json (>= 1.8, < 3)
47
+ simplecov-html (~> 0.10.0)
48
+ simplecov-html (0.10.0)
49
+ term-ansicolor (1.4.0)
50
+ tins (~> 1.0)
51
+ thor (0.19.1)
52
+ tins (1.12.0)
38
53
  unicode-display_width (1.1.1)
39
54
 
40
55
  PLATFORMS
@@ -42,11 +57,12 @@ PLATFORMS
42
57
 
43
58
  DEPENDENCIES
44
59
  bundler (~> 1.13)
60
+ coveralls (~> 0)
45
61
  env-checker!
46
62
  rake (~> 10.0)
47
63
  rspec (~> 3.0)
48
- rubocop
49
- rubocop-rspec
64
+ rubocop (~> 0)
65
+ simplecov (~> 0)
50
66
 
51
67
  BUNDLED WITH
52
68
  1.13.6
data/README.md CHANGED
@@ -1,9 +1,18 @@
1
- # EnvChecker
1
+ # Env-checker
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/env-checker.svg)](https://badge.fury.io/rb/env-checker)
4
+ [![Dependency Status](https://gemnasium.com/badges/github.com/ryanfox1985/env-checker.svg)](https://gemnasium.com/github.com/ryanfox1985/env-checker)
5
+ [![Build Status](https://travis-ci.org/ryanfox1985/env-checker.svg?branch=master)](https://travis-ci.org/ryanfox1985/env-checker)
6
+ [![Coverage Status](https://coveralls.io/repos/github/ryanfox1985/env-checker/badge.svg?branch=master)](https://coveralls.io/github/ryanfox1985/env-checker?branch=master)
7
+ [![Code Climate](https://codeclimate.com/github/ryanfox1985/env-checker/badges/gpa.svg)](https://codeclimate.com/github/ryanfox1985/env-checker)
8
+ [![license](https://img.shields.io/github/license/mashape/apistatus.svg)](https://github.com/ryanfox1985/env-checker/blob/master/LICENSE)
9
+
2
10
 
3
11
  Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/env_checker`. To experiment with that code, run `bin/console` for an interactive prompt.
4
12
 
5
13
  TODO: Delete this and the text above, and describe your gem
6
14
 
15
+
7
16
  ## Installation
8
17
 
9
18
  Add this line to your application's Gemfile:
@@ -20,19 +29,58 @@ Or install it yourself as:
20
29
 
21
30
  $ gem install env-checker
22
31
 
32
+
23
33
  ## Usage
24
34
 
25
- TODO: Write usage instructions here
26
35
 
27
- ## Development
36
+ ### Rails or Ruby standalone
37
+
38
+ Create a initializer to configure the gem and run the hook to check the
39
+ environment variables. Example:
28
40
 
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
41
+ ```ruby
42
+ # config/initializers/env_checker.rb
43
+
44
+ require 'env_checker'
45
+
46
+ EnvChecker.configure do |config|
47
+ config.optional_variables = %w(MyVar1 MyVar2)
48
+ config.required_variables = %w(MyVar1 MyVar2)
49
+
50
+ # LOGGER
51
+ # ======
52
+ # Default is:
53
+ #
54
+ # config.logger = Logger.new(STDERR)
55
+ #
56
+ # Some possible settings:
57
+ # config.logger = Rails.logger # Log with all your app's other messages
58
+ # config.logger = Logger.new('log/env_checker.log') # Use this file
59
+ # config.logger = Logger.new('/dev/null') # Don't log at all (on a Unix system)
60
+ end
61
+
62
+ # Example to run always
63
+ [YOUR_APP]::Application.config.after_initialize do
64
+ EnvChecker.check_environment_variables
65
+ end
66
+
67
+ # Example to run in specific environments
68
+ if Rails.env.production? || Rails.env.test?
69
+ [YOUR_APP]::Application.config.after_initialize do
70
+ EnvChecker.check_environment_variables
71
+ end
72
+ end
73
+ ```
74
+
75
+
76
+ ### Standalone and CLI
77
+
78
+ TODO: Write usage instructions here
30
79
 
31
- 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).
32
80
 
33
81
  ## Contributing
34
82
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/env-checker. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
83
+ Bug reports and pull requests are welcome on GitHub at https://github.com/ryanfox1985/env-checker. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
36
84
 
37
85
 
38
86
  ## License
data/Rakefile CHANGED
@@ -1,5 +1,5 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
3
 
4
4
  RSpec::Core::RakeTask.new(:spec)
5
5
 
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require "bundler/setup"
4
- require "env_checker"
3
+ require 'bundler/setup'
4
+ require 'env_checker'
5
5
 
6
6
  # You can add fixtures and/or initialization code here to make experimenting
7
7
  # with your gem easier. You can also use a different console, if you like.
@@ -10,5 +10,5 @@ require "env_checker"
10
10
  # require "pry"
11
11
  # Pry.start
12
12
 
13
- require "irb"
13
+ require 'irb'
14
14
  IRB.start
@@ -4,35 +4,27 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'env_checker/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
- spec.name = "env-checker"
7
+ spec.name = 'env-checker'
8
8
  spec.version = EnvChecker::VERSION
9
- spec.authors = ["Guillermo Guerrero Ibarra"]
10
- spec.email = ["guillermo@guerreroibarra.com"]
9
+ spec.authors = ['Guillermo Guerrero Ibarra']
10
+ spec.email = ['guillermo@guerreroibarra.com']
11
11
 
12
12
  spec.summary = %q{Check your environment variables and don't forget anyone.}
13
13
  spec.description = %q{Check your environment variables and don't forget anyone.}
14
- spec.homepage = "https://github.com/ryanfox1985/env-checker"
15
- spec.license = "MIT"
16
-
17
- # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
- # to allow pushing to a single host or delete this section to allow pushing to any host.
19
- #if spec.respond_to?(:metadata)
20
- # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
21
- #else
22
- # raise "RubyGems 2.0 or newer is required to protect against " \
23
- # "public gem pushes."
24
- #end
14
+ spec.homepage = 'https://github.com/ryanfox1985/env-checker'
15
+ spec.license = 'MIT'
25
16
 
26
17
  spec.files = `git ls-files -z`.split("\x0").reject do |f|
27
18
  f.match(%r{^(test|spec|features)/})
28
19
  end
29
- spec.bindir = "exe"
20
+ spec.bindir = 'exe'
30
21
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
- spec.require_paths = ["lib"]
22
+ spec.require_paths = ['lib']
32
23
 
33
- spec.add_development_dependency "bundler", "~> 1.13"
34
- spec.add_development_dependency "rake", "~> 10.0"
35
- spec.add_development_dependency "rspec", "~> 3.0"
36
- spec.add_development_dependency "rubocop-rspec", '~> 0'
37
- spec.add_development_dependency "rubocop", '~> 0'
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
+ spec.add_development_dependency 'rubocop', '~> 0'
28
+ spec.add_development_dependency 'coveralls', '~> 0'
29
+ spec.add_development_dependency 'simplecov', '~> 0'
38
30
  end
@@ -1,23 +1,18 @@
1
1
  $LOAD_PATH.unshift(File.dirname(__FILE__))
2
2
 
3
- require "env_checker/version"
4
- require "env_checker/missing_keys_error"
5
- require "env_checker/configuration"
3
+ require 'env_checker/version'
4
+ require 'env_checker/missing_keys_error'
5
+ require 'env_checker/configuration'
6
6
 
7
7
  module EnvChecker
8
8
  class << self
9
9
  attr_accessor :configuration
10
10
 
11
11
  def check_environment_variables
12
- if configuration.optional_variables
13
- missing_keys = missing_keys_environment(configuration.optional_variables)
14
- puts missing_keys # TODO: do something more.
15
- end
12
+ bov = check_optional_variables
13
+ brv = check_required_variables
16
14
 
17
- if configuration.required_variables
18
- missing_keys = missing_keys_environment(configuration.required_variables)
19
- raise MissingKeysError.new(missing_keys) if missing_keys.any?
20
- end
15
+ bov & brv
21
16
  end
22
17
 
23
18
  def configure
@@ -27,7 +22,51 @@ module EnvChecker
27
22
 
28
23
  private
29
24
 
30
- def missing_keys_environment(keys)
25
+ def check_optional_variables
26
+ if configuration.optional_variables
27
+ missing_keys = missing_keys_env(configuration.optional_variables)
28
+ log_message(:warning, "EnvChecker: Warning missing these optional
29
+ variables: [#{missing_keys}]")
30
+
31
+ return missing_keys.empty?
32
+ end
33
+
34
+ true
35
+ end
36
+
37
+ def check_required_variables
38
+ if configuration.required_variables
39
+ missing_keys = missing_keys_env(configuration.required_variables)
40
+
41
+ if missing_keys.any?
42
+ log_message(:error, "EnvChecker: Error missing these required
43
+ variables: [#{missing_keys}]")
44
+
45
+ raise MissingKeysError.new(missing_keys)
46
+ end
47
+ end
48
+
49
+ true
50
+ end
51
+
52
+ def log_message(type, message)
53
+ return unless configuration
54
+
55
+ # TODO: add other integrations like slack, email...
56
+
57
+ return unless configuration.logger
58
+
59
+ case type
60
+ when :warning
61
+ configuration.logger.warn(message)
62
+ when :error
63
+ configuration.logger.error(message)
64
+ else
65
+ configuration.logger.info(message)
66
+ end
67
+ end
68
+
69
+ def missing_keys_env(keys)
31
70
  keys.flatten - ::ENV.keys
32
71
  end
33
72
  end
@@ -1,11 +1,13 @@
1
+ require 'logger'
2
+
1
3
  module EnvChecker
2
4
  class Configuration
3
- # Has default settings, which can be overridden in the initializer.
4
-
5
5
  attr_accessor :required_variables, :optional_variables, :logger
6
6
 
7
+ # Has default settings, which can be overridden in the initializer.
7
8
  def initialize
8
9
  @required_variables = []
10
+ @optional_variables = []
9
11
  @logger = Logger.new(STDERR)
10
12
  end
11
13
  end
@@ -1,3 +1,3 @@
1
1
  module EnvChecker
2
- VERSION = "0.1.0"
2
+ VERSION = '0.1.1'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: env-checker
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
  - Guillermo Guerrero Ibarra
@@ -53,7 +53,7 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: rubocop-rspec
56
+ name: rubocop
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
@@ -67,7 +67,21 @@ dependencies:
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
- name: rubocop
70
+ name: coveralls
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: simplecov
71
85
  requirement: !ruby/object:Gem::Requirement
72
86
  requirements:
73
87
  - - "~>"
@@ -96,7 +110,6 @@ files:
96
110
  - Gemfile
97
111
  - Gemfile.lock
98
112
  - LICENSE
99
- - LICENSE.txt
100
113
  - README.md
101
114
  - Rakefile
102
115
  - bin/console
@@ -1,21 +0,0 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2016 Guillermo Guerrero
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.