Class: PebbleX::Pebble
- Inherits:
-
Object
- Object
- PebbleX::Pebble
- Defined in:
- lib/pebble_x/pebble.rb
Instance Attribute Summary collapse
-
#pebble_id ⇒ Object
Returns the value of attribute pebble_id.
-
#phone ⇒ Object
Returns the value of attribute phone.
-
#verbose ⇒ Object
Returns the value of attribute verbose.
Instance Method Summary collapse
- #build ⇒ Object
- #debug ⇒ Object
-
#initialize(environment) ⇒ Pebble
constructor
A new instance of Pebble.
- #install ⇒ Object
- #kill_pebble ⇒ Object
- #logs ⇒ Object
- #pebble_call(args, requires_connection = false) ⇒ Object
- #process_sys_call_line(line) ⇒ Object
- #pwd ⇒ Object
- #sys_call(call) ⇒ Object
Constructor Details
#initialize(environment) ⇒ Pebble
Returns a new instance of Pebble.
8 9 10 |
# File 'lib/pebble_x/pebble.rb', line 8 def initialize(environment) @pebble_cmd = environment.pebble_cmd end |
Instance Attribute Details
#pebble_id ⇒ Object
Returns the value of attribute pebble_id.
6 7 8 |
# File 'lib/pebble_x/pebble.rb', line 6 def pebble_id @pebble_id end |
#phone ⇒ Object
Returns the value of attribute phone.
5 6 7 |
# File 'lib/pebble_x/pebble.rb', line 5 def phone @phone end |
#verbose ⇒ Object
Returns the value of attribute verbose.
4 5 6 |
# File 'lib/pebble_x/pebble.rb', line 4 def verbose @verbose end |
Instance Method Details
#build ⇒ Object
56 57 58 |
# File 'lib/pebble_x/pebble.rb', line 56 def build pebble_call('build') end |
#debug ⇒ Object
68 69 70 71 |
# File 'lib/pebble_x/pebble.rb', line 68 def debug r = install r == 0 ? logs : r end |
#install ⇒ Object
60 61 62 |
# File 'lib/pebble_x/pebble.rb', line 60 def install pebble_call('install', true) end |
#kill_pebble ⇒ Object
44 45 46 47 |
# 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 ⇒ Object
64 65 66 |
# File 'lib/pebble_x/pebble.rb', line 64 def logs pebble_call('logs', true) end |
#pebble_call(args, requires_connection = false) ⇒ Object
49 50 51 52 53 54 |
# 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) ⇒ Object
16 17 18 19 20 21 |
# 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.($1, File.join(pwd, 'build')) + $2 end end |
#pwd ⇒ Object
12 13 14 |
# File 'lib/pebble_x/pebble.rb', line 12 def pwd Dir.pwd end |
#sys_call(call) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# 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 |