Class: Kitchen::Recipe
Overview
An object that yields a Document
for modification (those modifications are the “recipe”)
Direct Known Subclasses
Instance Attribute Summary collapse
-
#document ⇒ Document
The document the recipe makes available for modification.
-
#my_i18n_backend ⇒ I18n::Backend::Simple?
readonly
An I18n backend specific to this recipe, may be nil.
-
#source_location ⇒ String
readonly
The file location of the recipe.
Instance Method Summary collapse
-
#bake ⇒ Object
Executes the block given to
Recipe.new
on the document. -
#initialize(locales_dir: nil) {|doc| ... } ⇒ Recipe
constructor
Make a new Recipe.
Constructor Details
#initialize(locales_dir: nil) {|doc| ... } ⇒ Recipe
Make a new Recipe
46 47 48 49 50 51 52 53 |
# File 'lib/kitchen/recipe.rb', line 46 def initialize(locales_dir: nil, &block) raise(RecipeError, 'Recipes must be initialized with a block') unless block_given? @source_location = block.source_location[0] @block = block load_my_i18n_backend(locales_dir) end |
Instance Attribute Details
#document ⇒ Document
The document the recipe makes available for modification
11 12 13 |
# File 'lib/kitchen/recipe.rb', line 11 def document @document end |
#my_i18n_backend ⇒ I18n::Backend::Simple? (readonly)
An I18n backend specific to this recipe, may be nil
19 20 21 |
# File 'lib/kitchen/recipe.rb', line 19 def my_i18n_backend @my_i18n_backend end |
#source_location ⇒ String (readonly)
The file location of the recipe
15 16 17 |
# File 'lib/kitchen/recipe.rb', line 15 def source_location @source_location end |
Instance Method Details
#bake ⇒ Object
Executes the block given to Recipe.new
on the document. Aka, does the baking.
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/kitchen/recipe.rb', line 57 def bake with_my_locales do @block.to_proc.call(document) end rescue RecipeError, ElementNotFoundError, Nokogiri::CSS::SyntaxError => e print_recipe_error_and_exit(e) rescue ArgumentError, NoMethodError => e raise unless any_stack_file_matches_source_location?(e) print_recipe_error_and_exit(e) rescue NameError => e raise unless stack_starts_with_source_location?(e) print_recipe_error_and_exit(e) end |