class Guard::Gradle

Public Class Methods

new(options = {}) click to toggle source
Calls superclass method
# File lib/guard/gradle.rb, line 8
def initialize(options = {})
  @command = './gradlew'
  @task = 'test'
  @multi_projs = false
  @flags = false

  if options.has_key? :multi_project
    @multi_projs = options[:multi_project]
  end
  if options.has_key? :command
    @command = options[:command]
  end
  if options.has_key? :task
    @task = options[:task]
  end
  if options.has_key? :flags
    @flags = options[:flags]
  end

  @DEF_CMD = "#{@command} #{@task}"
  if @flags
    @DEF_CMD = "#{@DEF_CMD} #{@flags}"
  end

  super
end

Public Instance Methods

fire_command(command) click to toggle source
# File lib/guard/gradle.rb, line 55
def fire_command(command)
  UI.info "running #{command}"
  result = system command
  summary = result ? 'Success' : 'Failure'
  image = result ? :success : :failed
  notify(summary, image)
end
notify(summary, image) click to toggle source
# File lib/guard/gradle.rb, line 63
def notify(summary, image)
  ::Guard::Notifier.notify(summary, title: 'Gradle Test Results', image: image)
end
run_all() click to toggle source
# File lib/guard/gradle.rb, line 51
def run_all
  fire_command @DEF_CMD
end
run_on_changes(paths) click to toggle source
# File lib/guard/gradle.rb, line 35
def run_on_changes(paths)
  if paths.size == 1 && @multi_projs
    project = paths[0].split('/')[0]
    file = paths[0].split('/')[1]    
    if Dir.glob("#{project}/src/test/**/#{file}*").size > 0
      fire_command("#{@DEF_CMD} -p #{project} -Dtest.single=#{file} --daemon")
    else
      run_all
    end
  elsif(paths.size == 1) && (Dir.glob("src/test/**/#{paths[0]}*").size > 0)
    fire_command("#{@DEF_CMD} -Dtest.single=#{paths[0]} --daemon")
  else
    run_all
  end
end
start() click to toggle source
# File lib/guard/gradle.rb, line 67
def start
  fire_command @DEF_CMD
end