Class: QB::Docker::Image::Name
- Inherits:
-
QB::Data::Immutable
- Object
- Hamster::Hash
- QB::Data::Immutable
- QB::Docker::Image::Name
- Extended by:
- MethodDecorators
- Includes:
- NRSER::Log::Mixin
- Defined in:
- lib/qb/docker/image/name.rb
Instance Attribute Summary collapse
-
#name ⇒ String
readonly
For lack of a better name, the part of the name that's not anything else.
-
#port ⇒ Integer?
readonly
Registry server port, if any.
-
#registry_server ⇒ String?
readonly
Registry server, if any.
-
#repository ⇒ String?
readonly
The repository name, if any.
-
#source ⇒ String?
readonly
Source string this name was loaded from, if any.
Class Method Summary collapse
- .exists?(name) ⇒ Boolean
-
.from(source) ⇒ self
Get an instance from a source.
-
.from_s(string) ⇒ self
Load from a String.
- .list(*args, **opts) ⇒ Object
Instance Method Summary collapse
- #dirty? ⇒ return_type
-
#exists? ⇒ Boolean
(also: #exist?)
Does the name exist in the local daemon?.
- #formatted ⇒ Object
- #host ⇒ Object
- #inspect ⇒ Object
- #pretty_print(q) ⇒ Object
- #to_s ⇒ Object
Instance Attribute Details
#name ⇒ String (readonly)
For lack of a better name, the part of the name that's not anything else. It's also the only required part.
201 202 |
# File 'lib/qb/docker/image/name.rb', line 201 prop :name, type: t.non_empty_str |
#port ⇒ Integer? (readonly)
Registry server port, if any.
228 229 |
# File 'lib/qb/docker/image/name.rb', line 228 prop :port, type: t.port? |
#registry_server ⇒ String? (readonly)
Registry server, if any.
219 220 |
# File 'lib/qb/docker/image/name.rb', line 219 prop :registry_server, type: t.non_empty_str? |
#repository ⇒ String? (readonly)
The repository name, if any.
210 211 |
# File 'lib/qb/docker/image/name.rb', line 210 prop :repository, type: t.non_empty_str? |
#source ⇒ String? (readonly)
Source string this name was loaded from, if any.
190 191 |
# File 'lib/qb/docker/image/name.rb', line 190 prop :source, type: t.non_empty_str? |
Class Method Details
.exists?(name) ⇒ Boolean
167 168 169 |
# File 'lib/qb/docker/image/name.rb', line 167 def self.exists? name QB::Docker::CLI.image_named? name end |
.from(source) ⇒ self
Get an instance from a source.
154 155 156 157 158 159 |
# File 'lib/qb/docker/image/name.rb', line 154 def self.from source t.match source, self, source, t.str, method( :from_s ), t.hash_, method( :from_data ) end |
.from_s(string) ⇒ self
Load from a String.
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/qb/docker/image/name.rb', line 58 def self.from_s string strings = {} segments = string.split '/' if segments[-1].include? ':' rest, _, tag = segments[-1].rpartition ':' strings[:tag] = tag segments[-1] = rest else rest = string end case segments.length when 0 # Pass - construction will error when 1 # Just a name strings[:name] = segments[0] else if segments[0].include? ':' # segments = [s_0, s_1, ... s_n] # => repository = s_0 # segments = [s_1, s_2, ... s_n] # # like # # segments = ['docker.beiarea.com:8888', 'beiarea', 'wall'] # => registry_server = 'docker.beiarea.com' # port = '8888' # segments = ['beiarea', 'wall'] # registry_server, _, port = segments.shift.rpartition ':' strings[:registry_server] = registry_server strings[:port] = port end if segments.length > 1 # segments = [s_0, s_1, ... s_m] # => repository = s_0 # segments = [s_1, s_2, ... s_m] # # like # # segments = ['beiarea', 'wall'] # => repository = 'beiarea' # segments = ['wall'] # repository = segments.shift strings[:repository] = repository end # I think Docker image names *can* have more than just a repo and name # segment, though it's poorly supported from what I recall... though # we will handle it by just re-joining whatever's left into the name. # # segments = [s_0, s_1, ... s_p] # => name = "s_0/s_1/.../s_p" # # like # # segments = ['wall'] # => name = 'wall' # # or # # segments = ['www_rails', 'web'] # => name = 'www_rails/web' # strings[:name] = segments.join '/' end logger.debug "strings", strings # Now turn them into value using their prop types values = strings.transform_values_with_keys { |name, string| prop = [name] if prop.type.respond_to? :from_s prop.type.from_s string else string end } logger.debug "values", values # And construct! new source: string, **values end |
.list(*args, **opts) ⇒ Object
175 176 177 |
# File 'lib/qb/docker/image/name.rb', line 175 def self.list *args, **opts QB::Docker::CLI.image_names *args, **opts end |
Instance Method Details
#dirty? ⇒ return_type
TODO:
Document dirty? method.
Returns @todo Document return value.
269 270 271 |
# File 'lib/qb/docker/image/name.rb', line 269 def dirty? !!tag.try( :dirty? ) end |
#exists? ⇒ Boolean Also known as: exist?
Does the name exist in the local daemon?
254 255 256 |
# File 'lib/qb/docker/image/name.rb', line 254 def exists? QB::Docker::CLI.image_named? self end |
#formatted ⇒ Object
279 280 281 282 283 284 285 286 287 288 289 290 291 |
# File 'lib/qb/docker/image/name.rb', line 279 def formatted [ host, repository, name, ].compact.join( '/' ).thru { |without_tag| if tag "#{ without_tag }:#{ tag }" else without_tag end } end |
#host ⇒ Object
274 275 276 |
# File 'lib/qb/docker/image/name.rb', line 274 def host "#{ registry_server }:#{ port }" if registry_server && port end |
#inspect ⇒ Object
299 300 301 |
# File 'lib/qb/docker/image/name.rb', line 299 def inspect "#<#{ self.class.safe_name } #{ to_s }>" end |
#pretty_print(q) ⇒ Object
304 305 306 |
# File 'lib/qb/docker/image/name.rb', line 304 def pretty_print q q.text inspect end |
#to_s ⇒ Object
294 295 296 |
# File 'lib/qb/docker/image/name.rb', line 294 def to_s formatted end |