Class: Whisk::WhiskFile

Inherits:
Object
  • Object
show all
Defined in:
lib/whisk/whiskfile.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeWhiskFile

Returns a new instance of WhiskFile.



32
33
34
# File 'lib/whisk/whiskfile.rb', line 32

def initialize
  @bowls = {}
end

Instance Attribute Details

#bowlsObject

Returns the value of attribute bowls.



30
31
32
# File 'lib/whisk/whiskfile.rb', line 30

def bowls
  @bowls
end

Class Method Details

.from_file(filename) ⇒ Object



51
52
53
54
55
56
57
58
59
# File 'lib/whisk/whiskfile.rb', line 51

def from_file(filename)
  if ::File.exists?(filename) && ::File.readable?(filename)
    whiskfile = Whisk::WhiskFile.new
    whiskfile.instance_eval(::IO.read(filename), filename, 1)
    whiskfile
  else
    raise IOError, "Cannot open or read #{filename}!"
  end
end

Instance Method Details

#add_bowl(bowl) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/whisk/whiskfile.rb', line 36

def add_bowl(bowl)
  if bowls.has_key? bowl.name
    raise ArgumentError, "bowl #{bowl.name} already exists"
  else
    bowls[bowl.name] = bowl
  end
end

#bowl(name, &block) ⇒ Object



44
45
46
47
48
# File 'lib/whisk/whiskfile.rb', line 44

def bowl(name, &block)
  b = Whisk::Resource::Bowl.new(name)
  b.instance_eval(&block) if block_given?
  add_bowl(b)
end