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 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 |
#handlers ⇒ Array<Serverkit::Resource>
32 33 34 35 36 |
# File 'lib/serverkit/recipe.rb', line 32 def handlers @handlers ||= Array(handlers_property).flat_map do |attributes| ResourceBuilder.new(self, attributes).build.to_a end end |
#merge(recipe) ⇒ Serverkit::Recipe
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/serverkit/recipe.rb', line 40 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
54 55 56 57 58 |
# File 'lib/serverkit/recipe.rb', line 54 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.
61 62 63 |
# File 'lib/serverkit/recipe.rb', line 61 def to_hash @recipe_data.merge("resources" => resources.map(&:attributes)) end |
#valid? ⇒ Boolean
65 66 67 |
# File 'lib/serverkit/recipe.rb', line 65 def valid? errors.empty? end |