Class: Beg

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv = []) ⇒ Beg

Returns a new instance of Beg.


8
# File 'lib/beg.rb', line 8

def initialize argv = []; @argv = argv end

Instance Attribute Details

#argvObject

Returns the value of attribute argv


2
3
4
# File 'lib/beg.rb', line 2

def argv
  @argv
end

Class Method Details

.cli(argv) ⇒ Object


4
5
6
# File 'lib/beg.rb', line 4

def self.cli argv
  Beg.new(argv).run
end

Instance Method Details

#color(num, str) ⇒ Object


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

def color num, str
  "\e[%dm%s\e[0m" % [num, str]
end

#runObject


10
11
12
13
14
15
16
# File 'lib/beg.rb', line 10

def run
  if File.exists? 'Guardfile'
    run_with_guardfile
  else
    run_poor_man_style
  end
end

#run_poor_man_styleObject


22
23
24
25
26
27
# File 'lib/beg.rb', line 22

def run_poor_man_style
  loop do
    verbose_system ['inotifywait'] + Dir.glob('**/*.rb')
    verbose_system %w(bundle exec rake test)
  end
end

#run_with_guardfileObject


18
19
20
# File 'lib/beg.rb', line 18

def run_with_guardfile
  verbose_system %w(bundle exec guard) + @argv
end

#verbose_system(cmd) ⇒ Object


29
30
31
32
33
# File 'lib/beg.rb', line 29

def verbose_system cmd
  str = color 36, cmd.join(' ')
  puts "Running: " + str
  system *cmd
end