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>
- #handlers ⇒ Array<Serverkit::Resource>
-
#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 |
# File 'lib/serverkit/recipe.rb', line 18 def errors @errors ||= begin 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 end |
#handlers ⇒ Array<Serverkit::Resource>
31 32 33 34 35 |
# 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 |
#merge(recipe) ⇒ Serverkit::Recipe
39 40 41 42 43 44 45 46 47 48 49 |
# 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 |
#resources ⇒ Array<Serverkit::Resources::Base>
Note:
recipe resource will be expanded into resources defined in its recipe
53 54 55 56 57 |
# 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 |
#to_hash ⇒ Hash
Returns Fully-expanded recipe data.
60 61 62 |
# File 'lib/serverkit/recipe.rb', line 60 def to_hash @recipe_data.merge("resources" => resources.map(&:attributes)) end |
#valid? ⇒ Boolean
64 65 66 |
# File 'lib/serverkit/recipe.rb', line 64 def valid? errors.empty? end |