Class: Beaver

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBeaver

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_locObject

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

#cleanObject

Clean beaver



54
55
56
# File 'lib/beaver.rb', line 54

def clean
  FileUtils.rm_r @cache_loc
end

#endObject

Put this at the end of a file



48
49
50
51
# File 'lib/beaver.rb', line 48

def end
  command = ARGV[0] || @mainCommand
  self.call command
end