env-checker 0.1.6 → 0.1.7

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: d606bb4975be0f760db096c69b4a23c746c6ec2f
4
- data.tar.gz: 4d302b7b62a1dd1af3fbc4429128ed1060702a7e
3
+ metadata.gz: f282676d3c5ae43ac48a7f113ee2b431bcc99b8a
4
+ data.tar.gz: 0eb4785314b9a54a23f18d0f34d8f5e02f11b05b
5
5
  SHA512:
6
- metadata.gz: 28805353881884386a46352ce6d3d6a435bcddc1394834a4d973816aabf3f46e9d428c52ae19f7e6596f10d0a7dca921160bf335d607d03b24e41d2179e0da8a
7
- data.tar.gz: 01edfd571a14417c19f1d8df31b46bebe5fd1d18a73ada466cc02b8104ac8a88d25d6bae48c95e535ed0ffa6a0cfa69c1eba942c8a38603ddd288d68d41c49d9
6
+ metadata.gz: e8b80854cb56561b72c4392f6b54ba8325e095333822904ccab9258176acce7d07c96a9faaaa2a80678c33e2fda69affdd9174afcebf6e4d825ecc608057422b
7
+ data.tar.gz: 84f4880d192b258c34b3c3b95d9f74e800fe84c4768cd2be0448110275e340c29c2e861e1abdfea52a4445bf26060b532e8eeaf279bf3e6ff52bbf6b68a12c65
@@ -1,34 +1,35 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2016-11-12 02:10:52 +0100 using RuboCop version 0.45.0.
3
+ # on 2016-11-17 20:42:19 +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: 4
9
+ # Offense count: 3
10
10
  Metrics/AbcSize:
11
- Max: 23
11
+ Max: 29
12
12
 
13
13
  # Offense count: 1
14
14
  # Configuration parameters: CountComments.
15
15
  Metrics/BlockLength:
16
16
  Max: 32
17
17
 
18
- # Offense count: 1
19
- Metrics/CyclomaticComplexity:
20
- Max: 7
21
-
22
18
  # Offense count: 3
23
19
  # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives.
24
20
  # URISchemes: http, https
25
21
  Metrics/LineLength:
26
22
  Max: 95
27
23
 
28
- # Offense count: 4
24
+ # Offense count: 5
29
25
  # Configuration parameters: CountComments.
30
26
  Metrics/MethodLength:
31
- Max: 13
27
+ Max: 22
28
+
29
+ # Offense count: 1
30
+ # Configuration parameters: CountComments.
31
+ Metrics/ModuleLength:
32
+ Max: 109
32
33
 
33
34
  # Offense count: 1
34
35
  # Cop supports --auto-correct.
@@ -44,7 +45,7 @@ Style/ExtraSpacing:
44
45
  Style/FrozenStringLiteralComment:
45
46
  Enabled: false
46
47
 
47
- # Offense count: 9
48
+ # Offense count: 12
48
49
  # Cop supports --auto-correct.
49
50
  # Configuration parameters: EnforcedStyle, SupportedStyles, UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols.
50
51
  # SupportedStyles: ruby19, hash_rockets, no_mixed_keys, ruby19_no_mixed_keys
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- env-checker (0.1.6)
4
+ env-checker (0.1.7)
5
5
  slack-notifier (~> 1.5)
6
6
  thor (~> 0.19.1)
7
7
 
data/README.md CHANGED
@@ -20,10 +20,16 @@ You can define two variable lists:
20
20
  - **optional_variables:** These variables are from secondary services (Your app
21
21
  can run without these variables, like some `THRESHOLD`)
22
22
 
23
+ By default `EnvChecker` checks the global environment and after the current
24
+ or set environment.
25
+
23
26
  All the missing variables are notified by default in the `STDERR`. When a
24
27
  required variable is missing the gem raises an error `MissingKeysError` and
25
28
  stops the application.
26
29
 
30
+ By convention all the environment variable names must be in up case, the gem
31
+ internally parse the required_variables and optional_variables to up case.
32
+
27
33
  ## Installation
28
34
 
29
35
  Add this line to your application's Gemfile:
@@ -89,6 +95,18 @@ Inline passing the variables with the shell:
89
95
 
90
96
  $ env-checker check --optional MyOptVar1 MyOptVar2 --required MyReqVar1 MyReqVar2
91
97
 
98
+ Usage:
99
+ env-checker check
100
+
101
+ Options:
102
+ e, [--environment=ENVIRONMENT]
103
+ cf, [--config-file=CONFIG_FILE]
104
+ r, required, [--required-variables=one two three]
105
+ o, optional, [--optional-variables=one two three]
106
+ slack, [--slack-webhook-url=SLACK_WEBHOOK_URL]
107
+ [--run=RUN]
108
+
109
+
92
110
  Example with a `.yml` [example file](https://raw.githubusercontent.com/ryanfox1985/env-checker/master/sample_config.yml):
93
111
 
94
112
  $ env-checker check --config_file sample_config.yml
@@ -5,6 +5,7 @@ require 'env_checker/version'
5
5
  require 'env_checker/missing_keys_error'
6
6
  require 'env_checker/configuration'
7
7
  require 'env_checker/cli'
8
+ require 'byebug'
8
9
 
9
10
  module EnvChecker
10
11
  class << self
@@ -18,23 +19,32 @@ module EnvChecker
18
19
  end
19
20
 
20
21
  def cli_configure_and_check(options)
21
- return if !options[:optional] &&
22
- !options[:required] &&
23
- !options[:config_file]
22
+ if run_configure_and_check(options) && options[:run]
23
+ exit(system(options[:run]))
24
+ end
25
+
26
+ exit(true)
27
+ end
28
+
29
+ private
30
+
31
+ def run_configure_and_check(options)
32
+ return true if !options[:optional_variables] &&
33
+ !options[:required_variables] &&
34
+ !options[:config_file]
24
35
 
25
36
  self.configurations = create_config_from_parameters(options)
26
37
 
27
38
  begin
28
39
  exit(1) unless after_configure_and_check(configurations['global'])
29
- exit(true)
30
40
  rescue EnvChecker::MissingKeysError
31
41
  exit 2
32
42
  rescue EnvChecker::ConfigurationError
33
43
  exit 3
34
44
  end
35
- end
36
45
 
37
- private
46
+ true
47
+ end
38
48
 
39
49
  def after_configure_and_check(configuration)
40
50
  configuration.after_initialize
@@ -58,9 +68,17 @@ module EnvChecker
58
68
  end
59
69
 
60
70
  config.environment = options[:environment] if options[:environment]
61
- config.optional_variables = options[:optional] if options[:optional]
62
- config.required_variables = options[:required] if options[:required]
63
- config.slack_webhook_url = options[:slack] if options[:slack]
71
+ if options[:optional_variables]
72
+ config.optional_variables = options[:optional_variables]
73
+ end
74
+
75
+ if options[:required_variables]
76
+ config.required_variables = options[:required_variables]
77
+ end
78
+
79
+ if options[:slack_webhook_url]
80
+ config.slack_webhook_url = options[:slack_webhook_url]
81
+ end
64
82
 
65
83
  { 'global' => config }
66
84
  end
@@ -12,20 +12,34 @@ module EnvChecker
12
12
  option :required_variables, :aliases => [:r, :required], :type => :array
13
13
  option :optional_variables, :aliases => [:o, :optional], :type => :array
14
14
  option :slack_webhook_url, :aliases => :slack, :type => :string
15
+ option :run, :type => :string
15
16
  desc 'check', 'Check optional and required environment variables.'
16
17
  def check
17
18
  output = []
18
19
  output << 'Variables: '
19
20
 
20
- variables = %w(config_file slack_webhook_url optional required)
21
+ variables = %w(config_file
22
+ slack_webhook_url
23
+ environment
24
+ run
25
+ optional_variables
26
+ required_variables)
27
+
28
+ my_options = {}
21
29
  variables.each do |v|
22
- # TODO: get config variables from current environment
23
- # options[v.to_sym] ||= ENV[v.to_sym] if ENV[v.to_sym]
24
- output << "- #{v}: #{options[v.to_sym]}" if options[v.to_sym]
30
+ if ENV[v.upcase]
31
+ my_options[v.to_sym] ||= if v.upcase.include?('VARIABLES')
32
+ ENV[v.upcase].split(' ')
33
+ else
34
+ ENV[v.upcase]
35
+ end
36
+ end
37
+ my_options[v.to_sym] = options[v.to_sym] if options[v.to_sym]
38
+ output << "- #{v}: #{my_options[v.to_sym]}" if my_options[v.to_sym]
25
39
  end
26
40
  puts output.join("\n")
27
41
 
28
- EnvChecker.cli_configure_and_check(options)
42
+ EnvChecker.cli_configure_and_check(my_options)
29
43
  end
30
44
  end
31
45
  end
@@ -26,6 +26,12 @@ module EnvChecker
26
26
  @slack_webhook_url != '' &&
27
27
  @slack_notifier = Slack::Notifier.new(@slack_webhook_url)
28
28
 
29
+ @required_variables &&
30
+ @required_variables = @required_variables.map(&:upcase)
31
+
32
+ @optional_variables &&
33
+ @optional_variables = @optional_variables.map(&:upcase)
34
+
29
35
  true
30
36
  end
31
37
 
@@ -1,3 +1,3 @@
1
1
  module EnvChecker
2
- VERSION = '0.1.6'
2
+ VERSION = '0.1.7'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: env-checker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Guillermo Guerrero Ibarra
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-11-15 00:00:00.000000000 Z
11
+ date: 2016-11-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor