Class: MetaBridge::Bridge

Inherits:
Object
  • Object
show all
Includes:
Command
Defined in:
lib/meta_bridge/bridge.rb

Overview

Wrapper class for the Android Debug Bridge (adb).

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Command

#run

Instance Attribute Details

#device_idObject

Returns the value of attribute device_id.



8
9
10
# File 'lib/meta_bridge/bridge.rb', line 8

def device_id
  @device_id
end

Instance Method Details

#adb(subcommand, params = []) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/meta_bridge/bridge.rb', line 30

def adb(subcommand, params = [])
  connect_to_device if device_id && subcommand != 'connect'

  cmd = []
  params = params.respond_to?(:join) ? params.join(' ') : params.to_s

  cmd << 'adb'
  cmd << "-s #{device_id}" if device_id
  cmd << subcommand
  cmd << params.is_a?(String) ? params : params.join(' ')

  cmd.join(' ')
end

#connect_to_deviceObject



26
27
28
# File 'lib/meta_bridge/bridge.rb', line 26

def connect_to_device
  run(adb 'connect', device_id)
end

#get_stateObject



10
11
12
# File 'lib/meta_bridge/bridge.rb', line 10

def get_state
  run(adb 'get-state') { |out| out.gets.strip }
end

#logcat(opts = {}) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/meta_bridge/bridge.rb', line 14

def logcat(opts = {})
  params = []
  params << '-v threadtime'
  params << '-d'

  run(adb 'logcat', params) do |out|
    while line = out.gets
      puts line    
    end
  end
end