-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
divertdown-web will store data other than source, so change the format
- Loading branch information
Showing
14 changed files
with
446 additions
and
347 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# frozen_string_literal: true | ||
|
||
module DiverDown | ||
class Web | ||
class AliasStore | ||
def initialize | ||
# Hash{ alias_name => Set<source_name, ...> } | ||
@alias_to_source_names = Hash.new { |h, k| h[k] = Set.new } | ||
@source_name_to_alias = {} | ||
end | ||
|
||
# @param alias_name [String] | ||
# @param source_names [Array<String>] | ||
# @return [void] | ||
def add_alias(alias_name, source_names) | ||
@alias_to_source_names[alias_name].merge(source_names) | ||
|
||
source_names.each do |source_name| | ||
@source_name_to_alias[source_name] = alias_name | ||
end | ||
end | ||
|
||
# @param alias_name [String] | ||
# @return [String] | ||
def resolve_alias(source_name) | ||
if @source_name_to_alias.key?(source_name) | ||
@source_name_to_alias[source_name] | ||
else | ||
source_name | ||
end | ||
end | ||
|
||
# @param alias_name [String] | ||
# @return [Array<String>] | ||
def aliased_source_names(alias_name) | ||
@alias_to_source_names[alias_name].to_a if @alias_to_source_names.key?(alias_name) | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.