Class: Automatic::Recipe

Inherits:
Object
  • Object
show all
Defined in:
lib/automatic/recipe.rb

Constant Summary collapse

PERMITTED_CLASSES =

A Recipe is trusted local configuration, but it is still loaded safely: the document may name none of its own Ruby classes to instantiate. That costs nothing, since no Recipe needs it. It is a second line of defence and not the trust boundary; see doc/REQUIREMENTS.md section 17.

[Date, Time, Symbol].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path = '') ⇒ Recipe

Returns a new instance of Recipe.



28
29
30
# File 'lib/automatic/recipe.rb', line 28

def initialize(path = '')
  load_recipe(path)
end

Instance Attribute Details

#procedureObject (readonly)

Returns the value of attribute procedure.



26
27
28
# File 'lib/automatic/recipe.rb', line 26

def procedure
  @procedure
end

Instance Method Details

#each_pluginObject



53
54
55
56
57
# File 'lib/automatic/recipe.rb', line 53

def each_plugin
  return enum_for(:each_plugin) unless block_given?

  @procedure.plugins.each { |plugin| yield plugin }
end

#load_recipe(path) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/automatic/recipe.rb', line 32

def load_recipe(path)
  resolved = resolve_path(path)
  document = parse(resolved)

  unless document.is_a?(Hash)
    raise InvalidRecipeError,
          "recipe #{resolved} is not a mapping"
  end

  @procedure = Hashie::Mash.new(document)

  unless @procedure.plugins.is_a?(Array)
    raise InvalidRecipeError,
          "recipe #{resolved} has no plugins sequence"
  end

  Automatic::Log.level(@procedure.global&.log&.level)
  Automatic::Log.puts('info', "Loading Recipe: #{resolved}")
  @procedure
end