Class: Hippo::Recipe
Defined Under Namespace
Classes: RecipeNotFound
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Class Method Summary collapse
-
.load_from_file(path) ⇒ Hippo::Recipe
Load a new Recipe class from a given file.
Instance Method Summary collapse
-
#build_specs ⇒ Hash<Hippo::BuildSpec>
Return the builds for this recipe.
-
#console ⇒ Object
Return configuration.
-
#initialize(hash, hippofile_path = nil) ⇒ Recipe
constructor
A new instance of Recipe.
-
#kubernetes ⇒ Hippo::Kubernetes
Return kubernetes configuration.
-
#name ⇒ String?
Return the app name.
-
#parse(stage, commit, string) ⇒ String
Parse a string through the template parser.
-
#repository ⇒ Hippo::Repository
Return the repository that this manifest should be working with.
-
#root ⇒ Object
Return the root directory where the Hippofile is located.
-
#stages ⇒ Hash<Hippo::Stage>
Return the stages for this recipe.
-
#template_vars ⇒ Hash
Return the template variables that should be exposed.
Methods included from Util
#load_yaml_from_data, #load_yaml_from_directory, #load_yaml_from_path, #open_in_editor
Constructor Details
#initialize(hash, hippofile_path = nil) ⇒ Recipe
Returns a new instance of Recipe.
34 35 36 37 |
# File 'lib/hippo/recipe.rb', line 34 def initialize(hash, hippofile_path = nil) @hash = hash @hippofile_path = hippofile_path end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
39 40 41 |
# File 'lib/hippo/recipe.rb', line 39 def path @path end |
Class Method Details
.load_from_file(path) ⇒ Hippo::Recipe
Load a new Recipe class from a given file.
23 24 25 26 27 28 29 30 |
# File 'lib/hippo/recipe.rb', line 23 def load_from_file(path) unless File.file?(path) raise RecipeNotFound, "No recipe file found at #{path}" end hash = YAML.load_file(path) new(hash, path) end |
Instance Method Details
#build_specs ⇒ Hash<Hippo::BuildSpec>
Return the builds for this recipe
86 87 88 89 90 |
# File 'lib/hippo/recipe.rb', line 86 def build_specs @build_specs ||= @hash['builds'].each_with_object({}) do |(key, ), hash| hash[key] = BuildSpec.new(self, key, ) end end |
#console ⇒ Object
Return configuration
95 96 97 |
# File 'lib/hippo/recipe.rb', line 95 def console @hash['console'] end |
#kubernetes ⇒ Hippo::Kubernetes
Return kubernetes configuration
66 67 68 |
# File 'lib/hippo/recipe.rb', line 66 def kubernetes @kubernetes ||= Kubernetes.new(self, @hash['kubernetes'] || {}) end |
#name ⇒ String?
Return the app name
59 60 61 |
# File 'lib/hippo/recipe.rb', line 59 def name @hash['name'] end |
#parse(stage, commit, string) ⇒ String
Parse a string through the template parser
113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/hippo/recipe.rb', line 113 def parse(stage, commit, string) template = Liquid::Template.parse(string) template_variables = template_vars template_variables['stage'] = stage.template_vars if commit template_variables['commit'] = { 'ref' => commit.objectish, 'message' => commit. } end template.render(template_variables) end |
#repository ⇒ Hippo::Repository
Return the repository that this manifest should be working with
50 51 52 53 54 |
# File 'lib/hippo/recipe.rb', line 50 def repository return unless @hash['repository'] @repository ||= Repository.new(@hash['repository']) end |
#root ⇒ Object
Return the root directory where the Hippofile is located
43 44 45 |
# File 'lib/hippo/recipe.rb', line 43 def root File.dirname(@hippofile_path) end |
#stages ⇒ Hash<Hippo::Stage>
Return the stages for this recipe
73 74 75 76 77 78 79 80 81 |
# File 'lib/hippo/recipe.rb', line 73 def stages @stages ||= begin yamls = load_yaml_from_directory(File.join(root, 'stages')) yamls.each_with_object({}) do |yaml, hash| stage = Stage.new(yaml) hash[stage.name] = stage end end end |
#template_vars ⇒ Hash
Return the template variables that should be exposed
102 103 104 105 106 107 |
# File 'lib/hippo/recipe.rb', line 102 def template_vars { 'repository' => repository ? repository.template_vars : nil, 'builds' => build_specs.each_with_object({}) { |(_, bs), h| h[bs.name] = bs.template_vars } } end |