Class: Serverkit::Recipe
- Inherits:
-
Object
- Object
- Serverkit::Recipe
- Defined in:
- lib/serverkit/recipe.rb
Instance Attribute Summary collapse
-
#recipe_data ⇒ Object
readonly
Returns the value of attribute recipe_data.
-
#variables_path ⇒ Object
readonly
Returns the value of attribute variables_path.
Instance Method Summary collapse
- #errors ⇒ Array<Serverkit::Errors::Base>
-
#initialize(recipe_data, variables_path = nil) ⇒ Recipe
constructor
A new instance of Recipe.
- #merge(recipe) ⇒ Serverkit::Recipe
- #resources ⇒ Array<Serverkit::Resources::Base>
-
#to_hash ⇒ Hash
Fully-expanded recipe data.
- #valid? ⇒ Boolean
Constructor Details
#initialize(recipe_data, variables_path = nil) ⇒ Recipe
Returns a new instance of Recipe.
12 13 14 15 |
# File 'lib/serverkit/recipe.rb', line 12 def initialize(recipe_data, variables_path = nil) @recipe_data = recipe_data @variables_path = variables_path end |
Instance Attribute Details
#recipe_data ⇒ Object (readonly)
Returns the value of attribute recipe_data.
8 9 10 |
# File 'lib/serverkit/recipe.rb', line 8 def recipe_data @recipe_data end |
#variables_path ⇒ Object (readonly)
Returns the value of attribute variables_path.
8 9 10 |
# File 'lib/serverkit/recipe.rb', line 8 def variables_path @variables_path end |
Instance Method Details
#errors ⇒ Array<Serverkit::Errors::Base>
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/serverkit/recipe.rb', line 18 def errors @errors ||= begin case when !has_valid_typed_recipe_data? errors_for_invalid_typed_recipe_data when !has_valid_typed_resources_property? errors_for_invalid_typed_resources_property else errors_in_resources end end end |
#merge(recipe) ⇒ Serverkit::Recipe
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/serverkit/recipe.rb', line 33 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 |
#resources ⇒ Array<Serverkit::Resources::Base>
Note:
recipe resource will be expanded into resources defined in its recipe
47 48 49 50 51 |
# File 'lib/serverkit/recipe.rb', line 47 def resources @resources ||= resources_property.flat_map do |attributes| ResourceBuilder.new(self, attributes).build.to_a end end |
#to_hash ⇒ Hash
Returns Fully-expanded recipe data.
54 55 56 |
# File 'lib/serverkit/recipe.rb', line 54 def to_hash { "resources" => resources.map(&:attributes) } end |
#valid? ⇒ Boolean
58 59 60 |
# File 'lib/serverkit/recipe.rb', line 58 def valid? errors.empty? end |