Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
dwilkie committed Sep 5, 2024
1 parent edacf4b commit 4b99c9f
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 70 deletions.
2 changes: 1 addition & 1 deletion components/services/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def process
def handle_ecs_event(event)
case event.group
when ENV.fetch("SWITCH_GROUP")
HandleSwitchEvent.call(event:, regions: SomlengRegions.regions)
HandleSwitchEvent.call(event:, regions: SomlengRegion::Region)
when ENV.fetch("MEDIA_PROXY_GROUP")
HandleMediaProxyEvent.call(event:)
when ENV.fetch("CLIENT_GATEWAY_GROUP")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "json"

SomlengRegions.configure do |config|
SomlengRegion.configure do |config|
config.region_data = AppSettings.fetch(:region_data)
config.stub_regions = AppSettings.fetch(:stub_regions)
end
17 changes: 17 additions & 0 deletions components/services/lib/somleng_region.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

module SomlengRegion
class << self
def configure
yield(configuration)
configuration
end

def configuration
@configuration ||= Configuration.new
end
alias config configuration
end
end

require_relative "somleng_region/configuration"
require_relative "somleng_region/region"
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module SomlengRegions
module SomlengRegion
class Configuration
attr_accessor :region_data, :stub_regions
end
Expand Down
48 changes: 48 additions & 0 deletions components/services/lib/somleng_region/region.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
require "ostruct"

module SomlengRegion
class Region < OpenStruct
class RegionNotFound < StandardError; end

MOCK_REGIONS = [
new(
identifier: "ap-southeast-1",
alias: "hydrogen",
group_id: 1,
human_name: "South East Asia (Singapore)"
),
new(
identifier: "us-east-1",
alias: "helium",
group_id: 2,
human_name: "North America (Virginia, US)"
)
]

class << self
def all
collection

Check warning on line 24 in components/services/lib/somleng_region/region.rb

View check run for this annotation

Codecov / codecov/patch

components/services/lib/somleng_region/region.rb#L24

Added line #L24 was not covered by tests
end

def find_by(attributes)
collection.find do |region|
attributes.all? { |key, value| region[key] == value }
end
end

def find_by!(*)
find_by(*) || raise(RegionNotFound.new)
end

private

def collection
@collection ||= config.stub_regions ? MOCK_REGIONS : config.region_data.map { |region| new(region) }
end

def config
SomlengRegion.configuration
end
end
end
end
37 changes: 0 additions & 37 deletions components/services/lib/somleng_regions.rb

This file was deleted.

25 changes: 0 additions & 25 deletions components/services/lib/somleng_regions/collection.rb

This file was deleted.

5 changes: 0 additions & 5 deletions components/services/lib/somleng_regions/region.rb

This file was deleted.

0 comments on commit 4b99c9f

Please sign in to comment.