alsa_aconnect 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 15f9788a8fe37cd553690282394fdac0bd2bf30de7dccffd6b83540013ba55f4
4
- data.tar.gz: 01d4786195dccd53b11184be34d34eae6da37a2d0bab6e79ec0fc2125926d7b6
3
+ metadata.gz: da2e1f58bb84d8f28e0c8d7b9b4c8db07de4471a5401192d754ae2e1f0d635d5
4
+ data.tar.gz: f8f1826eaf299c9718ac0158add3d832d2ab99c6e92a8c8abf853a7d193b1bff
5
5
  SHA512:
6
- metadata.gz: 9ceb96edc8acb00da4bc75e8ce8c972cdd5486b39d6587b1513da9abc57edc3abd9625e25fa6d8297d63952053a61e68632b22cb412ae77c5ac992dcd6a5173e
7
- data.tar.gz: 6309907438e7bdc992be734b2ef81c60ca2e510a2721bef9b0b14f796f6d58c5e0c035fa6b335a5a77b9f3974141de669d4f3f70c131ec02c92e15ae2d14d27d
6
+ metadata.gz: c843743897fdffde6daa16facf423d79b6f3b7baa86cf557931da88aba1af336cc1895ff8d0a9462fb32a32729606d71f6dc86198f91d87965014723d0dff547
7
+ data.tar.gz: ecec114bded1c1ec6673eb2f014f8d184e9c244d7f3c0032d0bda1b8ee2c5dcd670b49107d42457a924341d47b517b44293cf75808dabeeef18080828734e673
@@ -1,18 +1,20 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'alsa/aconnect/version'
4
+ require 'alsa/aconnect/config'
4
5
  require 'alsa/aconnect/error'
5
- require 'alsa/aconnect/cmd'
6
6
  require 'alsa/aconnect/parser'
7
7
  require 'alsa/aconnect/port'
8
8
  require 'alsa/aconnect/client'
9
9
 
10
+ require 'open3'
11
+
10
12
  module ALSA
11
13
  module Aconnect
12
14
  module_function
13
15
 
14
16
  def input_clients
15
- out = Cmd.run('-i', '-l')
17
+ out = run('-i', '-l')
16
18
  Parser.parse_clients(out).map { |text| Client.new(text, :input) }
17
19
  end
18
20
 
@@ -21,7 +23,7 @@ module ALSA
21
23
  end
22
24
 
23
25
  def output_clients
24
- out = Cmd.run('-o', '-l')
26
+ out = run('-o', '-l')
25
27
  Parser.parse_clients(out).map { |text| Client.new(text, :output) }
26
28
  end
27
29
 
@@ -33,14 +35,33 @@ module ALSA
33
35
  input = "#{input.client.id}:#{input.id}" if input.is_a?(Port)
34
36
  output = "#{output.client.id}:#{output.id}" if output.is_a?(Port)
35
37
 
36
- Cmd.run('-d', input, output)
38
+ run('-d', input, output)
37
39
  end
38
40
 
39
41
  def disconnect(input, output)
40
42
  input = "#{input.client.id}:#{input.id}" if input.is_a?(Port)
41
43
  output = "#{output.client.id}:#{output.id}" if output.is_a?(Port)
42
44
 
43
- Cmd.run(input, output)
45
+ run(input, output)
44
46
  end
47
+
48
+ def run(*arguments)
49
+ cmd = [config.exec_path, *arguments].compact.join(' ')
50
+ out, err, status = Open3.capture3(cmd)
51
+ code = status.exitstatus
52
+ raise Error.new code, err unless code.zero?
53
+
54
+ out
55
+ end
56
+
57
+ def config
58
+ @config ||= Config.new
59
+ end
60
+
61
+ def configure
62
+ yield config if block_given?
63
+ end
64
+
65
+ configure
45
66
  end
46
67
  end
@@ -0,0 +1,11 @@
1
+ module ALSA
2
+ module Aconnect
3
+ class Config
4
+ attr_accessor :exec_path
5
+
6
+ def initialize
7
+ @exec_path = 'aconnect'
8
+ end
9
+ end
10
+ end
11
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module ALSA
4
4
  module Aconnect
5
- VERSION = '0.1.2'
5
+ VERSION = '0.1.3'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: alsa_aconnect
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Denis Talakevich
@@ -32,7 +32,7 @@ files:
32
32
  - examples/midi_keyboard.rb
33
33
  - lib/alsa/aconnect.rb
34
34
  - lib/alsa/aconnect/client.rb
35
- - lib/alsa/aconnect/cmd.rb
35
+ - lib/alsa/aconnect/config.rb
36
36
  - lib/alsa/aconnect/error.rb
37
37
  - lib/alsa/aconnect/parser.rb
38
38
  - lib/alsa/aconnect/port.rb
@@ -1,29 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'open3'
4
-
5
- module ALSA
6
- module Aconnect
7
- class Cmd
8
- EXEC = 'aconnect'
9
-
10
- def self.run(*arguments)
11
- new(EXEC, arguments).run
12
- end
13
-
14
- def initialize(exec, *arguments)
15
- @exec = exec
16
- @arguments = arguments
17
- end
18
-
19
- def run
20
- cmd = [@exec, *@arguments].compact.join(' ')
21
- out, err, status = Open3.capture3(cmd)
22
- code = status.exitstatus
23
- raise Error.new code, err.join("\n") unless code.zero?
24
-
25
- out
26
- end
27
- end
28
- end
29
- end