Class: GembirdBackend::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/gembird-backend/command.rb

Constant Summary collapse

BIN =

the sispmctl binary

'sispmctl'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dry = false) ⇒ Command

Returns a new instance of Command.



7
8
9
# File 'lib/gembird-backend/command.rb', line 7

def initialize dry=false
  @dry = dry
end

Instance Attribute Details

#dryObject (readonly)

set dry to true for testing purposes



6
7
8
# File 'lib/gembird-backend/command.rb', line 6

def dry
  @dry
end

Instance Method Details

#build(*options) ⇒ Object



23
24
25
# File 'lib/gembird-backend/command.rb', line 23

def build *options
  [BIN, options].flatten.join ' '
end

#call(action, argument = nil, options = {}) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/gembird-backend/command.rb', line 11

def call action, argument = nil, options = {}
  args = []
  if device = options[:device]
    # serial or number
    args << (device.to_s.include?(":") ? "-D" : "-d")
    args << device
  end
  args << (argument ? [action, argument] : action)
  command = build args
  dry ? command : exec(command)
end

#devicesArray<Hash>

scans for devices

Examples:

return

[{:number=>"0",
  :usb_device=>"001",
  :usb_bus=>"004",
  :type=>"4-socket SiS-PM",
  :serial=>"02:01:48:af:e0"}]

Returns:

  • (Array<Hash>)

    devices



39
40
41
# File 'lib/gembird-backend/command.rb', line 39

def devices
  call '-s'
end

#exec(command) ⇒ Object



27
28
29
# File 'lib/gembird-backend/command.rb', line 27

def exec command
  `#{command}`
end

#off!(socket = 'all', options = {}) ⇒ Array<Hash>

switch a socket off

Returns:

  • (Array<Hash>)

    devices

See Also:



53
54
55
# File 'lib/gembird-backend/command.rb', line 53

def off! socket='all', options={}
  call '-f', socket, options
end

#on!(socket = 'all', options = {}) ⇒ Array<Hash>

switch a socket on

Returns:

  • (Array<Hash>)

    devices

See Also:



46
47
48
# File 'lib/gembird-backend/command.rb', line 46

def on! socket='all', options={}
  call '-o', socket, options
end

#status(socket = 'all', options = {}) ⇒ Array<Hash>

get the status of a socket

Examples:

return

[{:number=>"0",
  :usb_device => "003",
  :sockets=>{"1"=>"on",
             "2"=>"off",
             "3"=>"on",
             "4"=>"off"}}]
  :sockets=>{"1"=>"on", "2"=>"off", "3"=>"on", "4"=>"off"}}]

Returns:

  • (Array<Hash>)

    devices



74
75
76
# File 'lib/gembird-backend/command.rb', line 74

def status socket='all', options={}
  call '-g', socket, options
end

#toggle!(socket = 'all', options = {}) ⇒ Array<Hash>

toggle a socket

Returns:

  • (Array<Hash>)

    devices

See Also:



60
61
62
# File 'lib/gembird-backend/command.rb', line 60

def toggle! socket='all', options={}
  call '-t', socket, options
end