Class: Rrr::Run

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(files) ⇒ Run

Returns a new instance of Run.



11
12
13
14
# File 'lib/cli.rb', line 11

def initialize(files)
  @files = files
  init && touch && run
end

Instance Attribute Details

#datetimeObject (readonly)

Returns the value of attribute datetime.



9
10
11
# File 'lib/cli.rb', line 9

def datetime
  @datetime
end

#filesObject (readonly)

Returns the value of attribute files.



9
10
11
# File 'lib/cli.rb', line 9

def files
  @files
end

Instance Method Details

#collectionObject



46
47
48
49
50
# File 'lib/cli.rb', line 46

def collection
  @collection ||= begin
    files.empty? ? list : files
  end
end

#initObject



16
17
18
19
20
21
22
# File 'lib/cli.rb', line 16

def init
  @datetime = begin
    Time.parse(File.open('.rrr', 'r').read)
  rescue
    Time.now
  end
end

#listObject



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

def list
  file_list = FileList.new('spec/**/*_spec.rb')
  file_list.select{|file| File.ctime(file) > datetime}
end

#rspecObject



52
53
54
# File 'lib/cli.rb', line 52

def rspec
  "rspec"
end

#runObject



35
36
37
38
39
40
41
42
43
44
# File 'lib/cli.rb', line 35

def run
  if collection.empty?
    puts "INFO: no recent changes in specs ... running all specs\nINFO: #{rspec}"
    command = rspec
  else
    command = "#{rspec} #{collection.join(' ')}"
    puts "rrr: #{command}"
  end
  system(command)
end

#touchObject



24
25
26
27
28
# File 'lib/cli.rb', line 24

def touch
  File.open('.rrr', 'w') do |file|
    file.write(Time.now)
  end
end