Class: Docker::Template::Metadata
Constant Summary
collapse
- ALIASES =
Provides aliases for the root element so you can do something like:
* data["release"].fallback
{
"entry" => "entries",
"release" => "releases",
"version" => "versions",
"script" => "scripts",
"image" => "images"
}
Instance Method Summary
collapse
Methods included from Routable
route_to_hash, route_to_ivar
Constructor Details
#initialize(metadata, root_metadata = metadata) ⇒ Metadata
Returns a new instance of Metadata.
33
34
35
36
37
38
39
40
41
|
# File 'lib/docker/template/metadata.rb', line 33
def initialize(metadata, root_metadata = metadata)
@is_root = metadata == root_metadata
@root_metadata = root_metadata || {}
@metadata = metadata || {}
return unless is_root?
@root_metadata = @metadata
@base = Template.config
end
|
Instance Method Details
Queries providing a default value if on the root repo hash otherwise returning the returned value, as a self.class if it’s a Hash.
61
62
63
64
65
66
67
68
|
# File 'lib/docker/template/metadata.rb', line 61
def [](key)
key = determine_key(key)
val = @metadata[key]
return try_default(key) if !val && is_root?
return self.class.new(val, @root_metadata) if val.is_a?(Hash)
val
end
|
51
52
53
54
55
56
|
# File 'lib/docker/template/metadata.rb', line 51
def aliased
tag = from_root("tag")
aliases = from_root("aliases")
return aliases[tag] if aliases.key?(tag)
tag
end
|
#as_gem_version ⇒ Object
45
46
47
|
# File 'lib/docker/template/metadata.rb', line 45
def as_gem_version
"#{self["repo"]}@#{self["version"].fallback}"
end
|
91
92
93
94
95
96
|
# File 'lib/docker/template/metadata.rb', line 91
def as_hash
{} \
.merge(for_all.to_h) \
.merge(by_type.to_h) \
.merge(by_tag. to_h)
end
|
100
101
102
103
104
105
|
# File 'lib/docker/template/metadata.rb', line 100
def as_set
Set.new \
.merge(for_all.to_a) \
.merge(by_type.to_a) \
.merge(by_tag .to_a)
end
|
#as_string_set ⇒ Object
85
86
87
|
# File 'lib/docker/template/metadata.rb', line 85
def as_string_set
as_set.to_a.join(" ")
end
|
Pulls data based on the given tag through anything that provides a “tag” key with the given tags. (“tags” is a Hash)
123
124
125
126
127
128
|
# File 'lib/docker/template/metadata.rb', line 123
def by_tag
return unless tag = aliased
return unless key?("tag")
hash = self["tag"]
hash[tag]
end
|
Pull data based on the type given in { “tags” => { tag => type }} through anything that provides a “type” key with the type as a sub-key and the values.
134
135
136
137
138
139
140
141
142
|
# File 'lib/docker/template/metadata.rb', line 134
def by_type
return unless tag = aliased
type = from_root("tags")[tag]
return unless key?("type")
return unless type
hash = self["type"]
hash[type]
end
|
116
117
118
|
# File 'lib/docker/template/metadata.rb', line 116
def fallback
by_tag || by_type || for_all
end
|
#from_root(key) ⇒ Object
109
110
111
112
|
# File 'lib/docker/template/metadata.rb', line 109
def from_root(key)
root = self.class.new(@root_metadata)
root[key]
end
|
#merge(new_) ⇒ Object
78
79
80
81
|
# File 'lib/docker/template/metadata.rb', line 78
def merge(new_)
@metadata.merge!(new_)
self
end
|
72
73
74
|
# File 'lib/docker/template/metadata.rb', line 72
def tags
self["tags"].keys + self["aliases"].keys
end
|