couchdb-ruby-server 1.0.0 → 1.0.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: aa9cbfeea39a79efb59cfa9b1d278ee06ea5451c
4
- data.tar.gz: 1fa6648489a455bc477d446af41b2f84c48eb215
3
+ metadata.gz: 1e9ffed61239c2bb7d32f8eaa6720683c8baee09
4
+ data.tar.gz: d0674c1c0e546777f974fa7d381ce5c5cae13c12
5
5
  SHA512:
6
- metadata.gz: 196f7dd41438a62fe78b9d98c3f6824b04e29639f82fc9994017ad95d3594c8476f01211bdc985405283d1a80c9674f9a443191a8b72afc2ae57a6a8fee287a9
7
- data.tar.gz: 1e4608f3551c2937ce0acc9f2a7f13075e2ccb9b079b3c1935cf7e1537af679053c32649c310aa3393ec442ea5eab0d1777053dba02fa6da703bdf6a67a542b7
6
+ metadata.gz: 360e274df3ae6321d2c091026242796de8d95735a8911b489dd93a039194d101f1e26b79788f09a0eba24263467630a22b00e16991094a148ec0ee69d7eb8022
7
+ data.tar.gz: 1061aeab8a3d3051ba604f1ddb2e8d38b088d2db976131683c77d4094787b247161554051c2e89ab16a2d45b3143dfdfb93f2c83da61cdcab0b9611169e586f4
data/.gitignore CHANGED
@@ -19,3 +19,4 @@ Gemfile.lock
19
19
  core
20
20
  *.gem
21
21
  /doc/
22
+ /ext/Rakefile
data/.travis.yml CHANGED
@@ -5,9 +5,7 @@ rvm:
5
5
  - "2.0.0"
6
6
  - "2.1" # latest 2.1.x
7
7
  - "2.2" # latest 2.2.x
8
- - "jruby-18mode"
9
- - "jruby-19mode"
10
- script:
11
- CODECLIMATE_REPO_TOKEN=PLACE_TOKEN_HERE bundle exec rake test
8
+ script: # use QS_TRACE=1 for the tracing
9
+ CODECLIMATE_REPO_TOKEN=306fa22cbd8a30beb74c4fd7536e659ac9b669147772d9718f0032dcda96e507 bundle exec rake test
12
10
  branches:
13
11
  - "master"
data/README.md CHANGED
@@ -26,7 +26,7 @@ You may load your own code into the query server context by providing path to a
26
26
  Actually any tagname for the query server may be set in `local.ini` instead of `ruby` so it's possible to run several query servers e.g. per application. Just remember to copy that tagname into couchapp's `language` file.
27
27
 
28
28
  ## Tests
29
- `bundle exec rake test`. Gem following original [tests](https://github.com/apache/couchdb/blob/master/test/view_server/query_server_spec.rb).
29
+ `bundle exec rake test`. Gem is trying to follow original [tests](https://github.com/apache/couchdb/blob/master/test/view_server/query_server_spec.rb).
30
30
 
31
31
  ## Documentation
32
32
  This README is all i could say in a rush. No other documentation provided at this moment, see the sources.
data/TODO.md CHANGED
@@ -2,3 +2,4 @@
2
2
 
3
3
  3. Client and server libs -- see what i have to copy here
4
4
  4. Implement $SAFE=4 thread, set safe level via args
5
+ 5. RUBY_GC_MALLOC_LIMIT=24000000
@@ -1,18 +1,22 @@
1
- #!/usr/bin/env RUBY_GC_MALLOC_LIMIT=24000000 ruby
1
+ #!/usr/bin/env ruby
2
2
  require 'couchdb-ruby-server'
3
3
  require 'argparser'
4
4
 
5
- args = ArgParser.new :program => 'couchdb-ruby-server',
6
- :version => CouchdbRubyServer::VERSION,
7
- :info => 'CouchDB query server to run ruby design docs.',
8
- :licence => 'MIT',
9
- :copyright=> '2014-2015 sinmsinm@gmail.com',
10
- :options => [{ :names => %w[r require],
11
- :argument => 'LIB',
12
- :multiple => true,
13
- :help => 'Aux library to require.' }]
14
- args['require'].value.each do |r|
15
- require r
16
- end
5
+ module CouchdbRubyServer
6
+ trace {'+ bin/couchdb-ruby-server'}
7
+ at_exit { trace {'- bin/couchdb-ruby-server' } }
8
+ args = ArgParser.new :program => 'couchdb-ruby-server',
9
+ :version => CouchdbRubyServer::VERSION,
10
+ :info => 'CouchDB query server to run ruby design docs.',
11
+ :licence => 'MIT',
12
+ :copyright=> '2014-2015 sinmsinm@gmail.com',
13
+ :options => [{ :names => %w[r require],
14
+ :argument => 'LIB',
15
+ :multiple => true,
16
+ :help => 'Aux library to require.' }]
17
+ args['require'].value.each do |r|
18
+ require r
19
+ end
17
20
 
18
- CouchdbRubyServer.run
21
+ run
22
+ end
@@ -20,9 +20,9 @@ Gem::Specification.new do |s|
20
20
  # '--main' << 'README' <<
21
21
  # '--markup' << 'markdown' <<
22
22
  # '--line-numbers'
23
- s.add_development_dependency 'bundler', '~> 1'
24
- s.add_development_dependency 'rake', '~> 10'
25
- s.add_development_dependency 'minitest', '~> 4'
26
- s.add_dependency 'argparser', '~> 1'
27
- s.add_dependency 'oj', '~> 2.7'
23
+ s.add_development_dependency 'bundler', '~> 1.7'
24
+ s.add_development_dependency 'rake', '~> 10.1'
25
+ s.add_development_dependency 'minitest', '~> 4.7'
26
+ s.add_dependency 'argparser', '~> 1.0'
27
+ s.add_dependency 'oj', '~> 2.7'
28
28
  end
@@ -0,0 +1,17 @@
1
+ # coding: utf-8
2
+
3
+ module CouchdbRubyServer
4
+ module Serializer
5
+ require 'oj'
6
+ ::Oj.default_options = {:mode => :compat,
7
+ :class_cache => true }
8
+ def self.dump(obj)
9
+ Oj.dump(obj)
10
+ end
11
+
12
+ def self.load(str)
13
+ return nil if str.nil?
14
+ Oj.load(str)
15
+ end
16
+ end
17
+ end
@@ -1,9 +1,5 @@
1
1
  # coding: utf-8
2
2
 
3
-
4
- $stdin.sync = true
5
- $stdout.sync = true
6
-
7
3
  module CouchdbRubyServer
8
4
  class Error < RuntimeError
9
5
  attr_reader :key
@@ -39,23 +35,15 @@ module CouchdbRubyServer
39
35
 
40
36
  TYPES_MIME = Hash[MIME_TYPES.map {|k, v| [v, k] }]
41
37
 
42
- def self.to_json(obj)
43
- Oj.dump(obj)
44
- end
45
-
46
- def self.json_parse(str)
47
- return nil if str.nil?
48
- Oj.load str
49
- end
50
-
51
38
  def self.log message
52
39
  respond ['log', "#{message}"]
53
40
  end
54
41
 
55
42
  def self.respond obj
56
- puts to_json obj
43
+ trace {"+ respond(#{obj.inspect})"}
44
+ puts Serializer.dump(obj)
57
45
  rescue
58
- log "respond error converting object to JSON: #{$!.message}\n#{$!.backtrace.join("\n")}"
46
+ puts('["log", "' + "respond error converting object to JSON: #{$!.message}\n#{$!.backtrace.join("\n")}" + '"]')
59
47
  puts 'false'
60
48
  end
61
49
 
@@ -136,7 +124,7 @@ module CouchdbRubyServer
136
124
  respond ["chunks", @@chunks]
137
125
  end
138
126
  @@chunks = []
139
- json = json_parse ARGF.gets
127
+ json = Serializer.load($stdin.gets)
140
128
  if json[0] == 'list_end'
141
129
  @@last_row = true
142
130
  return nil
@@ -209,10 +197,13 @@ module CouchdbRubyServer
209
197
  end
210
198
 
211
199
  def self.run
200
+ trace {'+ run'}
201
+ $stdout.sync = true
212
202
  log "CouchdbRubyServer started, RUBY_VERSION: #{RUBY_VERSION}"
213
203
  log "RUBY_GC_MALLOC_LIMIT=#{ENV['RUBY_GC_MALLOC_LIMIT']}"
214
204
  while cmd = $stdin.gets
215
- cmd = json_parse cmd
205
+ cmd = Serializer.load(cmd)
206
+ trace {"cmd = #{cmd.inspect}"}
216
207
  case cmd[0]
217
208
  when "reset"
218
209
  @@callables = []
@@ -0,0 +1,7 @@
1
+ module CouchdbRubyServer
2
+ @@trace = ENV['QS_TRACE']
3
+ def self.trace(str = nil)
4
+ return unless @@trace
5
+ $stderr.puts("QS_TRACE: #{block_given? ? yield : str}")
6
+ end
7
+ end
@@ -1,5 +1,5 @@
1
1
  # coding: utf-8
2
2
 
3
3
  module CouchdbRubyServer
4
- VERSION = '1.0.0'
4
+ VERSION = '1.0.1'
5
5
  end
@@ -1,8 +1,6 @@
1
1
  # coding: utf-8
2
2
 
3
- require 'oj'
4
- ::Oj.default_options = {:mode => :compat,
5
- :class_cache => true }
6
-
7
3
  require 'couchdb-ruby-server/version'
4
+ require 'couchdb-ruby-server/serializer'
5
+ require 'couchdb-ruby-server/tracer'
8
6
  require 'couchdb-ruby-server/server'
@@ -19,32 +19,27 @@
19
19
  # QS_LANG=lang
20
20
  # run tests on the query server (for now, one of: js, erlang)
21
21
  #
22
- require 'json'
23
22
 
24
23
  COUCH_ROOT = "#{File.dirname(__FILE__)}/../.." unless defined?(COUCH_ROOT)
25
24
  LANGUAGE = ENV["QS_LANG"] || "ruby"
25
+ COMMANDS = {
26
+ "js" => "#{COUCH_ROOT}/bin/couchjs #{COUCH_ROOT}/share/server/main.js",
27
+ "erlang" => "#{COUCH_ROOT}/test/view_server/run_native_process.es",
28
+ "ruby" => "bin/couchdb-ruby-server"
29
+ }
26
30
 
27
31
  puts "Running query server specs for #{LANGUAGE} query server"
28
32
 
29
33
  require 'spec_helper'
30
34
 
31
- class OSProcessRunner
32
- def self.run
33
- trace = ENV["QS_TRACE"] || false
34
- puts "launching #{run_command}" if trace
35
- if block_given?
36
- IO.popen(run_command, "r+") do |io|
37
- qs = QueryServerRunner.new(io, trace)
38
- yield qs
39
- end
40
- else
41
- io = IO.popen(run_command, "r+")
42
- QueryServerRunner.new(io, trace)
43
- end
35
+ class QueryServerRunner
36
+ def trace str=nil, &block
37
+ CouchdbRubyServer.trace str, &block
44
38
  end
45
- def initialize io, trace = false
46
- @qsio = io
47
- @trace = trace
39
+
40
+ def initialize
41
+ trace {"launching #{COMMANDS[LANGUAGE]}"}
42
+ @qsio = IO.popen(COMMANDS[LANGUAGE], "w+")
48
43
  end
49
44
  def close
50
45
  @qsio.close
@@ -76,59 +71,21 @@ class OSProcessRunner
76
71
  jsgets
77
72
  end
78
73
  def rrun json
79
- line = json.to_json
80
- puts "run: #{line}" if @trace
81
- @qsio.puts line
74
+ line = CouchdbRubyServer::Serializer.dump(json)
75
+ trace { "run: #{line}" }
76
+ @qsio.puts(line)
82
77
  end
83
78
  def rgets
84
- resp = @qsio.gets
85
- puts "got: #{resp}" if @trace
79
+ resp = @qsio.closed? ? '' : @qsio.gets
80
+ trace { "got: #{resp}" }
86
81
  resp
87
82
  end
88
83
  def jsgets
89
- resp = rgets
90
- # err = @qserr.gets
91
- # puts "err: #{err}" if err
92
- if resp
93
- begin
94
- rj = JSON.parse("[#{resp.chomp}]")[0]
95
- rescue JSON::ParserError
96
- puts "JSON ERROR (dump under trace mode)"
97
- # puts resp.chomp
98
- while resp = rgets
99
- # puts resp.chomp
100
- end
101
- end
102
- if rj.respond_to?(:[]) && rj.is_a?(Array)
103
- if rj[0] == "log"
104
- log = rj[1]
105
- puts "log: #{log}" if @trace
106
- rj = jsgets
107
- end
108
- end
109
- rj
110
- else
111
- raise "no response"
112
- end
113
- end
114
- end
115
-
116
- class QueryServerRunner < OSProcessRunner
117
-
118
- COMMANDS = {
119
- "js" => "#{COUCH_ROOT}/bin/couchjs #{COUCH_ROOT}/share/server/main.js",
120
- "erlang" => "#{COUCH_ROOT}/test/view_server/run_native_process.es",
121
- "ruby" => "bin/couchdb-ruby-server"
122
- }
123
-
124
- def self.run_command
125
- COMMANDS[LANGUAGE]
126
- end
127
- end
128
-
129
- class ExternalRunner < OSProcessRunner
130
- def self.run_command
131
- "#{COUCH_ROOT}/src/couchdb/couchjs #{COUCH_ROOT}/share/server/echo.js"
84
+ raise "no response" unless resp = rgets
85
+ rj = CouchdbRubyServer::Serializer.load("[#{resp}]").first
86
+ return rj unless rj.is_a?(Array) && rj[0] == "log"
87
+ trace { "log: #{rj[1]}" }
88
+ jsgets
132
89
  end
133
90
  end
134
91
 
@@ -618,7 +575,7 @@ end
618
575
  describe "query server normal case" do
619
576
  before(:all) do
620
577
  `cd #{COUCH_ROOT} && make` unless LANGUAGE == 'ruby'
621
- @qs = QueryServerRunner.run
578
+ @qs = QueryServerRunner.new
622
579
  end
623
580
  after(:all) do
624
581
  @qs.close
@@ -892,7 +849,7 @@ end
892
849
 
893
850
  describe "query server that exits" do
894
851
  before(:each) do
895
- @qs = QueryServerRunner.run
852
+ @qs = QueryServerRunner.new
896
853
  @ddoc = {
897
854
  "_id" => "foo",
898
855
  "lists" => {
data/spec/spec_helper.rb CHANGED
@@ -5,6 +5,8 @@ rescue LoadError
5
5
  $stderr.puts "CodeClimate is not started: #{$!.message}"
6
6
  end
7
7
 
8
- #require 'couchdb-ruby-server' INTENTIONALLY, TESTING COMMAND LINE CALL
8
+ require 'couchdb-ruby-server/tracer'
9
+ require 'couchdb-ruby-server/serializer'
10
+
9
11
  require 'minitest/autorun'
10
12
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: couchdb-ruby-server
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - sinm
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-20 00:00:00.000000000 Z
11
+ date: 2015-04-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -16,56 +16,56 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1'
19
+ version: '1.7'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1'
26
+ version: '1.7'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '10'
33
+ version: '10.1'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '10'
40
+ version: '10.1'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: minitest
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '4'
47
+ version: '4.7'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '4'
54
+ version: '4.7'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: argparser
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '1'
61
+ version: '1.0'
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '1'
68
+ version: '1.0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: oj
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -100,7 +100,9 @@ files:
100
100
  - couchdb-ruby-server.gemspec
101
101
  - couchdb-ruby-server.sublime-project
102
102
  - lib/couchdb-ruby-server.rb
103
+ - lib/couchdb-ruby-server/serializer.rb
103
104
  - lib/couchdb-ruby-server/server.rb
105
+ - lib/couchdb-ruby-server/tracer.rb
104
106
  - lib/couchdb-ruby-server/version.rb
105
107
  - spec/couchdb-ruby-server_spec.rb
106
108
  - spec/spec_helper.rb