exercism-config 0.35.0 → 0.36.0

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
  SHA256:
3
- metadata.gz: 401b3183f0a461e800f197b80dc749b27f5b510dd2c5d0d5dbd4db5b05fd43b8
4
- data.tar.gz: 966a7406de8ab62637608ee07001d22bc085170f183202919d655f8f5c3b3d3b
3
+ metadata.gz: 97a6e5acb4ba0d52a4c9ace53896415a63c223bad24b8efc9b0390f0740d7307
4
+ data.tar.gz: b5b66fdec816ae029fa2f4db3e1db28f538f29f74a4b71473e007e0991845565
5
5
  SHA512:
6
- metadata.gz: 6085bfd7a01d9470a55efd75d9bce1ec11f2855651eabcc20becbd974776298cb38c6b110742e5769c40e906b44954c84e3e74c9221c4644673b91126d591168
7
- data.tar.gz: 5ae15d20611d6a2b225a004efd57308c4fe5dfa41a49ea3e4c0d5b64662fc785808e7f635eb41d5a496c13bd483099f26b285c2c3ec5a5b91b8f30dde6ffcdd3
6
+ metadata.gz: a210de31c00337cfa8d713fa4fde4854a3ddd8ea08a8057179bd8996d829e6968a31b349e5a11e5e082a6c406f19192203321e6062670d9aa14e88da2c12017d
7
+ data.tar.gz: c623fa955cdeaa244540ecc5785d5dd862321aa06f0a004a2cc7cbe5ecd6d067415e02c5dc0db79f2fe052148847cdc7b81c462d05e31f9edce679eb10362a7e
@@ -3,7 +3,7 @@ require "bundler/setup"
3
3
  require "exercism-config"
4
4
 
5
5
  # Only allow this to run in development
6
- return unless Exercism.environment == :development
6
+ return unless Exercism.env.development?
7
7
 
8
8
  puts "Create AWS/DynamoDB tables..."
9
9
 
@@ -3,6 +3,7 @@ require 'mandate'
3
3
  require 'ostruct'
4
4
  require 'json'
5
5
 
6
+ require_relative 'exercism_config/environment'
6
7
  require_relative 'exercism_config/determine_environment'
7
8
  require_relative 'exercism_config/generate_aws_settings'
8
9
  require_relative 'exercism_config/setup_dynamodb_client'
@@ -14,11 +15,15 @@ require_relative 'exercism_config/version'
14
15
  require_relative 'exercism/config'
15
16
 
16
17
  module Exercism
17
- class ConfigError < RuntimeError
18
+ class ConfigError < RuntimeError; end
19
+
20
+ def self.env
21
+ @environment ||= ExercismConfig::DetermineEnvironment.()
18
22
  end
19
23
 
20
24
  def self.environment
21
- @environment ||= ExercismConfig::DetermineEnvironment.()
25
+ puts "Exercism.environment is deprecated. Use Exercism.env"
26
+ env
22
27
  end
23
28
 
24
29
  def self.config
@@ -6,11 +6,7 @@ module ExercismConfig
6
6
  env = ENV['EXERCISM_ENV'] || ENV['RAILS_ENV'] || ENV['APP_ENV']
7
7
  raise Exercism::ConfigError, 'No environment set - set one of EXERCISM_ENV, RAILS_ENV or APP_ENV' unless env
8
8
 
9
- unless %w[development test production].include?(env)
10
- raise Exercism::ConfigError, "environment must be one of development, test or production. Got #{env}."
11
- end
12
-
13
- env.to_sym
9
+ Environment.new(env)
14
10
  end
15
11
  end
16
12
  end
@@ -0,0 +1,49 @@
1
+ module ExercismConfig
2
+ class Environment
3
+ ALLOWED_ENVS = %{development test production}
4
+ private_constant :ALLOWED_ENVS
5
+
6
+ def initialize(raw_env)
7
+ @env = raw_env.to_s
8
+
9
+ unless ALLOWED_ENVS.include?(env)
10
+ raise Exercism::ConfigError, "environment must be one of development, test or production. Got #{env}."
11
+ end
12
+ end
13
+
14
+ def ==(other)
15
+ env == other.to_s
16
+ end
17
+
18
+ def eql?(other)
19
+ env == other.to_s
20
+ end
21
+
22
+ def hash
23
+ env.hash
24
+ end
25
+
26
+ def to_s
27
+ env
28
+ end
29
+
30
+ def inspect
31
+ env
32
+ end
33
+
34
+ def development?
35
+ env == "development"
36
+ end
37
+
38
+ def test?
39
+ env == "test"
40
+ end
41
+
42
+ def production?
43
+ env == "production"
44
+ end
45
+
46
+ private
47
+ attr_reader :env
48
+ end
49
+ end
@@ -13,26 +13,17 @@ module ExercismConfig
13
13
 
14
14
  memoize
15
15
  def aws_access_key_id
16
- case Exercism.environment
17
- when :development, :test
18
- 'FAKE'
19
- end
16
+ Exercism.env.production? ? nil : 'FAKE'
20
17
  end
21
18
 
22
19
  memoize
23
20
  def aws_secret_access_key
24
- case Exercism.environment
25
- when :development, :test
26
- 'FAKE'
27
- end
21
+ Exercism.env.production? ? nil : 'FAKE'
28
22
  end
29
23
 
30
24
  memoize
31
25
  def profile
32
- case Exercism.environment
33
- when :production
34
- 'exercism_staging'
35
- end
26
+ Exercism.env.production? ? nil : 'exercism_staging'
36
27
  end
37
28
  end
38
29
  end
@@ -3,7 +3,7 @@ module ExercismConfig
3
3
  include Mandate
4
4
 
5
5
  def call
6
- return generate_mock if Exercism.environment == :test
6
+ return generate_mock if Exercism.env.test?
7
7
 
8
8
  retrieve_from_dynamodb
9
9
  end
@@ -37,7 +37,7 @@ module ExercismConfig
37
37
  end
38
38
 
39
39
  # Tweak things for dynamodb when we're running in test mode
40
- if Exercism.environment == :test
40
+ if Exercism.env.test?
41
41
  %w[dynamodb_tooling_jobs_table].each do |key|
42
42
  data[key] = "#{data[key]}-test"
43
43
  end
@@ -15,14 +15,11 @@ module ExercismConfig
15
15
  end
16
16
 
17
17
  private
18
- attr_reader :environment
19
18
 
20
19
  memoize
21
20
  def config_endpoint
22
- return nil unless %i[development test].include?(Exercism.environment)
23
- if Exercism.environment == :test && ENV['EXERCISM_CI']
24
- return "http://127.0.0.1:#{ENV['DYNAMODB_PORT']}"
25
- end
21
+ return nil if Exercism.env.production?
22
+ return "http://127.0.0.1:#{ENV['DYNAMODB_PORT']}" if Exercism.env.test? && ENV['EXERCISM_CI']
26
23
 
27
24
  host = ENV['EXERCISM_DOCKER'] ? 'dynamodb:8000' : 'localhost:3040'
28
25
  "http://#{host}"
@@ -18,11 +18,10 @@ module ExercismConfig
18
18
  end
19
19
 
20
20
  private
21
- attr_reader :environment
22
21
 
23
22
  memoize
24
23
  def config_endpoint
25
- return nil unless %i[development test].include?(Exercism.environment)
24
+ return nil if Exercism.env.production?
26
25
  return "http://127.0.0.1:#{ENV['S3_PORT']}" if ENV['EXERCISM_CI']
27
26
 
28
27
  host = ENV['EXERCISM_DOCKER'] ? 's3:9090' : 'localhost:3041'
@@ -1,3 +1,3 @@
1
1
  module ExercismConfig
2
- VERSION = '0.35.0'.freeze
2
+ VERSION = '0.36.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: exercism-config
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.35.0
4
+ version: 0.36.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Walker
@@ -150,6 +150,7 @@ files:
150
150
  - lib/exercism-config.rb
151
151
  - lib/exercism/config.rb
152
152
  - lib/exercism_config/determine_environment.rb
153
+ - lib/exercism_config/environment.rb
153
154
  - lib/exercism_config/generate_aws_settings.rb
154
155
  - lib/exercism_config/retrieve.rb
155
156
  - lib/exercism_config/setup_dynamodb_client.rb