Class: Aide::Dsl

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

Overview

The Dsl class is used for parsing Aide dsl files. All of the functions made available by this class are available to any dsl file. TODO: This class needs better documentation.

Instance Method Summary collapse

Constructor Details

#initialize(bot, filename = nil) {|_self| ... } ⇒ Dsl

Creates a new Dsl instance.

Parameters:

  • bot: Aide::Bot. The bot this dsl will modify/set up.

  • filename: String. The file to parse, if any; defaults to nil.

Yields:

Yields self after the file is parsed.

Yields:

  • (_self)

Yield Parameters:

  • _self (Aide::Dsl)

    the object that the method was called on



16
17
18
19
20
# File 'lib/aide/dsl.rb', line 16

def initialize(bot, filename = nil)
  @bot = bot
  load_file filename if filename
  yield self if block_given?
end

Instance Method Details

#allow(*people) ⇒ Object

Adds *people to the allow_list.



39
40
41
# File 'lib/aide/dsl.rb', line 39

def allow(*people)
  @bot.add_allow_list people
end

#block(*people) ⇒ Object

Adds *people to the block_list.



46
47
48
# File 'lib/aide/dsl.rb', line 46

def block(*people)
  @bot.add_block_list people   
end

#bot_password(text) ⇒ Object

Sets the password for the Bot that is being loaded.



32
33
34
# File 'lib/aide/dsl.rb', line 32

def bot_password(text)
  @bot.password=text
end

#bot_username(text) ⇒ Object

Sets the username for the Bot that is being loaded.



25
26
27
# File 'lib/aide/dsl.rb', line 25

def bot_username(text)
  @bot.username=text
end

#load_block(&block) ⇒ Object

Parses a block as though it were a Dsl file.



70
71
72
# File 'lib/aide/dsl.rb', line 70

def load_block(&block)
  instance_eval(&block)
end

#load_file(filename) ⇒ Object

Reads in and parses a Dsl file.



63
64
65
# File 'lib/aide/dsl.rb', line 63

def load_file(filename)
  instance_eval(File.read(filename), filename)
end

#with(text, &block) ⇒ Object

Defines an action for the bot.

Parameters:

  • text: String. The text to match on.

  • *&block*: Block. The code to execute when text is found (see Aide::ActionContext)



56
57
58
# File 'lib/aide/dsl.rb', line 56

def with(text,&block)
  @bot.add_action text, block
end