Class: Confer::Recipe
- Inherits:
-
Object
- Object
- Confer::Recipe
- Defined in:
- lib/confer/recipe.rb
Overview
Public: Encapsulates a recipe. Usually instantiated by calling a method from a mixed in module such as ‘Confer::Recipe::Yaml`.
Defined Under Namespace
Classes: Step
Instance Attribute Summary collapse
-
#steps ⇒ Object
readonly
Public: An Array of steps this recipe contains.
Class Method Summary collapse
-
.from_array(array) ⇒ Object
Public: Loads a recipe from an array of steps.
-
.from_file(path) ⇒ Object
Public: Loads a recipe from a YAML file.
Instance Method Summary collapse
-
#initialize(steps = []) ⇒ Recipe
constructor
Public: Instantiate a new instance with the given steps.
Constructor Details
#initialize(steps = []) ⇒ Recipe
Public: Instantiate a new instance with the given steps.
array - An Array of Hash objects defining the steps for this recipe. opts - A Hash of options.
53 54 55 |
# File 'lib/confer/recipe.rb', line 53 def initialize(steps = []) @steps = steps end |
Instance Attribute Details
#steps ⇒ Object (readonly)
Public: An Array of steps this recipe contains.
45 46 47 |
# File 'lib/confer/recipe.rb', line 45 def steps @steps end |
Class Method Details
.from_array(array) ⇒ Object
Public: Loads a recipe from an array of steps.
array - An Array containing a Hash of options indexed by name for each
step in the recipe.
Returns a Recipe instance.
38 39 40 |
# File 'lib/confer/recipe.rb', line 38 def self.from_array(array) Recipe.new array.map { |e| Step.new(*e.first) } end |
.from_file(path) ⇒ Object
Public: Loads a recipe from a YAML file.
path - A String containing the path to the YAML file to load.
Returns a Recipe instance.
22 23 24 25 26 27 28 |
# File 'lib/confer/recipe.rb', line 22 def self.from_file(path) self.from_array YAML.load File.open(path, 'r').read rescue Errno::ENOENT => e raise RecipeNotFoundError.new(e) rescue Psych::SyntaxError => e raise RecipeSyntaxError.new(e) end |