Class: Dog::Configure

Inherits:
Object
  • Object
show all
Defined in:
lib/dog/configure.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfigure

Returns a new instance of Configure.



27
28
29
30
31
# File 'lib/dog/configure.rb', line 27

def initialize
  @commands = {}
  @scheduled_tasks = []
  @chat_rooms = []
end

Instance Attribute Details

#chat_rooms(*chat_rooms) ⇒ Object (readonly)

Returns the value of attribute chat_rooms.



25
26
27
# File 'lib/dog/configure.rb', line 25

def chat_rooms
  @chat_rooms
end

#scheduled_tasksObject (readonly)

Returns the value of attribute scheduled_tasks.



25
26
27
# File 'lib/dog/configure.rb', line 25

def scheduled_tasks
  @scheduled_tasks
end

Class Method Details

._config_string(path) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/dog/configure.rb', line 16

def self._config_string(path)
  return File.read path if File.file? path

  Dir.foreach(path).each_with_object("") do |item, output|
    next if item == '.' or item == '..'
    output << _config_string(File.join(path, item))
  end
end

.parse(config_string) ⇒ Object



10
11
12
13
14
# File 'lib/dog/configure.rb', line 10

def self.parse(config_string)
  config = Configure.new
  config.instance_eval(config_string)
  config
end

.parse_path(config_path) ⇒ Object



6
7
8
# File 'lib/dog/configure.rb', line 6

def self.parse_path(config_path)
  parse(_config_string(config_path))
end

Instance Method Details

#command(title, &block) ⇒ Object



41
42
43
44
45
# File 'lib/dog/configure.rb', line 41

def command(title, &block)
  command = @commands.fetch title, Command.new(title)
  command.instance_eval &block
  @commands[title] = command
end

#commandsObject



33
34
35
# File 'lib/dog/configure.rb', line 33

def commands
  @commands.values
end

#get_command(command_title) ⇒ Object



37
38
39
# File 'lib/dog/configure.rb', line 37

def get_command(command_title)
  @commands[command_title]
end

#task(title) {|task| ... } ⇒ Object

Yields:



47
48
49
50
51
# File 'lib/dog/configure.rb', line 47

def task(title)
  task = ScheduledTask.new(title)
  yield task
  @scheduled_tasks << task
end