i3ipc 0.2.0 → 0.4.0

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
- SHA1:
3
- metadata.gz: d1656014a13ed6678e5efba71d74c72e7d910906
4
- data.tar.gz: c41b56ab703cf2bc2322ed83218aa7f696e2552f
2
+ SHA256:
3
+ metadata.gz: c7e3d2c510024a85232a57b5f85b746e2048ecb7d502c7143c45e7288cbe0733
4
+ data.tar.gz: '059d5c94bb5cf00a0b9d2faaa01a96e27099fc2c5d9c9971382bf0d05152e0e7'
5
5
  SHA512:
6
- metadata.gz: 38f1d719f5c32f6ebd335d376481e76cb6be67ecba380af9753792654b05cf6adeecdb54847089fbf91372c3994291861d1cd49d22e9e660d3c62a9f1a3b5d69
7
- data.tar.gz: 136c448a42f39671740959c11c5beca1cd5f16115f2e983b590e6d60dbfd9ee480decde1f66b2c3fa4376ac708b5abe771fe055fd10f0ee2a676ba1adc2f045f
6
+ metadata.gz: ea322a9f4842087079a18be0cdc56a287e0891de881bd6cff69f955bbdeac2f28f39100ce44af4aca887ffdf346ea7279d7251785d3c29ceecce8be47c8f1aca
7
+ data.tar.gz: 487a918c2b6aa1b108ede111df9725477a3ea49fc8c9ae1a294b30f47d983d27c6790d50e3c2f0c2844c6104b68c955606f37267d3835ad8cf888706634358d4
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --format documentation --color
data/Gemfile CHANGED
@@ -1,4 +1,9 @@
1
- source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in i3ipc.gemspec
4
- gemspec
1
+ source "https://rubygems.org"
2
+
3
+ gem 'rspec'
4
+
5
+ group :development do
6
+ gem 'guard'
7
+ gem 'guard-rspec'
8
+ gem 'pry'
9
+ end
data/Guardfile ADDED
@@ -0,0 +1,5 @@
1
+ guard :rspec, cmd: 'rspec' do
2
+ watch(%r{^spec/.+_spec\.rb$})
3
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
4
+ watch('spec/spec_helper.rb') { "spec" }
5
+ end
@@ -27,9 +27,9 @@ module I3Ipc
27
27
  # con.close
28
28
  class Connection
29
29
 
30
- def initialize(connect = true)
31
- @protocol = Protocol.new
32
- open
30
+ def initialize(protocol = Protocol.new, autoconnect = true)
31
+ @protocol = protocol
32
+ open if autoconnect
33
33
  end
34
34
 
35
35
  def open
@@ -89,7 +89,7 @@ module I3Ipc
89
89
 
90
90
  private
91
91
 
92
- def reply_for(type, message = nil, events=nil)
92
+ def reply_for(type, message = nil)
93
93
  @protocol.send(type, message)
94
94
 
95
95
  Reply.parse(@protocol.receive type)
@@ -106,6 +106,5 @@ module I3Ipc
106
106
  else raise WrongEvent.new(event)
107
107
  end
108
108
  end
109
-
110
109
  end
111
110
  end
@@ -150,9 +150,21 @@ module I3Ipc
150
150
  end
151
151
 
152
152
  def get_socketpath
153
- path = `i3 --get-socketpath`.chomp!
154
- raise 'Unable to get i3 socketpath' unless path
155
- path
153
+ if !ENV['I3SOCK'].nil?
154
+ ENV['I3SOCK']
155
+ else
156
+ cmd = if system('i3 --version')
157
+ 'i3'
158
+ elsif system('sway --version')
159
+ 'sway'
160
+ else
161
+ raise 'Unable to find i3 compatible window manager'
162
+ end
163
+
164
+ path = `#{cmd} --get-socketpath`.chomp!
165
+ raise 'Unable to get i3 compatible socketpath' unless path
166
+ path
167
+ end
156
168
  end
157
169
 
158
170
  def check_connected
data/lib/i3ipc/reply.rb CHANGED
@@ -45,7 +45,7 @@ module I3Ipc
45
45
  parse_data JSON.parse(response)
46
46
  end
47
47
 
48
- # Indicates whether this reply success or not.
48
+ # Indicates whether this reply is successful or not.
49
49
  #
50
50
  # @return false if this reply represents and error from i3-ipc protocol.
51
51
  # Otherwise returns true, which means that request is successful and
data/lib/i3ipc/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module I3ipc
2
- VERSION = "0.2.0"
2
+ VERSION = "0.4.0"
3
3
  end
@@ -3,43 +3,81 @@ require 'spec_helper'
3
3
  module I3Ipc
4
4
  describe Connection do
5
5
 
6
+ let(:protocol) { Protocol.new '' }
7
+ let(:stub_protocol) do
8
+ allow(protocol).to receive(:send)
9
+ allow(protocol).to receive(:receive)
10
+ end
11
+ subject { Connection.new protocol, false }
12
+
6
13
  describe '#command' do
14
+ it 'returns i3ipc reply' do
15
+ stub_protocol.and_return('{}')
16
+ expect(subject.command('cmd')).to be_a Reply
17
+ end
7
18
 
8
- before(:all) do
9
- class Connection
10
- def initialize
11
- @protocol = Protocol.new ''
12
- end
13
- end
19
+ it 'sends correct command and receives success response' do
20
+ stub_protocol.and_return({ success: true }.to_json)
21
+ expect(subject.command('focus left').success?).to be true
14
22
  end
15
23
 
16
- it 'returns Reply object' do
17
- allow_any_instance_of(Protocol).to receive(:send)
18
- allow_any_instance_of(Protocol).to receive(:receive)
19
- .and_return("{}")
24
+ it 'sends incorrect command and receives error response' do
25
+ stub_protocol.and_return({ success: false, error: 'wrong command' }.to_json)
26
+ reply = subject.command('my command')
27
+ expect(reply.success).to be false
28
+ expect(reply.error).to eql 'wrong command'
29
+ end
30
+ end
20
31
 
21
- expect(Connection.new.command('cmd')).to be_a Reply
32
+ describe '#workspaces' do
33
+ it 'returns i3ipc reply' do
34
+ stub_protocol.and_return('{}')
35
+ expect(subject.workspaces).to be_a Reply
22
36
  end
37
+ end
23
38
 
24
- it 'sends correct command and receives success response' do
25
- allow_any_instance_of(Protocol).to receive(:send)
26
- allow_any_instance_of(Protocol).to receive(:receive)
27
- .and_return(%Q[{"success": true}])
39
+ describe '#outputs' do
40
+ it 'returns i3ipc reply' do
41
+ stub_protocol.and_return('{}')
42
+ expect(subject.outputs).to be_a Reply
43
+ end
44
+ end
28
45
 
29
- connection = Connection.new
30
- reply = connection.command('focus left')
31
- expect(reply.success).to be true
46
+ describe '#tree' do
47
+ it 'returns i3ipc reply' do
48
+ stub_protocol.and_return('{}')
49
+ expect(subject.tree).to be_a Reply
32
50
  end
51
+ end
33
52
 
34
- it 'sends incorrect command and receives error response' do
35
- allow_any_instance_of(Protocol).to receive(:send)
36
- allow_any_instance_of(Protocol).to receive(:receive)
37
- .and_return(%Q[{"success": false, "error": "wrong command"}])
53
+ describe '#marks' do
54
+ it 'returns i3ipc reply' do
55
+ stub_protocol.and_return('{}')
56
+ expect(subject.marks).to be_a Reply
57
+ end
58
+ end
38
59
 
39
- connection = Connection.new
40
- reply = connection.command('my command')
41
- expect(reply.success).to be false
42
- expect(reply.error).to eql 'wrong command'
60
+ describe '#bar_config' do
61
+ it 'returns i3ipc reply' do
62
+ stub_protocol.and_return('{}')
63
+ expect(subject.bar_config).to be_a Reply
64
+ end
65
+ end
66
+
67
+ describe '#version' do
68
+ it 'returns i3ipc reply' do
69
+ stub_protocol.and_return('{}')
70
+ expect(subject.version).to be_a Reply
71
+ end
72
+
73
+ it 'able to parse version attributes' do
74
+ resp = { human_readable: '4.2', minor: 2, patch: 0, major: 4 }
75
+ stub_protocol.and_return(resp.to_json)
76
+ reply = subject.version
77
+ expect(reply.human_readable).to eq resp[:human_readable]
78
+ expect(reply.minor).to eq resp[:minor]
79
+ expect(reply.patch).to eq resp[:patch]
80
+ expect(reply.major).to eq resp[:major]
43
81
  end
44
82
  end
45
83
  end
@@ -87,7 +87,7 @@ module I3Ipc
87
87
 
88
88
  it 'throws error if not connected' do
89
89
  subject.disconnect
90
- expect { subject.send(type) }.to raise_error
90
+ expect { subject.send(type) }.to raise_error Protocol::NotConnected
91
91
  end
92
92
  end
93
93
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: i3ipc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vitalii Elengaupt
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-09 00:00:00.000000000 Z
11
+ date: 2023-06-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -64,9 +64,11 @@ extensions: []
64
64
  extra_rdoc_files: []
65
65
  files:
66
66
  - ".gitignore"
67
+ - ".rspec"
67
68
  - ".travis.yml"
68
69
  - ".yardopts"
69
70
  - Gemfile
71
+ - Guardfile
70
72
  - LICENSE.txt
71
73
  - README.md
72
74
  - Rakefile
@@ -85,7 +87,7 @@ homepage: https://github.com/veelenga/i3ipc-ruby
85
87
  licenses:
86
88
  - MIT
87
89
  metadata: {}
88
- post_install_message:
90
+ post_install_message:
89
91
  rdoc_options: []
90
92
  require_paths:
91
93
  - lib
@@ -100,9 +102,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
100
102
  - !ruby/object:Gem::Version
101
103
  version: '0'
102
104
  requirements: []
103
- rubyforge_project:
104
- rubygems_version: 2.4.8
105
- signing_key:
105
+ rubygems_version: 3.2.32
106
+ signing_key:
106
107
  specification_version: 4
107
108
  summary: Interprocess communication with i3 wm
108
109
  test_files:
@@ -111,4 +112,3 @@ test_files:
111
112
  - spec/i3ipc/protocol_spec.rb
112
113
  - spec/i3ipc/reply_spec.rb
113
114
  - spec/spec_helper.rb
114
- has_rdoc: