celluloid-io-pg-listener 0.2.0 → 0.2.1

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: 6b32bda94c9d7c0caa12e0eb1ffe874e2e71fff0
4
- data.tar.gz: b81a26d47347897cb829fd411fc672991d2cfec7
3
+ metadata.gz: 20bb2e2002bda41c462c15c5ab299defb1b63758
4
+ data.tar.gz: 30afe775d53c72343dcc331dec3059b0592fb6be
5
5
  SHA512:
6
- metadata.gz: 3af82bdda3b7154ddf349813da7bffb2a355aebe42cb22f05c57404db242c6557c13e177b05e30337bae2bc459d2eb970aecf82be3bd18476f0ffcb8e87f5700
7
- data.tar.gz: ea6c3423da0866304ad84cba117f31ff82a1d4aa5a7e104bb9fbd091f738ad8b5ff418ab483a5eff58a7b76de718981d23a650172b35cb3fd50e06504574f8c3
6
+ metadata.gz: c83597eb06762c5a0f0b56a4e0565cb6892e82a8f73723972c7994b59c7164057106434b12a0d4cbf4257c831701c339ec739a92fe7dd37411718b686d665055
7
+ data.tar.gz: cf1fd392c57d3d48de25797a3b22e4fe0e9e2645a0261484f97d319758980db100908c6c2d86f0330a86200346a30c20572b3b5dd279945826e71e6c3fe97709
data/.codeclimate.yml ADDED
@@ -0,0 +1,11 @@
1
+ engines:
2
+ rubocop:
3
+ enabled: true
4
+ bundler-audit:
5
+ enabled: false
6
+ ratings:
7
+ paths:
8
+ - "**.rb"
9
+ - Gemfile.lock
10
+ exclude_paths:
11
+ - spec/**/*
data/.gitignore CHANGED
@@ -9,3 +9,4 @@
9
9
  /tmp/
10
10
  .ruby-gemset
11
11
  .ruby-version
12
+ /spec/apps/log
data/.travis.yml CHANGED
@@ -10,3 +10,5 @@ script: "bundle exec rspec spec"
10
10
  gemfile:
11
11
  - gemfiles/rails_4.2.4.gemfile
12
12
  - gemfiles/rails_3.2.22.gemfile
13
+ addons:
14
+ postgresql: "9.4" # json_build_object was introduced in 9.4
data/README.md CHANGED
@@ -2,9 +2,8 @@
2
2
 
3
3
  Simple way to NOTIFY and LISTEN to channels in PostgreSQL
4
4
 
5
- The goal is to integrate the listener client with a Rails project, and that is underway in the spec/ folder, but as yet unfinished. Standalone the listener client works great.
6
-
7
- Inspired by https://gist.github.com/tpitale/3915671
5
+ Standalone the listener client works great in an `irb` session.
6
+ Real-world, practical, use requires a long running process, and for an example of that see [bin/supervisor](https://github.com/pboling/celluloid-io-pg-listener/blob/master/bin/supervisor)
8
7
 
9
8
  | Project | Celluloid IO PG Listener |
10
9
  |------------------------ | ----------------- |
@@ -22,6 +21,19 @@ Inspired by https://gist.github.com/tpitale/3915671
22
21
  | author | [Peter Boling](https://coderbits.com/pboling) |
23
22
  | Spread ~♡ⓛⓞⓥⓔ♡~ | [![Endorse Me](https://api.coderwall.com/pboling/endorsecount.png)](http://coderwall.com/pboling) |
24
23
 
24
+ ## Prerequisites
25
+
26
+ Compatible with Ruby 2.1+, and tested on Travis. Might also be compatible with Ruby 2.0, but haven't had time or inclination to find out. That's why we have a fork button!
27
+
28
+ Requires Celluloid greater than 0.17.2 because that release fixed an important memory leak in Celluloid.
29
+ ```
30
+ gem "celluloid", ">= 0.17.2"
31
+ ```
32
+
33
+ Currently requires pg gem v0.18.3 or greater, but really that's only because I haven't had time to test with older versions. Feel free to do that and send a PR.
34
+ ```
35
+ gem "pg", ">= 0.18.3"
36
+ ```
25
37
 
26
38
  ## Installation
27
39
 
@@ -166,6 +178,14 @@ module CelluloidIOPGListener
166
178
  end
167
179
  ```
168
180
 
181
+ ## Credits
182
+
183
+ Written by Peter Boling for [Trumaker & Co](https://www.trumaker.com/)
184
+
185
+ Inspired by:
186
+ * https://gist.github.com/tpitale/3915671
187
+ * https://blog.andyet.com/2015/04/06/postgres-pubsub-with-json
188
+
169
189
  ## Development
170
190
 
171
191
  After checking out the repo, run `bin/setup` to install dependencies, and setup the test environment, including creating a role and a database. Then, run `appraisal rake` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -217,7 +237,7 @@ dependency on this gem using the [Pessimistic Version Constraint][pvc] with two
217
237
  For example:
218
238
 
219
239
  ```ruby
220
- spec.add_dependency 'celluloid-io-pg-listener', '~> 0.1'
240
+ spec.add_dependency 'celluloid-io-pg-listener', '~> 0.2'
221
241
  ```
222
242
 
223
243
  ## License
data/bin/setup CHANGED
@@ -14,6 +14,7 @@ fi
14
14
  psql -f bin/setup.sql -U $puser
15
15
  echo "Setup Role foss"
16
16
  psql -U $puser << EOF
17
+ DROP DATABASE IF EXISTS celluloid_io_pg_listener_test;
17
18
  CREATE DATABASE celluloid_io_pg_listener_test;
18
19
  ALTER DATABASE celluloid_io_pg_listener_test OWNER TO "foss";
19
20
  EOF
@@ -10,7 +10,7 @@ require "celluloid-io-pg-listener/initialization/client_extracted_signature"
10
10
  require "celluloid-io-pg-listener/initialization/argument_extraction"
11
11
  require "celluloid-io-pg-listener/initialization/async_listener"
12
12
  require "celluloid-io-pg-listener/client"
13
- # Require manually, if you want to try them out.
13
+ # Require manually, as in bin/console, if you want to try them out.
14
14
  # require "celluloid-io-pg-listener/examples/client"
15
15
  # require "celluloid-io-pg-listener/examples/server"
16
16
  # require "celluloid-io-pg-listener/examples/listener_client_by_inheritance"
@@ -36,13 +36,13 @@ module CelluloidIOPGListener
36
36
  @pg_connection ||= PG.connect(conninfo_hash)
37
37
  end
38
38
 
39
- def notify(channel, value)
40
- pg_connection.exec("NOTIFY #{channel}, '#{value}';")
41
- end
42
-
39
+ # Supported channel names are any delimited (double-quoted) identifier:
40
+ # We supply the double quotes, you supply the contents.
41
+ # If you want unicode character code support submit a pull request to make the quote style `U&"` a config setting.
42
+ # See: http://www.postgresql.org/docs/9.4/static/sql-syntax-lexical.html
43
43
  def listen(channel, action)
44
44
  actions[channel] = action
45
- pg_connection.exec("LISTEN #{channel}")
45
+ pg_connection.exec(%[LISTEN "#{channel}";])
46
46
  end
47
47
 
48
48
  def start_listening
@@ -77,7 +77,7 @@ module CelluloidIOPGListener
77
77
  def unlisten(channel)
78
78
  # (@listening ||= {})[channel] = false
79
79
  stop_listening # Not sure if there is a way to stop listening to a single channel without affecting the others.
80
- pg_connection.exec("UNLISTEN #{channel}")
80
+ pg_connection.exec(%[UNLISTEN "#{channel}";])
81
81
  end
82
82
 
83
83
  end
@@ -42,8 +42,12 @@ module CelluloidIOPGListener
42
42
  @pg_connection ||= PG.connect(conninfo_hash)
43
43
  end
44
44
 
45
+ # Supported channel names are any delimited (double-quoted) identifier:
46
+ # We supply the double quotes, you supply the contents.
47
+ # If you want unicode character code support submit a pull request to make the quote style `U&"` a config setting.
48
+ # See: http://www.postgresql.org/docs/9.4/static/sql-syntax-lexical.html
45
49
  def notify(channel, value)
46
- pg_connection.exec("NOTIFY #{channel}, '#{value}';")
50
+ pg_connection.exec(%[NOTIFY "#{channel}", '#{value}';])
47
51
  end
48
52
 
49
53
  end
@@ -1,7 +1,7 @@
1
1
  module CelluloidIOPGListener
2
2
  # Prepended to classes including the CelluloidIOPGListener::Client
3
- # Takes the arguments relevant to the CelluloidIOPGListener::Client module
4
- # and extracts it leaving the rest of the arguments to be passed to the
3
+ # Extracts the arguments relevant to the CelluloidIOPGListener::Client module
4
+ # Leaves the rest of the arguments to be passed to the
5
5
  # initializer of classes including the CelluloidIOPGListener::Client
6
6
  module Initialization
7
7
  module ArgumentExtraction
@@ -9,11 +9,6 @@ module CelluloidIOPGListener
9
9
  # 1st initialize override invoked
10
10
  def initialize(*args)
11
11
  @client_extracted_signature = CelluloidIOPGListener::Initialization::ClientExtractedSignature.new(*args)
12
- # When called from a sub-class of a class including Client
13
- # and the sub-class overrides initialize,
14
- # then the execution order changes,
15
- # and this method may no longer have a super.
16
- # However, due to the nature of the initialize method we can't tell if we have a legitimate super or not.
17
12
  super(*@client_extracted_signature.super_signature)
18
13
  end
19
14
 
@@ -1,3 +1,3 @@
1
1
  module CelluloidIOPGListener
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: celluloid-io-pg-listener
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Boling
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-10-15 00:00:00.000000000 Z
11
+ date: 2015-10-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: celluloid-io
@@ -172,6 +172,7 @@ executables: []
172
172
  extensions: []
173
173
  extra_rdoc_files: []
174
174
  files:
175
+ - ".codeclimate.yml"
175
176
  - ".gitignore"
176
177
  - ".rspec"
177
178
  - ".travis.yml"
@@ -221,7 +222,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
221
222
  version: '0'
222
223
  requirements: []
223
224
  rubyforge_project:
224
- rubygems_version: 2.4.8
225
+ rubygems_version: 2.4.5.1
225
226
  signing_key:
226
227
  specification_version: 4
227
228
  summary: Asynchronously LISTEN for Postgresql NOTIFY messages with payloads and Do