app_manifest 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: '07832c80f5af96888eaf027f758789adbf3f79a5'
4
- data.tar.gz: 908be879c0110a7c0739cff235536687fa6e834c
3
+ metadata.gz: 98e7fd7a9df5650e85261c7075ba606fee8577a3
4
+ data.tar.gz: d05a3fc7de5170ee6382f374bf11bbe00cc7d23d
5
5
  SHA512:
6
- metadata.gz: 3c1b7bdccc06899ce46bef23b268b1807b02e11a69768c4395683a6dba0b3ce25889b9fc30c87284236000270468f48fcbd7afeaaf47f3d9ad2614ac421af230
7
- data.tar.gz: 26d2b46194b915ed316f373643059a7dfa4c55843816c04a2cadfa87d5b025739c18d8b17ba531cd750e8b73c0def9d298e541dcc1ee60dd84ff853db6ebde15
6
+ metadata.gz: 52af724010c244dfa20b5f17ce50f109089acc3e0189ce268ce3391ba781a39a0ece6639aa224ebb6936a801e07ab02fa6538c3097426996f01a1e20fc1a542e
7
+ data.tar.gz: 695439ffdb68a4a023ed50e8ce522a87275f37cc41bb834e647d4151995d49c021c1746aefee6a52a2a0ec0fb317d4380655800a7adb0d5c450a40d4911c5065
@@ -7,6 +7,22 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
7
7
 
8
8
  ## Unreleased
9
9
 
10
+ ## [0.3.0] - 2017-06-18
11
+
12
+ ### Added
13
+ - Manifests are now fully modeled. There are now getters and setters for
14
+ nested data (for example: `manifest.addons.first.plan`).
15
+
16
+ ### Changed
17
+ - `Manifest#to_hash` now returns a hash for the current manifest state, rather
18
+ than the hash that was passed in.
19
+ - `Manifest#environment` now returns an `Environment` instance, as a result,
20
+ it's serialization will not include nested `environments` data.
21
+
22
+ ### Removed
23
+ - `Manifest#manifest` was removed as it was superfluous and potentially
24
+ confusing. `Manifest#to_hash` may be a suitable replacement.
25
+
10
26
  ## [0.2.1] - 2017-04-04
11
27
  ### Fixed
12
28
  - Prevent `NoMethodError on TrueClass` when a `true` or `false` environment variable is provided.
@@ -25,4 +25,5 @@ Gem::Specification.new do |spec|
25
25
  spec.add_development_dependency "rake", "~> 10.0"
26
26
  spec.add_development_dependency "minitest", "~> 5.0"
27
27
  spec.add_dependency "multi_json", "~> 1.0"
28
+ spec.add_dependency "virtus", "~> 1.0"
28
29
  end
@@ -1,6 +1,15 @@
1
1
  require 'multi_json'
2
+ require 'virtus'
2
3
 
3
4
  require "app_manifest/version"
5
+ require "app_manifest/nullable_array"
6
+ require "app_manifest/serializer"
7
+ require "app_manifest/addon"
8
+ require "app_manifest/buildpack"
9
+ require "app_manifest/env"
10
+ require "app_manifest/formation"
11
+ require "app_manifest/environment_attributes"
12
+ require "app_manifest/environment"
4
13
  require "app_manifest/manifest"
5
14
 
6
15
  # Create a new manifest from json string or a hash
@@ -0,0 +1,10 @@
1
+ module AppManifest
2
+ class Addon
3
+ include Virtus.model
4
+ include Serializer
5
+
6
+ attribute :plan, String
7
+ attribute :as, String
8
+ attribute :options, Hash[String => String], default: nil
9
+ end
10
+ end
@@ -0,0 +1,8 @@
1
+ module AppManifest
2
+ class Buildpack
3
+ include Virtus.model
4
+ include Serializer
5
+
6
+ attribute :url, String
7
+ end
8
+ end
@@ -0,0 +1,11 @@
1
+ module AppManifest
2
+ class Env
3
+ include Virtus.model
4
+ include Serializer
5
+
6
+ attribute :description, String
7
+ attribute :generator, String
8
+ attribute :required, Boolean
9
+ attribute :value, String
10
+ end
11
+ end
@@ -0,0 +1,7 @@
1
+ module AppManifest
2
+ class Environment
3
+ include Virtus.model
4
+ include EnvironmentAttributes
5
+ include Serializer
6
+ end
7
+ end
@@ -0,0 +1,21 @@
1
+ module AppManifest
2
+ # Setup attributes that are shared on Manifest and Environment models
3
+ module EnvironmentAttributes
4
+ def self.included(base)
5
+ base.attribute :addons, NullableArray[Addon]
6
+ base.attribute :buildpacks, NullableArray[Buildpack]
7
+ base.attribute :description, String
8
+ base.attribute :env, Hash[String => Env], default: nil
9
+ base.attribute :formation, Hash[String => Formation], default: nil
10
+ base.attribute :image, String
11
+ base.attribute :keywords, NullableArray[String]
12
+ base.attribute :logo, String
13
+ base.attribute :name, String
14
+ base.attribute :repository, String
15
+ base.attribute :scripts, Hash[String => String], default: nil
16
+ base.attribute :stack, String
17
+ base.attribute :success_url, String
18
+ base.attribute :website, String
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,9 @@
1
+ module AppManifest
2
+ class Formation
3
+ include Virtus.model
4
+ include Serializer
5
+
6
+ attribute :quantity, Integer
7
+ attribute :size, String
8
+ end
9
+ end
@@ -1,26 +1,26 @@
1
1
  module AppManifest
2
2
  # A simple model-like wrapper around a manifest hash.
3
3
  class Manifest
4
+ include Virtus.model
5
+ include EnvironmentAttributes
6
+ include Serializer
7
+
8
+ attribute :environments, Hash[String => Environment], default: nil
9
+
4
10
  def self.from_json(string)
5
11
  hash = MultiJson.load(string)
6
- self.new(hash)
12
+ new(hash)
7
13
  end
8
14
 
9
15
  def initialize(hash)
10
- @manifest = AppManifest.canonicalize(hash)
16
+ canonicalized = AppManifest.canonicalize(hash)
17
+ super(canonicalized)
11
18
  end
12
19
 
13
20
  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
21
+ scoped_data = (environments || {}).fetch(name.to_s, {}).to_hash
22
+ global_data = to_hash
23
+ Environment.new(global_data.merge(scoped_data))
20
24
  end
21
-
22
- private
23
-
24
- attr_reader :manifest
25
25
  end
26
26
  end
@@ -0,0 +1,13 @@
1
+ module AppManifest
2
+ class NullableArray < Array; end
3
+
4
+ class NullableArrayAttribute < Virtus::Attribute::Collection
5
+ default nil
6
+ required false
7
+ primitive Array
8
+
9
+ def coerce(value)
10
+ value.nil? ? value : super(value)
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,29 @@
1
+ module AppManifest
2
+ # Serialization logic for AppManifest models
3
+ module Serializer
4
+ def self.serialize(value)
5
+ case value
6
+ when Array
7
+ value.map { |v| serialize(v) }
8
+ when Hash
9
+ value.each_with_object({}) do |(k, v), h|
10
+ h[k] = serialize(v)
11
+ end
12
+ when Integer, Float, String, Symbol, TrueClass, FalseClass, NilClass
13
+ value
14
+ else
15
+ if value.respond_to?(:attributes)
16
+ value.attributes.each_with_object({}) do |(key, val), hash|
17
+ hash[key] = serialize(val) unless val.nil?
18
+ end
19
+ else
20
+ val.to_s
21
+ end
22
+ end
23
+ end
24
+
25
+ def to_hash
26
+ Serializer.serialize(self)
27
+ end
28
+ end
29
+ end
@@ -1,3 +1,3 @@
1
1
  module AppManifest
2
- VERSION = '0.2.1'.freeze
2
+ VERSION = '0.3.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: app_manifest
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Owen Jacobson
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2017-04-04 00:00:00.000000000 Z
12
+ date: 2017-07-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -67,6 +67,20 @@ dependencies:
67
67
  - - "~>"
68
68
  - !ruby/object:Gem::Version
69
69
  version: '1.0'
70
+ - !ruby/object:Gem::Dependency
71
+ name: virtus
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - "~>"
75
+ - !ruby/object:Gem::Version
76
+ version: '1.0'
77
+ type: :runtime
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - "~>"
82
+ - !ruby/object:Gem::Version
83
+ version: '1.0'
70
84
  description: Parse app manifests used by Heroku Button, Heroku Review Apps, and Heroku
71
85
  CI.
72
86
  email:
@@ -86,7 +100,15 @@ files:
86
100
  - bin/console
87
101
  - bin/setup
88
102
  - lib/app_manifest.rb
103
+ - lib/app_manifest/addon.rb
104
+ - lib/app_manifest/buildpack.rb
105
+ - lib/app_manifest/env.rb
106
+ - lib/app_manifest/environment.rb
107
+ - lib/app_manifest/environment_attributes.rb
108
+ - lib/app_manifest/formation.rb
89
109
  - lib/app_manifest/manifest.rb
110
+ - lib/app_manifest/nullable_array.rb
111
+ - lib/app_manifest/serializer.rb
90
112
  - lib/app_manifest/version.rb
91
113
  homepage: https://devcenter.heroku.com/articles/app-json-schema
92
114
  licenses: []