nobrainer_streams 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +49 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +41 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/nobrainer_streams.rb +72 -0
- data/lib/nobrainer_streams/rethinkdb_monkeypatch.rb +312 -0
- data/lib/nobrainer_streams/version.rb +3 -0
- data/nobrainer_streams.gemspec +26 -0
- metadata +114 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 125a83bd937986bdaa5a9c293e5117058f2a0a10
|
4
|
+
data.tar.gz: a2b4a215c810d771e40a17812ec15a956d17d43d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c5fe359a10db56bf735f70f8ad1fe7bab419636c7f7c4cc5d16d89911ad471ba2efc9f8b1ffdff8c4dd414b8f1664b9d653d43a0547a14b9c85a3566ea44c258
|
7
|
+
data.tar.gz: 6d946363a70775ee105a647089a126b844ff0528e28ce9b6ee99642f9192304ae8f2825f1a239f00dd3fb33e8f6ce4b23c753641027e932d32639bf23acedfc6
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, and in the interest of
|
4
|
+
fostering an open and welcoming community, we pledge to respect all people who
|
5
|
+
contribute through reporting issues, posting feature requests, updating
|
6
|
+
documentation, submitting pull requests or patches, and other activities.
|
7
|
+
|
8
|
+
We are committed to making participation in this project a harassment-free
|
9
|
+
experience for everyone, regardless of level of experience, gender, gender
|
10
|
+
identity and expression, sexual orientation, disability, personal appearance,
|
11
|
+
body size, race, ethnicity, age, religion, or nationality.
|
12
|
+
|
13
|
+
Examples of unacceptable behavior by participants include:
|
14
|
+
|
15
|
+
* The use of sexualized language or imagery
|
16
|
+
* Personal attacks
|
17
|
+
* Trolling or insulting/derogatory comments
|
18
|
+
* Public or private harassment
|
19
|
+
* Publishing other's private information, such as physical or electronic
|
20
|
+
addresses, without explicit permission
|
21
|
+
* Other unethical or unprofessional conduct
|
22
|
+
|
23
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
24
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
25
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
26
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
27
|
+
threatening, offensive, or harmful.
|
28
|
+
|
29
|
+
By adopting this Code of Conduct, project maintainers commit themselves to
|
30
|
+
fairly and consistently applying these principles to every aspect of managing
|
31
|
+
this project. Project maintainers who do not follow or enforce the Code of
|
32
|
+
Conduct may be permanently removed from the project team.
|
33
|
+
|
34
|
+
This code of conduct applies both within project spaces and in public spaces
|
35
|
+
when an individual is representing the project or its community.
|
36
|
+
|
37
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
38
|
+
reported by contacting a project maintainer at mail@tinco.nl. All
|
39
|
+
complaints will be reviewed and investigated and will result in a response that
|
40
|
+
is deemed necessary and appropriate to the circumstances. Maintainers are
|
41
|
+
obligated to maintain confidentiality with regard to the reporter of an
|
42
|
+
incident.
|
43
|
+
|
44
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
45
|
+
version 1.3.0, available at
|
46
|
+
[http://contributor-covenant.org/version/1/3/0/][version]
|
47
|
+
|
48
|
+
[homepage]: http://contributor-covenant.org
|
49
|
+
[version]: http://contributor-covenant.org/version/1/3/0/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Tinco Andringa
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# NobrainerStreams
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/nobrainer_streams`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'nobrainer_streams'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install nobrainer_streams
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/nobrainer_streams. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
36
|
+
|
37
|
+
|
38
|
+
## License
|
39
|
+
|
40
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
41
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "nobrainer_streams"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
require "nobrainer_streams/version"
|
2
|
+
require "nobrainer_streams/rethinkdb_monkeypatch"
|
3
|
+
|
4
|
+
module NoBrainer::Streams
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
included do
|
8
|
+
on_unsubscribe :stop_all_streams
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def stream_from(query, options = {}, callback = nil)
|
14
|
+
if query.respond_to? :to_rql
|
15
|
+
nobrainer_stream_from(query, options, callback)
|
16
|
+
else
|
17
|
+
super(query, options, callback)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def stop_all_streams
|
22
|
+
nobrainer_stop_all_streams
|
23
|
+
super
|
24
|
+
end
|
25
|
+
|
26
|
+
def nobrainer_stream_from(query, options = {}, callback = nil)
|
27
|
+
callback ||= -> (changes) do
|
28
|
+
transmit changes, via: "streamed from #{query.inspect}"
|
29
|
+
end
|
30
|
+
|
31
|
+
# defer_subscription_confirmation!
|
32
|
+
connection = NoBrainer::Streams::streams_connection
|
33
|
+
cursor = query.to_rql.changes(options).async_run(connection, ConcurrentAsyncHandler, &callback)
|
34
|
+
nobrainer_cursors << cursor
|
35
|
+
end
|
36
|
+
|
37
|
+
def nobrainer_stop_all_streams
|
38
|
+
nobrainer_cursors.each do |cursor|
|
39
|
+
begin
|
40
|
+
logger.info "Closing cursor: #{cursor.inspect}"
|
41
|
+
cursor.close
|
42
|
+
rescue => e
|
43
|
+
logger.error "Could not close cursor: #{e.message}\n#{e.backtrace.join("\n")}"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def nobrainer_cursors
|
49
|
+
@_nobrainer_cursors ||= []
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.streams_connection
|
53
|
+
@@streams_connection ||= NoBrainer::ConnectionManager.get_new_connection.raw
|
54
|
+
end
|
55
|
+
|
56
|
+
class ConcurrentAsyncHandler < RethinkDB::AsyncHandler
|
57
|
+
def run(&action)
|
58
|
+
options[:query_handle_class] = AsyncQueryHandler
|
59
|
+
yield
|
60
|
+
end
|
61
|
+
|
62
|
+
def handler
|
63
|
+
callback
|
64
|
+
end
|
65
|
+
|
66
|
+
class AsyncQueryHandler < RethinkDB::QueryHandle
|
67
|
+
def guarded_async_run(&b)
|
68
|
+
Concurrent.global_io_executor.post(&b)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,312 @@
|
|
1
|
+
require 'rethinkdb'
|
2
|
+
|
3
|
+
module RethinkDB
|
4
|
+
# Extend this class to define a new way of running rethinkdb queries
|
5
|
+
# asynchronously
|
6
|
+
class AsyncHandler
|
7
|
+
# The callback is set to be the user defined callback by the #async_run method
|
8
|
+
attr_accessor :callback
|
9
|
+
attr_accessor :connection
|
10
|
+
attr_accessor :options
|
11
|
+
|
12
|
+
# This method is called with a block that runs a rethinkdb connection
|
13
|
+
# synchronously
|
14
|
+
def run(&action)
|
15
|
+
raise "Must override AsyncHandler#run"
|
16
|
+
end
|
17
|
+
|
18
|
+
# This method should return a handler that will deal with incoming messages
|
19
|
+
def handler
|
20
|
+
raise "Must override AsyncHandler#handler"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# AsyncHandler that uses EventMachine to dispatch events
|
25
|
+
class EMHandler < AsyncHandler
|
26
|
+
def run
|
27
|
+
if !EM.reactor_running?
|
28
|
+
raise RuntimeError, "RethinkDB::RQL::em_run can only be called inside `EM.run`"
|
29
|
+
end
|
30
|
+
|
31
|
+
EM_Guard.register(connection)
|
32
|
+
options[:query_handle_class] = EMQueryHandle
|
33
|
+
yield
|
34
|
+
end
|
35
|
+
|
36
|
+
def handler
|
37
|
+
callback
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
class QueryHandle
|
42
|
+
# Override this method with an async dispatch, making sure that
|
43
|
+
# when the block is run @closed == false
|
44
|
+
def guarded_async_run(&b)
|
45
|
+
raise "Must override QueryHandle#guarded_async_run"
|
46
|
+
end
|
47
|
+
|
48
|
+
def callback(res)
|
49
|
+
begin
|
50
|
+
if @handler.stopped?
|
51
|
+
@closed = true
|
52
|
+
@conn.stop(@token)
|
53
|
+
return
|
54
|
+
elsif res
|
55
|
+
is_cfeed = (res['n'] & [Response::ResponseNote::SEQUENCE_FEED,
|
56
|
+
Response::ResponseNote::ATOM_FEED,
|
57
|
+
Response::ResponseNote::ORDER_BY_LIMIT_FEED,
|
58
|
+
Response::ResponseNote::UNIONED_FEED]) != []
|
59
|
+
|
60
|
+
case res['t']
|
61
|
+
when Response::ResponseType::SUCCESS_PARTIAL,
|
62
|
+
Response::ResponseType::SUCCESS_SEQUENCE
|
63
|
+
guarded_async_run do
|
64
|
+
handle_open
|
65
|
+
if res['t'] == Response::ResponseType::SUCCESS_PARTIAL
|
66
|
+
@conn.register_query(@token, @all_opts, self) if !@conn.closed?
|
67
|
+
@conn.dispatch([Query::QueryType::CONTINUE], @token) if !@conn.closed?
|
68
|
+
end
|
69
|
+
Shim.response_to_native(res, @msg, @all_opts).each do |row|
|
70
|
+
if is_cfeed
|
71
|
+
if (row.has_key?('new_val') && row.has_key?('old_val') &&
|
72
|
+
@handler.respond_to?(:on_change))
|
73
|
+
handle(:on_change, row['old_val'], row['new_val'])
|
74
|
+
elsif (row.has_key?('new_val') && !row.has_key?('old_val') &&
|
75
|
+
@handler.respond_to?(:on_initial_val))
|
76
|
+
handle(:on_initial_val, row['new_val'])
|
77
|
+
elsif (row.has_key?('old_val') && !row.has_key?('new_val') &&
|
78
|
+
@handler.respond_to?(:on_uninitial_val))
|
79
|
+
handle(:on_uninitial_val, row['old_val'])
|
80
|
+
elsif row.has_key?('error') && @handler.respond_to?(:on_change_error)
|
81
|
+
handle(:on_change_error, row['error'])
|
82
|
+
elsif row.has_key?('state') && @handler.respond_to?(:on_state)
|
83
|
+
handle(:on_state, row['state'])
|
84
|
+
else
|
85
|
+
handle(:on_unhandled_change, row)
|
86
|
+
end
|
87
|
+
else
|
88
|
+
handle(:on_stream_val, row)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
if res['t'] == Response::ResponseType::SUCCESS_SEQUENCE ||
|
92
|
+
@conn.closed?
|
93
|
+
handle_close
|
94
|
+
end
|
95
|
+
end
|
96
|
+
when Response::ResponseType::SUCCESS_ATOM
|
97
|
+
guarded_async_run do
|
98
|
+
return if @closed
|
99
|
+
handle_open
|
100
|
+
val = Shim.response_to_native(res, @msg, @all_opts)
|
101
|
+
if val.is_a?(Array)
|
102
|
+
handle(:on_array, val)
|
103
|
+
else
|
104
|
+
handle(:on_atom, val)
|
105
|
+
end
|
106
|
+
handle_close
|
107
|
+
end
|
108
|
+
when Response::ResponseType::WAIT_COMPLETE
|
109
|
+
guarded_async_run do
|
110
|
+
return if @closed
|
111
|
+
handle_open
|
112
|
+
handle(:on_wait_complete)
|
113
|
+
handle_close
|
114
|
+
end
|
115
|
+
else
|
116
|
+
exc = nil
|
117
|
+
begin
|
118
|
+
exc = Shim.response_to_native(res, @msg, @all_opts)
|
119
|
+
rescue Exception => e
|
120
|
+
exc = e
|
121
|
+
end
|
122
|
+
guarded_async_run do
|
123
|
+
return if @closed
|
124
|
+
handle_open
|
125
|
+
handle(:on_error, e)
|
126
|
+
handle_close
|
127
|
+
end
|
128
|
+
end
|
129
|
+
else
|
130
|
+
guarded_async_run {
|
131
|
+
return if @closed
|
132
|
+
handle_close
|
133
|
+
}
|
134
|
+
end
|
135
|
+
rescue Exception => e
|
136
|
+
guarded_async_run do
|
137
|
+
return if @closed
|
138
|
+
handle_open
|
139
|
+
handle(:on_error, e)
|
140
|
+
handle_close
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
class EMQueryHandle < QueryHandle
|
147
|
+
def guarded_async_run(&b)
|
148
|
+
EM.next_tick {
|
149
|
+
b.call if !@closed
|
150
|
+
}
|
151
|
+
end
|
152
|
+
|
153
|
+
def callback(res)
|
154
|
+
if !EM.reactor_running?
|
155
|
+
@closed = true
|
156
|
+
@conn.stop(@token)
|
157
|
+
return
|
158
|
+
end
|
159
|
+
super(res)
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
class RQL
|
164
|
+
def parse(*args, &b)
|
165
|
+
conn = nil
|
166
|
+
opts = nil
|
167
|
+
block = nil
|
168
|
+
async_handler = nil
|
169
|
+
args = args.map{|x| x.is_a?(Class) ? x.new : x}
|
170
|
+
args.each {|arg|
|
171
|
+
case arg
|
172
|
+
when RethinkDB::Connection
|
173
|
+
raise ArgumentError, "Unexpected second Connection #{arg.inspect}." if conn
|
174
|
+
conn = arg
|
175
|
+
when Hash
|
176
|
+
raise ArgumentError, "Unexpected second Hash #{arg.inspect}." if opts
|
177
|
+
opts = arg
|
178
|
+
when Proc
|
179
|
+
raise ArgumentError, "Unexpected second callback #{arg.inspect}." if block
|
180
|
+
block = arg
|
181
|
+
when Handler
|
182
|
+
raise ArgumentError, "Unexpected second callback #{arg.inspect}." if block
|
183
|
+
block = arg
|
184
|
+
when AsyncHandler
|
185
|
+
raise ArgumentError, "Unexpected second AsyncHandler #{arg.inspect}." if async_handler
|
186
|
+
async_handler = arg
|
187
|
+
else
|
188
|
+
raise ArgumentError, "Unexpected argument #{arg.inspect} " +
|
189
|
+
"(got #{args.inspect})."
|
190
|
+
end
|
191
|
+
}
|
192
|
+
conn = @@default_conn if !conn
|
193
|
+
opts = {} if !opts
|
194
|
+
block = b if !block
|
195
|
+
if (tf = opts[:time_format])
|
196
|
+
opts[:time_format] = (tf = tf.to_s)
|
197
|
+
if tf != 'raw' && tf != 'native'
|
198
|
+
raise ArgumentError, "`time_format` must be 'raw' or 'native' (got `#{tf}`)."
|
199
|
+
end
|
200
|
+
end
|
201
|
+
if (gf = opts[:group_format])
|
202
|
+
opts[:group_format] = (gf = gf.to_s)
|
203
|
+
if gf != 'raw' && gf != 'native'
|
204
|
+
raise ArgumentError, "`group_format` must be 'raw' or 'native' (got `#{gf}`)."
|
205
|
+
end
|
206
|
+
end
|
207
|
+
if (bf = opts[:binary_format])
|
208
|
+
opts[:binary_format] = (bf = bf.to_s)
|
209
|
+
if bf != 'raw' && bf != 'native'
|
210
|
+
raise ArgumentError, "`binary_format` must be 'raw' or 'native' (got `#{bf}`)."
|
211
|
+
end
|
212
|
+
end
|
213
|
+
if !conn
|
214
|
+
raise ArgumentError, "No connection specified!\n" \
|
215
|
+
"Use `query.run(conn)` or `conn.repl(); query.run`."
|
216
|
+
end
|
217
|
+
{conn: conn, opts: opts, block: block, async_handler: async_handler}
|
218
|
+
end
|
219
|
+
|
220
|
+
def em_run(*args, &b)
|
221
|
+
async_run(*args, EMHandler, &b)
|
222
|
+
end
|
223
|
+
|
224
|
+
def async_run(*args, &b)
|
225
|
+
unbound_if(@body == RQL)
|
226
|
+
args = parse(*args, &b)
|
227
|
+
if args[:block].is_a?(Proc)
|
228
|
+
args[:block] = CallbackHandler.new(args[:block])
|
229
|
+
end
|
230
|
+
if !args[:block].is_a?(Handler)
|
231
|
+
raise ArgumentError, "No handler specified."
|
232
|
+
end
|
233
|
+
|
234
|
+
async_handler = args[:async_handler]
|
235
|
+
if !async_handler.is_a?(AsyncHandler)
|
236
|
+
raise ArgumentError, "No async handler specified."
|
237
|
+
end
|
238
|
+
|
239
|
+
# If the user has defined the `on_state` method, we assume they want states.
|
240
|
+
if args[:block].respond_to?(:on_state)
|
241
|
+
args[:opts] = args[:opts].merge(include_states: true)
|
242
|
+
end
|
243
|
+
|
244
|
+
async_handler.callback = args[:block]
|
245
|
+
async_handler.connection = args[:conn]
|
246
|
+
async_handler.options = args[:opts]
|
247
|
+
|
248
|
+
async_handler.run do
|
249
|
+
async_handler.connection.run(@body, async_handler.options, async_handler.handler)
|
250
|
+
end
|
251
|
+
end
|
252
|
+
end
|
253
|
+
|
254
|
+
class Connection
|
255
|
+
def run(msg, opts, b)
|
256
|
+
query_handle_class = opts.delete(:query_handle_class) || QueryHandle
|
257
|
+
reconnect(:noreply_wait => false) if @auto_reconnect && !is_open()
|
258
|
+
raise ReqlRuntimeError, "Connection is closed." if !is_open()
|
259
|
+
|
260
|
+
global_optargs = {}
|
261
|
+
all_opts = @default_opts.merge(opts)
|
262
|
+
if all_opts.keys.include?(:noreply)
|
263
|
+
all_opts[:noreply] = !!all_opts[:noreply]
|
264
|
+
end
|
265
|
+
|
266
|
+
token = new_token
|
267
|
+
q = [Query::QueryType::START,
|
268
|
+
msg,
|
269
|
+
Hash[all_opts.map {|k,v|
|
270
|
+
[k.to_s, (v.is_a?(RQL) ? v.to_pb : RQL.new.expr(v).to_pb)]
|
271
|
+
}]]
|
272
|
+
|
273
|
+
if b.is_a? Handler
|
274
|
+
callback = query_handle_class.new(b, msg, all_opts, token, self)
|
275
|
+
register_query(token, all_opts, callback)
|
276
|
+
dispatch(q, token)
|
277
|
+
return callback
|
278
|
+
else
|
279
|
+
res = run_internal(q, all_opts, token)
|
280
|
+
return res if !res
|
281
|
+
if res['t'] == Response::ResponseType::SUCCESS_PARTIAL
|
282
|
+
value = Cursor.new(Shim.response_to_native(res, msg, opts),
|
283
|
+
msg, self, opts, token, true)
|
284
|
+
elsif res['t'] == Response::ResponseType::SUCCESS_SEQUENCE
|
285
|
+
value = Cursor.new(Shim.response_to_native(res, msg, opts),
|
286
|
+
msg, self, opts, token, false)
|
287
|
+
else
|
288
|
+
value = Shim.response_to_native(res, msg, opts)
|
289
|
+
end
|
290
|
+
|
291
|
+
if res['p']
|
292
|
+
real_val = {
|
293
|
+
"profile" => res['p'],
|
294
|
+
"value" => value
|
295
|
+
}
|
296
|
+
else
|
297
|
+
real_val = value
|
298
|
+
end
|
299
|
+
|
300
|
+
if b
|
301
|
+
begin
|
302
|
+
b.call(real_val)
|
303
|
+
ensure
|
304
|
+
value.close if value.is_a?(Cursor)
|
305
|
+
end
|
306
|
+
else
|
307
|
+
real_val
|
308
|
+
end
|
309
|
+
end
|
310
|
+
end
|
311
|
+
end
|
312
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'nobrainer_streams/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "nobrainer_streams"
|
8
|
+
spec.version = NobrainerStreams::VERSION
|
9
|
+
spec.authors = ["Tinco Andringa"]
|
10
|
+
spec.email = ["tinco@phusion.nl"]
|
11
|
+
|
12
|
+
spec.summary = %q{Temporary gem to add streams support to NoBrainer.}
|
13
|
+
spec.homepage = "https://github.com/phusion/nobrainer_streams"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
spec.bindir = "exe"
|
18
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.12"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
24
|
+
|
25
|
+
spec.add_dependency "rethinkdb", "~> 2.3"
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: nobrainer_streams
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tinco Andringa
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-07-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.12'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.12'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rethinkdb
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2.3'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '2.3'
|
69
|
+
description:
|
70
|
+
email:
|
71
|
+
- tinco@phusion.nl
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".rspec"
|
78
|
+
- ".travis.yml"
|
79
|
+
- CODE_OF_CONDUCT.md
|
80
|
+
- Gemfile
|
81
|
+
- LICENSE.txt
|
82
|
+
- README.md
|
83
|
+
- Rakefile
|
84
|
+
- bin/console
|
85
|
+
- bin/setup
|
86
|
+
- lib/nobrainer_streams.rb
|
87
|
+
- lib/nobrainer_streams/rethinkdb_monkeypatch.rb
|
88
|
+
- lib/nobrainer_streams/version.rb
|
89
|
+
- nobrainer_streams.gemspec
|
90
|
+
homepage: https://github.com/phusion/nobrainer_streams
|
91
|
+
licenses:
|
92
|
+
- MIT
|
93
|
+
metadata: {}
|
94
|
+
post_install_message:
|
95
|
+
rdoc_options: []
|
96
|
+
require_paths:
|
97
|
+
- lib
|
98
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- - ">="
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
108
|
+
requirements: []
|
109
|
+
rubyforge_project:
|
110
|
+
rubygems_version: 2.5.1
|
111
|
+
signing_key:
|
112
|
+
specification_version: 4
|
113
|
+
summary: Temporary gem to add streams support to NoBrainer.
|
114
|
+
test_files: []
|