Module: CFManifests
- Included in:
- ManifestsPlugin
- Defined in:
- lib/manifests/errors.rb,
lib/manifests/loader.rb,
lib/manifests/manifests.rb,
lib/manifests/loader/builder.rb,
lib/manifests/loader/resolver.rb,
lib/manifests/loader/normalizer.rb
Defined Under Namespace
Modules: Builder, Normalizer, Resolver Classes: CircularDependency, InvalidManifest, Loader, UnknownSymbol
Constant Summary collapse
- MANIFEST_FILE =
"manifest.yml"
- @@showed_manifest_usage =
false
- @@manifest =
nil
Instance Method Summary collapse
-
#all_apps ⇒ Object
return all the apps described by the manifest.
-
#apps_in_manifest(input = nil, use_name = true, &blk) ⇒ Object
splits the user’s input, resolving paths with the manifest, into internal/external apps.
- #check_attributes!(app, output = $stdout) ⇒ Object
- #check_manifest!(manifest_hash, output = $stdout) ⇒ Object
- #create_manifest_for(app, path) ⇒ Object
- #current_apps ⇒ Object
- #error_message_for_attribute(attribute) ⇒ Object
-
#find_apps(identifier) ⇒ Object
find apps by an identifier, which may be either a tag, a name, or a path.
- #known_manifest_attributes ⇒ Object
-
#load_manifest(file) ⇒ Object
load and resolve a given manifest file.
- #manifest ⇒ Object
-
#manifest_file ⇒ Object
find the manifest file to work with.
-
#resolve_symbol(sym) ⇒ Object
dynamic symbol resolution.
- #save_manifest(save_to = manifest_file) ⇒ Object
Instance Method Details
#all_apps ⇒ Object
return all the apps described by the manifest
110 111 112 |
# File 'lib/manifests/manifests.rb', line 110 def all_apps manifest[:applications] end |
#apps_in_manifest(input = nil, use_name = true, &blk) ⇒ Object
splits the user’s input, resolving paths with the manifest, into internal/external apps
internal apps are returned as their data in the manifest
external apps are the strings that the user gave, to be passed along wholesale to the wrapped command
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/manifests/manifests.rb', line 128 def apps_in_manifest(input = nil, use_name = true, &blk) names_or_paths = if input.has?(:apps) # names may be given but be [], which will still cause # interaction, so use #direct instead of #[] here input.direct(:apps) elsif input.has?(:app) [input.direct(:app)] elsif input.has?(:name) [input.direct(:name)] else [] end internal = [] external = [] names_or_paths.each do |x| if x.is_a?(String) if x =~ %r([/\\]) apps = find_apps(File.(x)) if apps.empty? fail("Path #{b(x)} is not present in manifest #{b(relative_manifest_file)}.") end else apps = find_apps(x) end if !apps.empty? internal += apps else external << x end else external << x end end [internal, external] end |
#check_attributes!(app, output = $stdout) ⇒ Object
62 63 64 65 66 |
# File 'lib/manifests/manifests.rb', line 62 def check_attributes!(app, output = $stdout) app.each do |k, v| output.puts (k) unless known_manifest_attributes.include? k end end |
#check_manifest!(manifest_hash, output = $stdout) ⇒ Object
57 58 59 60 |
# File 'lib/manifests/manifests.rb', line 57 def check_manifest!(manifest_hash, output = $stdout) manifest_hash[:applications].each{ |app| check_attributes!(app, output) } manifest_hash end |
#create_manifest_for(app, path) ⇒ Object
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 |
# File 'lib/manifests/manifests.rb', line 170 def create_manifest_for(app, path) = { "name" => app.name, "memory" => human_size(app.memory * 1024 * 1024, 0), "instances" => app.total_instances, "host" => app.host || "none", "domain" => app.domain ? app.domain : "none", "path" => path } services = app.services unless services.empty? ["services"] = {} services.each do |i| p = i.service_plan s = p.service ["services"][i.name] = { "label" => s.label, "provider" => s.provider, "version" => s.version, "plan" => p.name } end end if cmd = app.command ["command"] = cmd end if buildpack = app.buildpack ["buildpack"] = buildpack end end |
#current_apps ⇒ Object
114 115 116 117 118 119 |
# File 'lib/manifests/manifests.rb', line 114 def current_apps manifest[:applications].select do |app| next unless app[:path] from_manifest(app[:path]) == Dir.pwd end end |
#error_message_for_attribute(attribute) ⇒ Object
68 69 70 71 |
# File 'lib/manifests/manifests.rb', line 68 def (attribute) "\e[31mWarning: #{attribute} is not a valid manifest attribute. Please " + "remove this attribute from your manifest to get rid of this warning\e[0m" end |
#find_apps(identifier) ⇒ Object
find apps by an identifier, which may be either a tag, a name, or a path
97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/manifests/manifests.rb', line 97 def find_apps(identifier) return [] unless manifest apps = apps_by(:name, identifier) if apps.empty? apps = apps_by(:path, from_manifest(identifier)) end apps end |
#known_manifest_attributes ⇒ Object
73 74 75 76 77 |
# File 'lib/manifests/manifests.rb', line 73 def known_manifest_attributes [:applications, :buildpack, :command, :disk, :domain, :env, :host, :inherit, :instances, :mem, :memory, :name, :path, :properties, :runtime, :services, :stack] end |
#load_manifest(file) ⇒ Object
load and resolve a given manifest file
53 54 55 |
# File 'lib/manifests/manifests.rb', line 53 def load_manifest(file) check_manifest! Loader.new(file, self).manifest end |
#manifest ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/manifests/manifests.rb', line 12 def manifest return @@manifest if @@manifest if manifest_file && File.exists?(manifest_file) @@manifest = load_manifest(manifest_file) end end |
#manifest_file ⇒ Object
find the manifest file to work with
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/manifests/manifests.rb', line 29 def manifest_file return @manifest_file if @manifest_file unless path = input[:manifest] where = Dir.pwd while true if File.exists?(File.join(where, MANIFEST_FILE)) path = File.join(where, MANIFEST_FILE) break elsif File.basename(where) == "/" path = nil break else where = File.("../", where) end end end return unless path @manifest_file = File.(path) end |
#resolve_symbol(sym) ⇒ Object
dynamic symbol resolution
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/manifests/manifests.rb', line 80 def resolve_symbol(sym) case sym when "target-url" client_target when "target-base" target_base when "random-word" sprintf("%04x", rand(0x0100000)) when /^ask (.+)/ ask($1) end end |
#save_manifest(save_to = manifest_file) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/manifests/manifests.rb', line 20 def save_manifest(save_to = manifest_file) fail "No manifest to save!" unless @@manifest File.open(save_to, "w") do |io| YAML.dump(@@manifest, io) end end |