Module: ClusterBomb::Shawties

Included in:
BombShell
Defined in:
lib/cluster_bomb/shawties.rb

Constant Summary collapse

SHAWTIES_FILE_NAME =
File.join(Configuration::HOME,'shawties')

Instance Method Summary collapse

Instance Method Details

#define_shawtie(name, command) ⇒ Object



6
7
8
9
10
11
12
13
14
# File 'lib/cluster_bomb/shawties.rb', line 6

def define_shawtie(name, command)
  @shawties ||={}
  unless command.nil?
    @shawties[name]=command
  else
    @shawties.delete name
  end
  save_shawties
end

#get_shawtie(name) ⇒ Object



15
16
17
# File 'lib/cluster_bomb/shawties.rb', line 15

def get_shawtie(name)
  @shawties[name]
end

#load_shawties!Object



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/cluster_bomb/shawties.rb', line 18

def load_shawties!
  @shawties ||={}
  Configuration.check_dir
  begin
    buf = File.read(SHAWTIES_FILE_NAME)
  rescue
    `touch #{SHAWTIES_FILE_NAME}`
    buf = File.read(SHAWTIES_FILE_NAME)
  end
  unless buf.empty?
    @shawties = YAML.load(buf)
  end    
end

#save_shawtiesObject



31
32
33
34
# File 'lib/cluster_bomb/shawties.rb', line 31

def save_shawties
  Configuration::check_dir    
  File.open(SHAWTIES_FILE_NAME,"w") {|f| f.write(@shawties.to_yaml)}    
end

#shawtie_namesObject



35
36
37
# File 'lib/cluster_bomb/shawties.rb', line 35

def shawtie_names
  (@shawties.keys + ['d','l']).sort
end

#shawties_listObject



38
39
40
41
42
43
44
# File 'lib/cluster_bomb/shawties.rb', line 38

def shawties_list
  keys = @shawties.keys.sort
  puts "Available shorts:"
  keys.each do |k|
    puts "#{k}\n    #{@shawties[k]}"
  end
end