Class: Ru::CommandManager

Inherits:
Object
  • Object
show all
Defined in:
lib/ru/command_manager.rb

Defined Under Namespace

Classes: InvalidCodeError, InvalidNameError

Instance Method Summary collapse

Instance Method Details

#allObject



22
23
24
# File 'lib/ru/command_manager.rb', line 22

def all
  get_commands
end

#get(name) ⇒ Object



16
17
18
19
20
# File 'lib/ru/command_manager.rb', line 16

def get(name)
  validate_name(name)
  commands = get_commands
  commands[name]
end

#save(name, code) ⇒ Object

Raises:



8
9
10
11
12
13
14
# File 'lib/ru/command_manager.rb', line 8

def save(name, code)
  raise InvalidCodeError.new("Invalid code. Code cannot be blank.") if code.blank?
  validate_name(name)
  commands = get_commands
  commands[name] = code
  save_commands(commands)
end