app_manifest 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/README.md +47 -0
- data/Rakefile +10 -0
- data/app_manifest.gemspec +28 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/app_manifest.rb +166 -0
- data/lib/app_manifest/manifest.rb +26 -0
- data/lib/app_manifest/version.rb +3 -0
- metadata +113 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 88250826ba2e106bd940d7f102bb681c696808c6
|
4
|
+
data.tar.gz: 69002497677af7078a8ce80bdc212a7dabeb7e51
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 345cf82e77ed451b94f270b47aaec1d86cbe92bb23e3f8f257106b48d0822d8166133bbf6332624a77d7990c7ae12df6facae8e78bcca50cec0132b0df72965d
|
7
|
+
data.tar.gz: 99d7a9f26420962bbac8e5a833a31885f987d417eb0f3c2fcf4d457ebf915afd24cfdea0439f09a1a23a9c80ff8b1c60b7a6e2058a8482895e3d1abcded69919
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
# AppManifest
|
2
|
+
|
3
|
+
A Ruby Gem for parsing AppManifests according to the [app.json
|
4
|
+
schema](https://devcenter.heroku.com/articles/app-json-schema)
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'app_manifest'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install app_manifest
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
Initialize an app manifest:
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
AppManifest(name: 'my-app')
|
28
|
+
```
|
29
|
+
|
30
|
+
Extract an environment configuration:
|
31
|
+
```ruby
|
32
|
+
manifest = AppManifest(name: 'my-app', environments: { test: { addons: ['beta'] } })
|
33
|
+
|
34
|
+
manifest.environment(:test).to_hash
|
35
|
+
# => { name: 'my-app', addons: [{ plan: 'beta' }] }
|
36
|
+
```
|
37
|
+
|
38
|
+
## Development
|
39
|
+
|
40
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
41
|
+
|
42
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
43
|
+
|
44
|
+
## Contributing
|
45
|
+
|
46
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/heroku/app-manifest.
|
47
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'app_manifest/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'app_manifest'
|
8
|
+
spec.version = AppManifest::VERSION
|
9
|
+
spec.authors = ['Owen Jacobson', 'Josh W Lewis']
|
10
|
+
spec.email = ['ojacobson@heroku.com', 'jlewis@heroku.com']
|
11
|
+
|
12
|
+
spec.summary = 'A library for parsing Heroku app manifests'
|
13
|
+
spec.description = 'Parse app manifests used by Heroku Button, Heroku ' \
|
14
|
+
'Review Apps, and Heroku CI.'
|
15
|
+
spec.homepage = 'https://devcenter.heroku.com/articles/app-json-schema'
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
end
|
20
|
+
spec.bindir = "exe"
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.14"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
27
|
+
spec.add_dependency "multi_json", "~> 1.0"
|
28
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "app_manifest"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/lib/app_manifest.rb
ADDED
@@ -0,0 +1,166 @@
|
|
1
|
+
require 'multi_json'
|
2
|
+
|
3
|
+
require "app_manifest/version"
|
4
|
+
require "app_manifest/manifest"
|
5
|
+
|
6
|
+
# Create a new manifest from json string or a hash
|
7
|
+
def AppManifest(input)
|
8
|
+
if input.is_a?(Hash)
|
9
|
+
AppManifest::Manifest.new(input)
|
10
|
+
elsif input.is_a?(String)
|
11
|
+
AppManifest::Manifest.from_json(input)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
module AppManifest
|
16
|
+
class << self
|
17
|
+
# Takes a hash representing an app manifest and returns a new hash
|
18
|
+
# with canonical serialization. This will resolve shorthands and older
|
19
|
+
# serializations into a canonical serialization.
|
20
|
+
def canonicalize(manifest)
|
21
|
+
keys_to_sym(manifest)
|
22
|
+
.merge(canonicalize_env(manifest))
|
23
|
+
.merge(canonicalize_formation(manifest))
|
24
|
+
.merge(canonicalize_addons(manifest))
|
25
|
+
.merge(canonicalize_environments(manifest))
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
# Takes an env serialization returns a new serialization hash in the
|
31
|
+
# canonical format.
|
32
|
+
# For instance:
|
33
|
+
# canonicalize_env({"FOO" => "BAR"}) # => { "FOO" => { value: "BAR" } }
|
34
|
+
def canonicalize_env(manifest)
|
35
|
+
canonicalize_key(manifest, :env) do |env|
|
36
|
+
Hash[
|
37
|
+
env.map do |key, value|
|
38
|
+
if value.is_a? String
|
39
|
+
value = {
|
40
|
+
value: value,
|
41
|
+
}
|
42
|
+
end
|
43
|
+
[key.to_s, value]
|
44
|
+
end
|
45
|
+
]
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
# Takes a formation serialization and returns a new serializaiton in the
|
50
|
+
# standard format.
|
51
|
+
# For example:
|
52
|
+
# canonicalize_formation([{ "process" => "web", "count" => 1 }]
|
53
|
+
# # => { web: { count: 1 } }
|
54
|
+
def canonicalize_formation(manifest)
|
55
|
+
canonicalize_key(manifest, :formation) do |formation|
|
56
|
+
if formation.is_a? Array
|
57
|
+
Hash[
|
58
|
+
formation.map do |entry|
|
59
|
+
process = entry[:process]
|
60
|
+
entry = entry.reject { |k, _| k == :process }
|
61
|
+
[process.to_sym, entry]
|
62
|
+
end
|
63
|
+
]
|
64
|
+
else
|
65
|
+
formation
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
# Takes an addon serialization and returns a new serialization in the
|
71
|
+
# canonical format.
|
72
|
+
# For example:
|
73
|
+
# canonicalize_addons(["heroku-postgres:hobby-dev"])
|
74
|
+
# # => { plan: "heroku-postgres:hobby-dev" }
|
75
|
+
def canonicalize_addons(manifest)
|
76
|
+
canonicalize_key(manifest, :addons) do |addons|
|
77
|
+
addons.map do |entry|
|
78
|
+
if entry.is_a? String
|
79
|
+
{
|
80
|
+
plan: entry,
|
81
|
+
}
|
82
|
+
else
|
83
|
+
entry
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
|
90
|
+
# Takes an environments serialization and canonicalizes each entry.
|
91
|
+
def canonicalize_environments(manifest)
|
92
|
+
canonicalize_key(manifest, :environments) do |environments|
|
93
|
+
Hash[
|
94
|
+
environments.map do |key, environment|
|
95
|
+
[key, canonicalize(environment)]
|
96
|
+
end
|
97
|
+
]
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
# Takes a hash, a key in that hash, and a block. If the key is present, runs
|
102
|
+
# the corresponding value through the block and returns a new hash with the
|
103
|
+
# canonicalized value. (This can be merged into the original hash using
|
104
|
+
# .update.) Otherwise, returns an empty hash.
|
105
|
+
def canonicalize_key(manifest, key)
|
106
|
+
if manifest.has_key? key
|
107
|
+
val = manifest[key]
|
108
|
+
{
|
109
|
+
key => yield(val),
|
110
|
+
}
|
111
|
+
else
|
112
|
+
{}
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
# Takes a (possibly nested) hash whose keys respond to to_sym
|
117
|
+
# Returns a hash where all levels of hashes have only symbol keys
|
118
|
+
#
|
119
|
+
# {"a" => 1, "b" => { "c" => 2 }}
|
120
|
+
# => {:a => 1, :b => { :c => 2 }}
|
121
|
+
#
|
122
|
+
# This special-cases the immediate children of any key named 'env' or :env,
|
123
|
+
# so that env var names remain (or become) strings.
|
124
|
+
#
|
125
|
+
# {'env' => { 'a' => { 'b' => 2 }}}
|
126
|
+
# => {:env => { 'a' => { :b => 2 }}}
|
127
|
+
def keys_to_sym(hash)
|
128
|
+
Hash[
|
129
|
+
hash.map do |key, val|
|
130
|
+
[
|
131
|
+
key.to_sym,
|
132
|
+
if ['env', :env].include? key
|
133
|
+
env_to_sym(val)
|
134
|
+
else
|
135
|
+
val_to_sym(val)
|
136
|
+
end
|
137
|
+
]
|
138
|
+
end
|
139
|
+
]
|
140
|
+
end
|
141
|
+
|
142
|
+
def keys_to_string(hash)
|
143
|
+
Hash[
|
144
|
+
hash.map do |key, val|
|
145
|
+
[key.to_s, val_to_sym(val)]
|
146
|
+
end
|
147
|
+
]
|
148
|
+
end
|
149
|
+
|
150
|
+
def val_to_sym(value)
|
151
|
+
if value.is_a? Hash
|
152
|
+
keys_to_sym(value)
|
153
|
+
else
|
154
|
+
value
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
def env_to_sym(value)
|
159
|
+
if value.is_a? Hash
|
160
|
+
keys_to_string(value)
|
161
|
+
else
|
162
|
+
value
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module AppManifest
|
2
|
+
# A simple model-like wrapper around a manifest hash.
|
3
|
+
class Manifest
|
4
|
+
def self.from_json(string)
|
5
|
+
hash = MultiJson.load(string)
|
6
|
+
self.new(hash)
|
7
|
+
end
|
8
|
+
|
9
|
+
def initialize(hash)
|
10
|
+
@manifest = AppManifest.canonicalize(hash)
|
11
|
+
end
|
12
|
+
|
13
|
+
def environment(name)
|
14
|
+
env_manifest = manifest.fetch(:environments, {}).fetch(name, {})
|
15
|
+
self.class.new(manifest.merge(env_manifest))
|
16
|
+
end
|
17
|
+
|
18
|
+
def to_hash
|
19
|
+
manifest
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
attr_reader :manifest
|
25
|
+
end
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: app_manifest
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Owen Jacobson
|
8
|
+
- Josh W Lewis
|
9
|
+
autorequire:
|
10
|
+
bindir: exe
|
11
|
+
cert_chain: []
|
12
|
+
date: 2017-02-24 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '1.14'
|
21
|
+
type: :development
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '1.14'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: rake
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '10.0'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '10.0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: minitest
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - "~>"
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '5.0'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - "~>"
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '5.0'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: multi_json
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - "~>"
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '1.0'
|
63
|
+
type: :runtime
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - "~>"
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '1.0'
|
70
|
+
description: Parse app manifests used by Heroku Button, Heroku Review Apps, and Heroku
|
71
|
+
CI.
|
72
|
+
email:
|
73
|
+
- ojacobson@heroku.com
|
74
|
+
- jlewis@heroku.com
|
75
|
+
executables: []
|
76
|
+
extensions: []
|
77
|
+
extra_rdoc_files: []
|
78
|
+
files:
|
79
|
+
- ".gitignore"
|
80
|
+
- ".travis.yml"
|
81
|
+
- Gemfile
|
82
|
+
- README.md
|
83
|
+
- Rakefile
|
84
|
+
- app_manifest.gemspec
|
85
|
+
- bin/console
|
86
|
+
- bin/setup
|
87
|
+
- lib/app_manifest.rb
|
88
|
+
- lib/app_manifest/manifest.rb
|
89
|
+
- lib/app_manifest/version.rb
|
90
|
+
homepage: https://devcenter.heroku.com/articles/app-json-schema
|
91
|
+
licenses: []
|
92
|
+
metadata: {}
|
93
|
+
post_install_message:
|
94
|
+
rdoc_options: []
|
95
|
+
require_paths:
|
96
|
+
- lib
|
97
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
requirements: []
|
108
|
+
rubyforge_project:
|
109
|
+
rubygems_version: 2.5.1
|
110
|
+
signing_key:
|
111
|
+
specification_version: 4
|
112
|
+
summary: A library for parsing Heroku app manifests
|
113
|
+
test_files: []
|