Class: Hippo::Recipe

Inherits:
Object
  • Object
show all
Includes:
Util
Defined in:
lib/hippo/recipe.rb

Defined Under Namespace

Classes: RecipeNotFound

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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.

Parameters:

  • hash (Hash)

    the raw hash from the underlying yaml file



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

#pathObject (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.

Parameters:

  • path (String)

    path to recipe file.

Returns:



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_specsHash<Hippo::BuildSpec>

Return the builds for this recipe

Returns:



86
87
88
89
90
# File 'lib/hippo/recipe.rb', line 86

def build_specs
  @build_specs ||= @hash['builds'].each_with_object({}) do |(key, options), hash|
    hash[key] = BuildSpec.new(self, key, options)
  end
end

#consoleObject

Return configuration

Returns:



95
96
97
# File 'lib/hippo/recipe.rb', line 95

def console
  @hash['console']
end

#kubernetesHippo::Kubernetes

Return kubernetes configuration

Returns:



66
67
68
# File 'lib/hippo/recipe.rb', line 66

def kubernetes
  @kubernetes ||= Kubernetes.new(self, @hash['kubernetes'] || {})
end

#nameString?

Return the app name

Returns:

  • (String, nil)


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

Parameters:

  • string (String)

Returns:

  • (String)


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.message
    }
  end
  template.render(template_variables)
end

#repositoryHippo::Repository

Return the repository that this manifest should be working with

Returns:



50
51
52
53
54
# File 'lib/hippo/recipe.rb', line 50

def repository
  return unless @hash['repository']

  @repository ||= Repository.new(@hash['repository'])
end

#rootObject

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

#stagesHash<Hippo::Stage>

Return the stages for this recipe

Returns:



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_varsHash

Return the template variables that should be exposed

Returns:

  • (Hash)


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