class Serverkit::Recipe
Attributes
Public Class Methods
Source
# File lib/serverkit/recipe.rb, line 14 def initialize(recipe_data, variables_path = nil) @recipe_data = recipe_data @variables_path = variables_path end
@param [Hash] recipe_data
@param [String, nil] variables_path
Used for recipe resource to render ERB template
Public Instance Methods
Source
# File lib/serverkit/recipe.rb, line 20 def errors @errors ||= if !has_valid_typed_recipe_data? errors_for_invalid_typed_recipe_data elsif !has_valid_typed_resources_property? errors_for_invalid_typed_resources_property else errors_in_resources end end
@return [Array<Serverkit::Errors::Base>]
Source
# File lib/serverkit/recipe.rb, line 31 def handlers @handlers ||= Array(handlers_property).flat_map do |attributes| ResourceBuilder.new(self, attributes).build.to_a end end
@return [Array<Serverkit::Resource>]
Source
# File lib/serverkit/recipe.rb, line 39 def merge(recipe) self.class.new( recipe_data.deep_merge(recipe.recipe_data) do |key, a, b| if a.is_a?(Array) a | b else b end end ) end
@param [Serverkit::Recipe] recipe @return [Serverkit::Recipe]
Source
# File lib/serverkit/recipe.rb, line 53 def resources @resources ||= resources_property.flat_map do |attributes| ResourceBuilder.new(self, attributes).build.to_a end end
@note recipe resource will be expanded into resources defined in its recipe @return [Array<Serverkit::Resources::Base>]
Source
# File lib/serverkit/recipe.rb, line 60 def to_hash @recipe_data.merge("resources" => resources.map(&:attributes)) end
@return [Hash] Fully-expanded recipe data
Private Instance Methods
Source
# File lib/serverkit/recipe.rb, line 71 def errors_for_invalid_typed_recipe_data [Errors::InvalidRecipeTypeError.new(@recipe_data.class)] end
@return [Array<Serverkit::Errors::Base>]
Source
# File lib/serverkit/recipe.rb, line 76 def errors_for_invalid_typed_resources_property [Errors::InvalidResourcesTypeError.new(resources_property.class)] end
@return [Array<Serverkit::Errors::Base>]
Source
# File lib/serverkit/recipe.rb, line 81 def errors_in_resources resources.flat_map(&:all_errors) end
@return [Array<Serverkit::Errors::AttributeValidationError>]
Source
# File lib/serverkit/recipe.rb, line 86 def handlers_property @recipe_data["handlers"] end
@return [Array<String>, nil]
Source
# File lib/serverkit/recipe.rb, line 94 def has_valid_typed_recipe_data? @recipe_data.is_a?(Hash) end
Source
# File lib/serverkit/recipe.rb, line 90 def has_valid_typed_resources_property? resources_property.is_a?(Array) end
Source
# File lib/serverkit/recipe.rb, line 99 def resources_property @recipe_data["resources"] end
@return [Array<String>, nil]