Class: Beaver
- Inherits:
-
Object
- Object
- Beaver
- Defined in:
- lib/beaver.rb
Instance Attribute Summary collapse
-
#cache_loc ⇒ Object
The location where Beaver caches.
Instance Method Summary collapse
-
#__appendCommand(name, func) ⇒ Object
Appends a command to the global beaver.
- #__appendCommandCB(name, &func) ⇒ Object
-
#call(cmd) ⇒ Object
Call a command.
-
#clean ⇒ Object
Clean beaver.
-
#end ⇒ Object
Put this at the end of a file.
-
#initialize ⇒ Beaver
constructor
Initializer should not be used outside of this module.
Constructor Details
#initialize ⇒ Beaver
Initializer should not be used outside of this module
14 15 16 17 18 19 20 21 |
# File 'lib/beaver.rb', line 14 def initialize # Contains all commands # [commandName: String => command: Function] @commands = Hash.new # Contains the main command name @mainCommand = nil @cache_loc = "./.beaver" end |
Instance Attribute Details
#cache_loc ⇒ Object
The location where Beaver caches
11 12 13 |
# File 'lib/beaver.rb', line 11 def cache_loc @cache_loc end |
Instance Method Details
#__appendCommand(name, func) ⇒ Object
Appends a command to the global beaver
24 25 26 27 28 29 30 |
# File 'lib/beaver.rb', line 24 def __appendCommand(name, func) if @commands.size == 0 @mainCommand = name.to_sym end @commands[name.to_sym] = func end |
#__appendCommandCB(name, &func) ⇒ Object
32 33 34 |
# File 'lib/beaver.rb', line 32 def __appendCommandCB(name, &func) self.__appendCommand(name, func) end |
#call(cmd) ⇒ Object
Call a command
37 38 39 40 41 42 43 44 45 |
# File 'lib/beaver.rb', line 37 def call(cmd) _cmd = @commands[cmd.to_sym] if _cmd.nil? puts "No command called #{cmd} found" exit 1 end _cmd.call end |
#clean ⇒ Object
Clean beaver
54 55 56 |
# File 'lib/beaver.rb', line 54 def clean FileUtils.rm_r @cache_loc end |