screenomat/lib/screenie/dsl/builder.rb

36 lines
624 B
Ruby
Raw Normal View History

2010-12-09 21:20:21 +00:00
require 'screenie/dsl/session'
module Screenie
module DSL
class Builder
attr_reader :sessions
def initialize(code = '', &block)
@sessions = []
if !code.empty?
instance_eval(code)
else
instance_eval(&block)
end
end
def session(name = nil, &block)
name ||= "screenie-#{Time.now.to_i}"
session = Session.new(name.to_sym, &block)
@sessions << session
end
def first
@sessions.first
end
def [](key)
@sessions.find { |session| session.name == key }
end
end
end
end