zchannel 0.2.0 → 0.3.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
2
  SHA1:
3
- metadata.gz: 649b93103c675d5dfa973d8951dc11179815045b
4
- data.tar.gz: 8abcb7c009b2e86e41246daf914442e7eb09a53c
3
+ metadata.gz: 1ddefd25411898f9e157391b0024f2c20dc481f1
4
+ data.tar.gz: 00821b76dbee39af1210d7fe6d09b4eee3c4df46
5
5
  SHA512:
6
- metadata.gz: b66421c435e26cb6ad0f8023becaeac8b70518655401c4f501b80db464f2106a7fda73b9866c1a23507bcf9c0582173fb4d5479b25346fea5a41515389d2dfd2
7
- data.tar.gz: 83171424257774572cc16bddf0093c2ef517dc6b1062f941c7127d2c4016b98b66bfd6779fffa9c579561eef7680ba7493b447cbe7947001097057e6bd766731
6
+ metadata.gz: 16c44b7dd8784fc7313db3136498c1ded8f61c41a5ef2843b63a9ae273e1aa53474f882fc166344131dae445966d0af626e16ff12f1bf46b27f990440654d689
7
+ data.tar.gz: 835f2f8b041dd696880281c50beca1a5c69478da550e28082fd12b34d7ed61c9b88228c9e3396228d62d9b5afcb1a0171beda458bca537384cf551919b797f1e
@@ -1,17 +1,13 @@
1
+ script: ruby -S rake
2
+
1
3
  rvm:
2
- - 1.9.2
3
- - 1.9.3
4
- - 2.0.0
5
- - rbx-19mode
6
- # - ruby-head
4
+ - 2.2
5
+ - ruby-head
7
6
 
8
7
  env:
9
- - REDIS=1 SERIALIZER=YAML
10
- - REDIS=1 SERIALIZER=Marshal
11
- - REDIS=1 SERIALIZER=JSON
12
-
13
- services:
14
- - redis-server
8
+ - SERIALIZER=YAML
9
+ - SERIALIZER=Marshal
10
+ - SERIALIZER=JSON
15
11
 
16
12
  notifications:
17
- email: true
13
+ email: true
data/.yardopts CHANGED
@@ -1,5 +1,3 @@
1
1
  -m markdown -M redcarpet
2
2
  -
3
3
  README.md
4
- LICENSE.txt
5
- ChangeLog.txt
data/Gemfile CHANGED
@@ -1,3 +1,7 @@
1
1
  source 'http://rubygems.org'
2
2
  gemspec
3
3
  gem "test-unit"
4
+ group :docs do
5
+ gem "yard"
6
+ gem "redcarpet"
7
+ end
data/README.md CHANGED
@@ -1,12 +1,15 @@
1
+ [![Build Status](https://travis-ci.org/jazzonmymind/zchannel.rb.svg?branch=master)](https://travis-ci.org/jazzonmymind/zchannel.rb)
2
+ [![Code Climate](https://codeclimate.com/github/jazzonmymind/zchannel.rb/badges/gpa.svg)](https://codeclimate.com/github/jazzonmymind/zchannel.rb)
3
+
1
4
  __zchannel__
2
5
 
3
6
  zchannel is a library that assists with InterProcess Communication, or
4
7
  IPC for short. It provides a high level and easy to use API for sending
5
- Ruby objects between processes that are running on the same machine.
6
- A channel is implemented on top of an unbound UNIXSocket, and objects
7
- are serialized with a serializer of your choosing although the examples
8
- use the "Marshal" serializer, which is available without any extra
9
- dependencies.
8
+ Ruby objects between processes that are running on the same machine and
9
+ who have a parent-child relationship. A channel is implemented on top of an
10
+ unbound UNIXSocket. Objects are serialized on write and deserialized on
11
+ read using a serializer of your choice. The examples use the "Marshal"
12
+ serializer, which is available without any extra dependencies.
10
13
 
11
14
  __Examples__
12
15
 
@@ -1,10 +1,10 @@
1
1
  require 'socket'
2
2
  class ZChannel::UNIXSocket
3
- SEP = '_$_' if respond_to? :private_constant
3
+ SEP = "\x00" if respond_to? :private_constant
4
4
 
5
5
  #
6
6
  # @param [#dump,#load] serializer
7
- # An object who implements `.dump` and `.load` methods
7
+ # Any object that implements "dump" and "load" methods.
8
8
  #
9
9
  # @return [ZChannel::UNIXSocket]
10
10
  #
@@ -16,20 +16,18 @@ class ZChannel::UNIXSocket
16
16
 
17
17
  #
18
18
  # @return [Boolean]
19
- # Returns true when a channel is closed
19
+ # Returns true when a channel is closed.
20
20
  #
21
21
  def closed?
22
22
  @reader.closed? and @writer.closed?
23
23
  end
24
24
 
25
- #
26
- # Close the channel
27
25
  #
28
26
  # @raise [IOError]
29
- # When a channel is already closed
27
+ # Raises IOError when a channel is already closed.
30
28
  #
31
29
  # @return [Boolean]
32
- # Returns true on success
30
+ # Returns true when a channel is closed successfully.
33
31
  #
34
32
  def close
35
33
  if closed?
@@ -41,29 +39,34 @@ class ZChannel::UNIXSocket
41
39
  end
42
40
  end
43
41
 
42
+ #
43
+ # Perform a blocking write.
44
44
  #
45
45
  # @raise [IOError]
46
46
  # (see #send!)
47
47
  #
48
48
  # @param [Object] object
49
- # An object to add to a channel
49
+ # An object to write to a channel.
50
50
  #
51
51
  def send(object)
52
52
  send!(object, nil)
53
53
  end
54
+ alias_method :write, :send
54
55
 
55
56
  #
56
- # @param
57
- # (see ZChannel::UNIXSocket#send)
57
+ # Perform a write with a timeout.
58
+ #
59
+ # @param [Object] object
60
+ # An object to write to a channel.
58
61
  #
59
- # @param [Fixnum] timeout
60
- # Number of seconds to wait before raising an exception
62
+ # @param [Float, Fixnum] timeout
63
+ # The number of seconds to wait before raising an exception.
61
64
  #
62
65
  # @raise [IOError]
63
- # When channel is closed
66
+ # Raises an IOError when a channel is closed.
64
67
  #
65
68
  # @raise [ZChannel::TimeoutError]
66
- # When a write doesn't finish within the timeout
69
+ # Raises a ZChannel::TimeoutError when a write doesn't finish within the specified timeout.
67
70
  #
68
71
  def send!(object, timeout = 0.1)
69
72
  if @writer.closed?
@@ -77,30 +80,32 @@ class ZChannel::UNIXSocket
77
80
  raise ZChannel::TimeoutError, "timeout, waited #{timeout} seconds"
78
81
  end
79
82
  end
83
+ alias_method :write!, :send!
80
84
 
81
85
  #
82
- # Perform a blocking read
86
+ # Perform a blocking read.
83
87
  #
84
88
  # @raise
85
- # (see ZChannel::UNIXSocket#recv)
89
+ # (see ZChannel::UNIXSocket#recv!)
86
90
  #
87
91
  # @return [Object]
88
92
  #
89
93
  def recv
90
94
  recv!(nil)
91
95
  end
96
+ alias_method :read, :recv
92
97
 
93
98
  #
94
- # Perform a read with a timeout
99
+ # Perform a read with a timeout.
95
100
  #
96
- # @param [Fixnum] timeout
97
- # Number of seconds to wait before raising an exception
101
+ # @param [Float, Fixnum] timeout
102
+ # The number of seconds to wait before raising an exception.
98
103
  #
99
104
  # @raise [IOError]
100
- # When channel is closed
105
+ # Raises an IOError when a channel is closed.
101
106
  #
102
107
  # @raise [ZChannel::TimeoutError]
103
- # When a read doesn't finish within the timeout
108
+ # Raises ZChannel::TimeoutError when a read doesn't finish within the specified timeout.
104
109
  #
105
110
  # @return [Object]
106
111
  #
@@ -116,9 +121,12 @@ class ZChannel::UNIXSocket
116
121
  raise ZChannel::TimeoutError, "timeout, waited #{timeout} seconds"
117
122
  end
118
123
  end
124
+ alias_method :read!, :recv!
119
125
 
120
126
  #
121
127
  # @return [Object]
128
+ # Reads from a channel until there are no messages left, and
129
+ # then returns the last read message.
122
130
  #
123
131
  def last_msg
124
132
  @last_msg = recv while readable?
@@ -127,6 +135,7 @@ class ZChannel::UNIXSocket
127
135
 
128
136
  #
129
137
  # @return [Boolean]
138
+ # Returns true when a channel has messages waiting to be read.
130
139
  #
131
140
  def readable?
132
141
  if closed?
@@ -1,3 +1,3 @@
1
1
  module ZChannel
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -1,3 +1,5 @@
1
1
  require 'bundler/setup'
2
2
  require 'test/unit'
3
+ require 'json'
4
+ require 'yaml'
3
5
  Bundler.require :default, :test
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zchannel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - jazzonmymind
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-09 00:00:00.000000000 Z
11
+ date: 2016-08-12 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Provides a high level and easy to use API for sending objects between
14
14
  Ruby processes
@@ -57,4 +57,3 @@ specification_version: 4
57
57
  summary: Provides a high level and easy to use API for sending objects between Ruby
58
58
  processes
59
59
  test_files: []
60
- has_rdoc: