Skip to content
This repository
tree: 08979cb853
Fetching contributors…

Cannot retrieve contributors at this time

executable file 104 lines (79 sloc) 2.637 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
#!/usr/bin/env bash

original_ruby_strings=$rvm_ruby_strings
original_ruby_string=$rvm_ruby_string

source "$rvm_scripts_path/base"

rvm_monitor_sleep="${rvm_monitor_sleep:-2}"

timestamp()
{
  if [[ "Darwin" = "$(uname)" ]] ; then
    echo $(stat -f "%m" $1)
  else
    echo $(stat -c "%Y" $1)
  fi
}

push_if_timestamp_changed()
{
  local file=$1

  local file_timestamp=$(timestamp "$file")

  eval "time=\$${framework}_timestamp"

  if [[ "$file_timestamp" -gt $time ]] ; then

    array_push "changed_${framework}_files" $file

  fi
}

update_timestamp()
{
  if [[ -d "${1}/" ]] ; then

    \touch "$rvm_path/${$}_${1}_timestamp"

    eval "${1}_timestamp=\$(timestamp \"$rvm_path/${$}_${1}_timestamp\")"

  fi
}

update_timestamp "test"
update_timestamp "spec"

while : ; do
  changed_test_files=() ; changed_spec_files=() ; changed_code_files=()

  for file in lib/**/*.rb lib/*.rb app/**/*.rb app/*.rb ; do
    if [[ -f "$file" ]] ; then push_if_timestamp_changed $file "code" ; fi
  done

  for framework in test spec ; do

    if [[ -d "$framework/" ]] ; then

      for file in ${framework}/**/*_${framework}.rb ${framework}/*_${framework}.rb ; do
        if [[ -f "$file" ]] ; then
          push_if_timestamp_changed $file $framework
        fi
      done

      if [[ "$(array_length "changed_${framework}_files")" -gt 0 ]] ; then
        rvm_ruby_strings=$original_ruby_strings
        rvm_ruby_string=$original_ruby_string
        if [[ "spec" = "$framework" ]] ; then
          rvm_action="spec"
          rvm_ruby_args="spec/spec_helper.rb ${changed_spec_files[*]}"
          "$rvm_scripts_path/set" $rvm_action $rvm_ruby_args
        elif [[ "test" = "$framework" ]] ; then
          rvm_action="ruby"
          rvm_ruby_args=" -r$(echo "${changed_test_files[*]}" | sed 's/ / -r/g') test/test_helper.rb"
          "$rvm_scripts_path/set" $rvm_action $rvm_ruby_args
        fi
        update=1
      fi

      if [[ "$(array_length "changed_code_files")" -gt 0 ]] ; then
        rvm_ruby_strings=$original_ruby_strings
        rvm_ruby_string=$original_ruby_string
        if [[ "spec" = "$framework" ]] ; then
          rvm_action="spec"
          rvm_ruby_args="spec/"
          "$rvm_scripts_path/set" $rvm_action $rvm_ruby_args
        elif [[ "test" = "$framework" ]] ; then
          rvm_action="rake"
          rvm_ruby_args="test"
          "$rvm_scripts_path/set" "$rvm_action" $rvm_ruby_args
        fi
        update=1
      fi
    fi

    if [[ "$update" -eq 1 ]] ; then
      update_timestamp $framework
    fi
  done

  unset update changed_test_files changed_spec_files

  sleep $rvm_monitor_sleep
done
Something went wrong with that request. Please try again.