Class: GembirdBackend::Command
- Inherits:
-
Object
- Object
- GembirdBackend::Command
- Defined in:
- lib/gembird-backend/command.rb
Constant Summary collapse
- BIN =
the sispmctl binary
'sispmctl'
Instance Attribute Summary collapse
-
#dry ⇒ Object
readonly
set dry to true for testing purposes.
Instance Method Summary collapse
- #build(*options) ⇒ Object
- #call(action, argument = nil, options = {}) ⇒ Object
-
#devices ⇒ Array<Hash>
scans for devices.
- #exec(command) ⇒ Object
-
#initialize(dry = false) ⇒ Command
constructor
A new instance of Command.
-
#off!(socket = 'all', options = {}) ⇒ Array<Hash>
switch a socket off.
-
#on!(socket = 'all', options = {}) ⇒ Array<Hash>
switch a socket on.
-
#status(socket = 'all', options = {}) ⇒ Array<Hash>
get the status of a socket.
-
#toggle!(socket = 'all', options = {}) ⇒ Array<Hash>
toggle a socket.
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
#dry ⇒ Object (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 * [BIN, ].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, = {} args = [] if device = [: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 |
#devices ⇒ Array<Hash>
scans for 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
53 54 55 |
# File 'lib/gembird-backend/command.rb', line 53 def off! socket='all', ={} call '-f', socket, end |
#on!(socket = 'all', options = {}) ⇒ Array<Hash>
switch a socket on
46 47 48 |
# File 'lib/gembird-backend/command.rb', line 46 def on! socket='all', ={} call '-o', socket, end |
#status(socket = 'all', options = {}) ⇒ Array<Hash>
get the status of a socket
74 75 76 |
# File 'lib/gembird-backend/command.rb', line 74 def status socket='all', ={} call '-g', socket, end |
#toggle!(socket = 'all', options = {}) ⇒ Array<Hash>
toggle a socket
60 61 62 |
# File 'lib/gembird-backend/command.rb', line 60 def toggle! socket='all', ={} call '-t', socket, end |