class PebbleX::Pebble
Attributes
pebble_id[RW]
phone[RW]
verbose[RW]
Public Class Methods
new(environment)
click to toggle source
# File lib/pebble_x/pebble.rb, line 8 def initialize(environment) @pebble_cmd = environment.pebble_cmd end
Public Instance Methods
build()
click to toggle source
# File lib/pebble_x/pebble.rb, line 56 def build pebble_call('build') end
debug()
click to toggle source
# File lib/pebble_x/pebble.rb, line 68 def debug r = install r == 0 ? logs : r end
install()
click to toggle source
# File lib/pebble_x/pebble.rb, line 60 def install pebble_call('install', true) end
kill_pebble()
click to toggle source
# File lib/pebble_x/pebble.rb, line 44 def kill_pebble sys_call('pkill -f "python.*pebble.py "') sleep(0.5) # phone's Pebble app needs some time before it accepts new connections end
logs()
click to toggle source
# File lib/pebble_x/pebble.rb, line 64 def logs pebble_call('logs', true) end
pebble_call(args, requires_connection=false)
click to toggle source
# File lib/pebble_x/pebble.rb, line 49 def pebble_call(args, requires_connection=false) kill_pebble args += " --phone=#{@phone}" if requires_connection and @phone args += " --pebble_id=#{@pebble_id}" if requires_connection and @pebble_id sys_call("#{@pebble_cmd} #{args}") end
process_sys_call_line(line)
click to toggle source
# File lib/pebble_x/pebble.rb, line 16 def process_sys_call_line(line) return line unless line line.gsub %r{^(.*?)(:\d+:(\d+:)? (warning|error):)} do |full_match,foo| File.expand_path($1, File.join(pwd, 'build')) + $2 end end
pwd()
click to toggle source
# File lib/pebble_x/pebble.rb, line 12 def pwd Dir.pwd end
sys_call(call)
click to toggle source
# File lib/pebble_x/pebble.rb, line 23 def sys_call(call) r, io = IO.pipe fork do system(call, out: io, err: io) io.puts $?.exitstatus end io.close exit_status = nil r.each_line do |l| if r.eof? exit_status = l.to_i else l = process_sys_call_line(l) $stderr.puts l if l end end exit_status end