Class: Kashi::DSL

Inherits:
Object
  • Object
show all
Defined in:
lib/kashi/dsl.rb,
lib/kashi/dsl/cake.rb,
lib/kashi/dsl/test.rb,
lib/kashi/dsl/contact_group.rb

Defined Under Namespace

Classes: Cake, ContactGroup, Test

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filepath, options, &block) ⇒ DSL

Returns a new instance of DSL.



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/kashi/dsl.rb', line 17

def initialize(filepath, options, &block)
  @filepath = filepath
  @result = OpenStruct.new(cake: nil)

  @context = Hashie::Mash.new(
    filepath: filepath,
    templates: {},
    options: options,
  )

  instance_eval(&block)
end

Instance Attribute Details

#resultObject (readonly)

Returns the value of attribute result.



15
16
17
# File 'lib/kashi/dsl.rb', line 15

def result
  @result
end

Class Method Details

.define(source, filepath, options) ⇒ Object



8
9
10
11
12
# File 'lib/kashi/dsl.rb', line 8

def define(source, filepath, options)
  self.new(filepath, options) do
    eval(source, binding, filepath)
  end
end

Instance Method Details

#cake(&block) ⇒ Object



46
47
48
49
50
51
52
# File 'lib/kashi/dsl.rb', line 46

def cake(&block)
  if @result.cake
    @result.cake = Cake.new(@context, @result.cake.tests, @result.cake.contact_groups, &block).result
  else
    @result.cake = Cake.new(@context, &block).result
  end
end

#require(file) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/kashi/dsl.rb', line 30

def require(file)
  scfile = (file =~ %r|\A/|) ? file : File.expand_path(File.join(File.dirname(@filepath), file))

  if File.exist?(scfile)
    instance_eval(File.read(scfile), scfile)
  elsif File.exist?("#{scfile}.rb")
    instance_eval(File.read("#{scfile}.rb"), "#{scfile}.rb")
  else
    Kernel.require(file)
  end
end

#template(name, &block) ⇒ Object



42
43
44
# File 'lib/kashi/dsl.rb', line 42

def template(name, &block)
  @context.templates[name.to_s] = block
end