diff options
author | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2017-03-29 13:53:02 +0300 |
---|---|---|
committer | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2017-03-29 13:53:02 +0300 |
commit | 06bae00365cda6930063b98fde1a9b804f2ae3bc (patch) | |
tree | e65f656cd87e26c56c4274345f71e5376461aaad /lib/container_registry | |
parent | 5a7f8cb5d2f9ab7bc7172cedeb220b7d78530f78 (diff) |
Make container repository path code more readable
Diffstat (limited to 'lib/container_registry')
-rw-r--r-- | lib/container_registry/path.rb | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/lib/container_registry/path.rb b/lib/container_registry/path.rb index 0ca51ab3766..d3f8bf74e14 100644 --- a/lib/container_registry/path.rb +++ b/lib/container_registry/path.rb @@ -1,10 +1,24 @@ module ContainerRegistry + ## + # Class reponsible for extracting project and repository name from + # image repository path provided by a containers registry API response. + # + # Example: + # + # some/group/my_project/my/image -> + # project: some/group/my_project + # repository: my/image + # class Path InvalidRegistryPathError = Class.new(StandardError) - def initialize(name) - @name = name - @nodes = name.to_s.split('/') + def initialize(path) + @path = path + @nodes = path.to_s.split('/') + end + + def to_s + @path end def valid? @@ -20,7 +34,7 @@ module ContainerRegistry end def has_repository? - # ContainerRepository.find_by_full_path(@name).present? + # ContainerRepository.find_by_full_path(@path).present? end def repository_project @@ -30,7 +44,7 @@ module ContainerRegistry def repository_name return unless repository_project - @name.remove(%r(^?#{Regexp.escape(repository_project.full_path)}/?)) + @path.remove(%r(^?#{Regexp.escape(repository_project.full_path)}/?)) end end end |