class Guard::Tishadow::Builder

Public Class Methods

new(options = {}) click to toggle source
# File lib/guard/tishadow/builder.rb, line 10
def initialize(options = {})
  @build_command = options.delete(:build_command) || "alloy compile --config platform=ios 2>&1 && tishadow close && tishadow run"
  @spec_command = options.delete(:spec_command) || "tishadow spec"
  @verbose = options.delete(:verbose)
  @update = options.delete(:update)
  @spec = options.delete(:spec)
  @app_root = options.delete(:app_root)
  @update = true if @update.nil?
  @last_notice_at = nil
  @clock = nil
  @reload = false
end

Public Instance Methods

clear_notified() click to toggle source
# File lib/guard/tishadow/builder.rb, line 42
def clear_notified
  @last_notice_at = nil
end
format_result(result) click to toggle source
# File lib/guard/tishadow/builder.rb, line 93
def format_result(result)
  if @verbose
    UI.info(result)
  else
    UI.error(result.split("\n").grep(/error/i).join("\n"))
  end
end
maybe_build() click to toggle source

TODO: watch the process result and treat errors more carefully

# File lib/guard/tishadow/builder.rb, line 77
def maybe_build
  return unless @last_notice_at
  if time_to_build?
    UI.info "Tishadow building at #{Time.now} with \"#{@build_command}\""
    run_or_update
    clear_notified
    stop_clock
  end
end
notify(reload = false) click to toggle source
# File lib/guard/tishadow/builder.rb, line 23
def notify(reload = false)
  @reload ||= reload
  set_notified
  start_clock unless @clock
end
run() click to toggle source
# File lib/guard/tishadow/builder.rb, line 50
def run
  shell_command(@build_command)
  UI.info("Alloy compile and tishadow run complete.")
end
run_or_update() click to toggle source
# File lib/guard/tishadow/builder.rb, line 65
def run_or_update
  UI.info "Tishadow building at #{Time.now} with \"#{@build_command}\""
  if @reload || !@update
    @reload = false
    run
  else
    update
  end
  spec if @spec
end
set_notified() click to toggle source
# File lib/guard/tishadow/builder.rb, line 38
def set_notified
  @last_notice_at = Time.now
end
shell_command(cmd) click to toggle source
# File lib/guard/tishadow/builder.rb, line 87
def shell_command(cmd)
  cmd = "(cd #{@app_root} && #{cmd})" if @app_root
  UI.info(cmd)
  format_result(`#{cmd}`)
end
spec() click to toggle source
# File lib/guard/tishadow/builder.rb, line 60
def spec
  shell_command(@spec_command)
  UI.info("Spec run complete.")
end
start_clock() click to toggle source
# File lib/guard/tishadow/builder.rb, line 29
def start_clock
  @clock = PeriodCaller.new 1, :maybe_build, Celluloid.current_actor
end
stop_clock() click to toggle source
# File lib/guard/tishadow/builder.rb, line 33
def stop_clock
  @clock.terminate
  @clock = nil
end
time_to_build?() click to toggle source
# File lib/guard/tishadow/builder.rb, line 46
def time_to_build?
  (Time.now - @last_notice_at) > 1
end
update() click to toggle source
# File lib/guard/tishadow/builder.rb, line 55
def update
  shell_command("#{@build_command} --update")
  UI.info("Alloy compile and tishadow run --update complete.")
end