exercism_config 0.11.0 → 0.16.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: 29923659114d2bf254bad2e019a321f070cb3ff299ed4ea8ce715e92b8fd316e
4
- data.tar.gz: ab184837acd4f8df85259f8b92004a6b120232874d1b83cccdb7a4afcddaf8f8
3
+ metadata.gz: 75202fecc54b1825dc26f9e60d665857889b7811447c6901578934dc470b111b
4
+ data.tar.gz: 27f499b1562ad2ce6edde2cd8708f7cff05467f821f933f5e462dde483cdb4d1
5
5
  SHA512:
6
- metadata.gz: 893a4ffaa832a31aed0896a6191ce52e466a5cf1341a2f96674a55373cf0b011a815e51f3e832b38e4166616a95102cc4347ed63b549f3407f67efc7fb533947
7
- data.tar.gz: 424ce4177752ef4da4d8745ff1d3766396ff9ccd7a872cf1697383b3d73eec13933bc149dcf36665496f6eb8d8b11c1eacd44f989d8882eb9e0ebcb888f77a52
6
+ metadata.gz: 79df4d09897c5ed3c9ef96af5b0435d39e1418fa0d82b23b8047b4003c66d828d8651989353433a21e9d791e106e6fbf693770a0c6b2328d49bc324d29e72b98
7
+ data.tar.gz: 5385e1048f4eb054225447c5f7f84b7f9b433d231511698912c4681a15615d67b51a35b8977bf1af5baabe15038b5e7d0c2d3ea26fef412c017305659fb5526b
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- exercism_config (0.8.0)
4
+ exercism_config (0.11.0)
5
5
  aws-sdk-dynamodb (~> 1.0)
6
6
  mandate
7
7
  zeitwerk
@@ -3,8 +3,9 @@ require 'mandate'
3
3
  require "ostruct"
4
4
  require 'json'
5
5
 
6
+ require_relative 'exercism_config/determine_environment'
6
7
  require_relative 'exercism_config/generate_aws_settings'
7
- require_relative 'exercism_config/setup_dynamodb_client.rb'
8
+ require_relative 'exercism_config/setup_dynamodb_client'
8
9
  require_relative 'exercism_config/retrieve'
9
10
  require_relative 'exercism_config/generate_aws_settings'
10
11
  require_relative "exercism_config/version"
@@ -15,6 +16,10 @@ module Exercism
15
16
  class ConfigError < RuntimeError
16
17
  end
17
18
 
19
+ def self.environment
20
+ @environment ||= ExercismConfig::DetermineEnvironment.()
21
+ end
22
+
18
23
  def self.config
19
24
  @config ||= ExercismConfig::Retrieve.()
20
25
  end
@@ -2,10 +2,6 @@ module ExercismConfig
2
2
  class GenerateAwsSettings
3
3
  include Mandate
4
4
 
5
- def initialize(environment)
6
- @environment = environment
7
- end
8
-
9
5
  def call
10
6
  {
11
7
  region: 'eu-west-2',
@@ -17,7 +13,7 @@ module ExercismConfig
17
13
 
18
14
  memoize
19
15
  def aws_access_key_id
20
- case environment
16
+ case Exercism.environment
21
17
  when :development, :test
22
18
  "FAKE"
23
19
  else
@@ -27,7 +23,7 @@ module ExercismConfig
27
23
 
28
24
  memoize
29
25
  def aws_secret_access_key
30
- case environment
26
+ case Exercism.environment
31
27
  when :development, :test
32
28
  "FAKE"
33
29
  else
@@ -37,24 +33,10 @@ module ExercismConfig
37
33
 
38
34
  memoize
39
35
  def profile
40
- case environment
36
+ case Exercism.environment
41
37
  when :production
42
38
  "exercism_staging"
43
39
  end
44
40
  end
45
-
46
- memoize
47
- def environment
48
- return @environment.to_sym if @environment
49
-
50
- env = ENV["EXERCISM_ENV"] || ENV["RAILS_ENV"] || ENV["APP_ENV"]
51
- raise Exercism::ConfigError, "No environment set - set one of EXERCISM_ENV, RAILS_ENV or APP_ENV" unless env
52
-
53
- unless %w[development test production].include?(env)
54
- raise Exercism::ConfigError, "environments must be one of development test production. Got #{env}"
55
- end
56
-
57
- env.to_sym
58
- end
59
41
  end
60
42
  end
@@ -2,12 +2,8 @@ module ExercismConfig
2
2
  class Retrieve
3
3
  include Mandate
4
4
 
5
- def initialize(environment = nil)
6
- @environment = environment
7
- end
8
-
9
5
  def call
10
- client = SetupDynamodbClient.(environment)
6
+ client = SetupDynamoDBClient.()
11
7
 
12
8
  resp = client.scan({table_name: "config"})
13
9
  items = resp.to_h[:items]
@@ -15,7 +11,14 @@ module ExercismConfig
15
11
  h[item['id']] = item['value']
16
12
  end
17
13
 
18
- aws_settings = GenerateAwsSettings.(environment)
14
+ # Tweak things for dynamodb when we're running in test mode
15
+ if Exercism.environment == :test
16
+ %w{dynamodb_tooling_jobs_table}.each do |key|
17
+ data[key] = "#{data[key]}-test"
18
+ end
19
+ end
20
+
21
+ aws_settings = GenerateAwsSettings.()
19
22
  Exercism::Config.new(data, aws_settings)
20
23
  rescue Exercism::ConfigError
21
24
  raise
@@ -36,20 +39,6 @@ module ExercismConfig
36
39
 
37
40
  Aws::DynamoDB::Client.new(config)
38
41
  end
39
-
40
- memoize
41
- def environment
42
- return @environment.to_sym if @environment
43
-
44
- env = ENV["EXERCISM_ENV"] || ENV["RAILS_ENV"] || ENV["APP_ENV"]
45
- raise Exercism::ConfigError, "No environment set - set one of EXERCISM_ENV, RAILS_ENV or APP_ENV" unless env
46
-
47
- unless %w[development test production].include?(env)
48
- raise Exercism::ConfigError, "environments must be one of development test production. Got #{env}"
49
- end
50
-
51
- env.to_sym
52
- end
53
42
  end
54
43
  end
55
44
 
@@ -1,13 +1,9 @@
1
1
  module ExercismConfig
2
- class SetupDynamodbClient
2
+ class SetupDynamoDBClient
3
3
  include Mandate
4
4
 
5
- def initialize(environment)
6
- @environment = environment
7
- end
8
-
9
5
  def call
10
- aws_settings = GenerateAwsSettings.(environment).merge(
6
+ aws_settings = GenerateAwsSettings.().merge(
11
7
  endpoint: config_endpoint,
12
8
 
13
9
  # We don't want a profile for this AWS service
@@ -23,9 +19,10 @@ module ExercismConfig
23
19
 
24
20
  memoize
25
21
  def config_endpoint
26
- case environment
22
+ case Exercism.environment
27
23
  when :development, :test
28
- "http://localhost:3039"
24
+ host = ENV["EXERCISM_DOCKER"] ? "dynamodb:8000" : "localhost:3039"
25
+ "http://#{host}"
29
26
  else
30
27
  nil
31
28
  end
@@ -1,3 +1,3 @@
1
1
  module ExercismConfig
2
- VERSION = "0.11.0"
2
+ VERSION = "0.16.0"
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.11.0
4
+ version: 0.16.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Walker