Class: TheDude::Dsl

Inherits:
Object
  • Object
show all
Defined in:
lib/the_dude/dsl.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.from_file(path) ⇒ Object

Reads in a file and processes it using The Dude Dsl

Parameters:

  • path (String)

    Path to the file to read



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

def from_file path
  run File.read(path) if File.exists? path
end

.run(text = nil, &code) ⇒ Object

Runs the specified code inside an instance of the DSL. Code can be passed as a string or block. If both are given, the string is ignored.

Parameters:

  • text (String) (defaults to: nil)

    Code to run

  • code (Block)

    Code to run



31
32
33
34
35
36
37
# File 'lib/the_dude/dsl.rb', line 31

def run text=nil, &code
  if block_given?
    new.instance_exec &code
  else
    new.instance_eval text
  end
end

Instance Method Details

#ask(*args) ⇒ Object

Forwards the call on to TheDude.ask



4
5
6
# File 'lib/the_dude/dsl.rb', line 4

def ask *args
  TheDude.ask *args
end

#command(*args, &block) ⇒ Object

Forwards the call on to Command.new



9
10
11
# File 'lib/the_dude/dsl.rb', line 9

def command *args, &block
  TheDude::Command.new *args, &block
end

#say(*args) ⇒ Object

Forwards the call on to TheDude.say



14
15
16
# File 'lib/the_dude/dsl.rb', line 14

def say *args
  TheDude.say *args
end

#var(*args) ⇒ Object

Creates and registers a new variable



19
20
21
# File 'lib/the_dude/dsl.rb', line 19

def var *args
  TheDude::Variable.new(*args).register
end