Class: Salt::Saltfile

Inherits:
Object
  • Object
show all
Defined in:
lib/salt/saltfile.rb

Defined Under Namespace

Classes: DSL

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(basedir = '.', formuladir = nil, saltfile = nil) ⇒ Saltfile

Returns a new instance of Saltfile.

Parameters:

  • basedir (String) (defaults to: '.')
  • formuladir (String) (defaults to: nil)
  • saltfile (String) (defaults to: nil)


16
17
18
19
20
21
22
# File 'lib/salt/saltfile.rb', line 16

def initialize(basedir='.', formuladir=nil, saltfile=nil)
  @basedir = basedir
  @formuladir = formuladir || @basedir
  @saltfile = saltfile || File.join(@basedir, 'Saltfile')
  
  @formulas = []
end

Instance Attribute Details

#basedirObject (readonly)

Returns the value of attribute basedir.



8
9
10
# File 'lib/salt/saltfile.rb', line 8

def basedir
  @basedir
end

#formuladirObject (readonly)

Returns the value of attribute formuladir.



9
10
11
# File 'lib/salt/saltfile.rb', line 9

def formuladir
  @formuladir
end

#formulasObject (readonly)

Returns the value of attribute formulas.



10
11
12
# File 'lib/salt/saltfile.rb', line 10

def formulas
  @formulas
end

#saltfileObject (readonly)

Returns the value of attribute saltfile.



11
12
13
# File 'lib/salt/saltfile.rb', line 11

def saltfile
  @saltfile
end

Instance Method Details

#add_formula(name, args) ⇒ Object

Parameters:

  • name (String)
  • args (*Object)


45
46
47
# File 'lib/salt/saltfile.rb', line 45

def add_formula(name, args)
  @formulas << Salt::Formula.new(name, @formuladir, args)
end

#loadObject



25
26
27
28
29
30
31
# File 'lib/salt/saltfile.rb', line 25

def load 
  if File.readable? @saltfile
    self.load!
  else
    $stderr.puts "Saltfile (#{@saltfile}) missing or unreadable"
  end
end

#load!Object



34
35
36
37
38
39
40
# File 'lib/salt/saltfile.rb', line 34

def load!
  dsl = DSL.new(self)
  dsl.instance_eval(saltfile_contents, @saltfile)
rescue SyntaxError, LoadError => e
  puts e.inspect.magenta
  raise Salt::Matrix::Error.wrap(e, "Failed to process #{@saltfile}")
end

#saltfile_contentsFile

Returns:

  • (File)


50
51
52
# File 'lib/salt/saltfile.rb', line 50

def saltfile_contents
  File.read(@saltfile)
end