pg_array_parser 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/.travis.yml +2 -3
- data/CHANGELOG.md +4 -0
- data/README.md +29 -9
- data/Rakefile +6 -2
- data/ext/pg_array_parser/PgArrayParserEngine.java +99 -94
- data/ext/pg_array_parser/PgArrayParserEngineService.java +13 -19
- data/lib/pg_array_parser.jar +0 -0
- data/lib/pg_array_parser.rb +5 -2
- data/lib/pg_array_parser/version.rb +1 -1
- metadata +27 -28
- data/LICENSE +0 -22
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
# 0.0.3
|
2
|
+
* Refactored Java to ensure thread safety - [mauricio](https://github.com/mauricio) -
|
3
|
+
Merged at [a30aba](https://github.com/dockyard/pg_array_parser/commit/a30aba4885812290f83c693e6b68c697b0dac675)
|
4
|
+
|
1
5
|
# 0.0.2
|
2
6
|
* Refactored C extension - [jeremyevans](https://github.com/jeremyevens) - Merged at [ad4987](https://github.com/dockyard/pg_array_parser/commit/ad4987dba411decca4aebd0750c990212dc81039)
|
3
7
|
* Adds JRuby support - thanks to [tychobrailleur](https://github.com/tychobrailleur) for help with the java class
|
data/README.md
CHANGED
@@ -1,12 +1,15 @@
|
|
1
1
|
# PgArrayParser
|
2
|
+
[![Build Status](http://travis-ci.org/dockyard/easy_auth.png)](http://travis-ci.org/dockyard/pg_array_parser)
|
3
|
+
[![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/dockyard/pg_array_parser)
|
2
4
|
|
3
5
|
Fast PostreSQL array parsing.
|
4
|
-
|
5
6
|
## Installation
|
6
7
|
|
7
8
|
Add this line to your application's Gemfile:
|
8
9
|
|
9
|
-
|
10
|
+
```ruby
|
11
|
+
gem 'pg_array_parser'
|
12
|
+
```
|
10
13
|
|
11
14
|
And then execute:
|
12
15
|
|
@@ -39,12 +42,29 @@ parser.parse_pg_array '{some,strings that,"May have some ,\'s"}'
|
|
39
42
|
|
40
43
|
## Authors
|
41
44
|
|
42
|
-
Dan McClain
|
45
|
+
[Dan McClain](http://github.com/danmcclain) [twitter](http://twitter.com/_danmcclain)
|
46
|
+
|
47
|
+
## Versioning ##
|
48
|
+
|
49
|
+
This gem follows [Semantic Versioning](http://semver.org)
|
50
|
+
|
51
|
+
## Want to help? ##
|
52
|
+
|
53
|
+
Stable branches are created based upon each minor version. Please make
|
54
|
+
pull requests to specific branches rather than master.
|
55
|
+
|
56
|
+
Please make sure you include tests!
|
57
|
+
|
58
|
+
Unles Rails drops support for Ruby 1.8.7 we will continue to use the
|
59
|
+
hash-rocket syntax. Please respect this.
|
60
|
+
|
61
|
+
Don't use tabs to indent, two spaces are the standard.
|
62
|
+
|
63
|
+
## Legal ##
|
64
|
+
|
65
|
+
[DockYard](http://dockyard.com), LLC © 2012
|
43
66
|
|
44
|
-
|
67
|
+
[@dockyard](http://twitter.com/dockyard)
|
45
68
|
|
46
|
-
|
47
|
-
|
48
|
-
3. Commit your changes (`git commit -am 'Added some feature'`)
|
49
|
-
4. Push to the branch (`git push origin my-new-feature`)
|
50
|
-
5. Create new Pull Request
|
69
|
+
[Licensed under the MIT
|
70
|
+
license](http://www.opensource.org/licenses/mit-license.php)
|
data/Rakefile
CHANGED
@@ -6,10 +6,14 @@ require 'rspec/core/rake_task'
|
|
6
6
|
spec = Gem::Specification.load('pg_array_parser.gemspec')
|
7
7
|
|
8
8
|
if RUBY_PLATFORM =~ /java/
|
9
|
-
|
10
|
-
|
9
|
+
require 'rake/javaextensiontask'
|
10
|
+
Rake::JavaExtensionTask.new('pg_array_parser', spec)
|
11
|
+
else
|
12
|
+
require 'rake/extensiontask'
|
13
|
+
Rake::ExtensionTask.new('pg_array_parser', spec)
|
11
14
|
end
|
12
15
|
|
16
|
+
task :install => :compile
|
13
17
|
task :spec => :install
|
14
18
|
|
15
19
|
RSpec::Core::RakeTask.new(:spec)
|
@@ -1,113 +1,118 @@
|
|
1
1
|
package pgarrayparser;
|
2
2
|
|
3
|
-
import org.jruby
|
4
|
-
import org.jruby.RubyArray;
|
5
|
-
import org.jruby.RubyClass;
|
6
|
-
import org.jruby.RubyFixnum;
|
7
|
-
import org.jruby.RubyString;
|
8
|
-
import org.jruby.RubyNil;
|
9
|
-
import org.jruby.RubyModule;
|
10
|
-
import org.jruby.RubyObject;
|
11
|
-
import org.jruby.anno.JRubyMethod;
|
3
|
+
import org.jruby.*;
|
12
4
|
import org.jruby.anno.JRubyClass;
|
13
|
-
import org.jruby.
|
5
|
+
import org.jruby.anno.JRubyMethod;
|
14
6
|
import org.jruby.runtime.ThreadContext;
|
15
7
|
import org.jruby.runtime.builtin.IRubyObject;
|
16
|
-
import org.jruby.runtime.load.BasicLibraryService;
|
17
8
|
|
18
|
-
|
19
|
-
|
9
|
+
@JRubyClass(name = "PgArrayParser::PgArrayParserEngine")
|
10
|
+
public class PgArrayParserEngine extends RubyObject {
|
11
|
+
|
20
12
|
public PgArrayParserEngine(final Ruby runtime, RubyClass rubyClass) {
|
21
|
-
|
13
|
+
super(runtime, rubyClass);
|
22
14
|
}
|
23
15
|
|
24
|
-
private Ruby runtime;
|
25
|
-
private int index;
|
26
|
-
private String arrayString;
|
27
16
|
@JRubyMethod(name = "parse_pg_array")
|
28
|
-
public
|
29
|
-
|
30
|
-
|
31
|
-
arrayString = value.asJavaString();
|
32
|
-
IRubyObject returnValue = readArray();
|
33
|
-
return returnValue;
|
34
|
-
|
17
|
+
public RubyArray parse_pg_array( ThreadContext context, IRubyObject value) {
|
18
|
+
String content = value.asJavaString();
|
19
|
+
return parseData(context, content, 0);
|
35
20
|
}
|
36
21
|
|
37
|
-
private RubyArray
|
22
|
+
private static RubyArray parseData( ThreadContext context, String content, int index)
|
38
23
|
{
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
for(;index < arrayString.length(); ++index)
|
52
|
-
{
|
53
|
-
currentChar = arrayString.charAt(index);
|
54
|
-
if(openQuote < 1)
|
55
|
-
{
|
56
|
-
if(currentChar == ',' || currentChar == '}')
|
57
|
-
{
|
58
|
-
if(!escapeNext)
|
59
|
-
{
|
60
|
-
if(openQuote == 0 && word.length() == 4 && word.toString().equals("NULL"))
|
61
|
-
{
|
62
|
-
array.append(runtime.getNil());
|
63
|
-
}
|
64
|
-
else
|
65
|
-
{
|
66
|
-
array.append(RubyString.newString(runtime, word.toString()));
|
67
|
-
}
|
68
|
-
}
|
69
|
-
if(currentChar == '}')
|
70
|
-
{
|
71
|
-
return array;
|
24
|
+
RubyArray items = RubyArray.newArray(context.getRuntime());
|
25
|
+
|
26
|
+
for( int x = index; x < content.length(); x++ ) {
|
27
|
+
|
28
|
+
char token = content.charAt(x);
|
29
|
+
|
30
|
+
switch (token) {
|
31
|
+
case '{':
|
32
|
+
x = parseArrayContents( context, items, content, x + 1 );
|
33
|
+
break;
|
34
|
+
case '}':
|
35
|
+
return items;
|
72
36
|
}
|
73
|
-
|
74
|
-
openQuote = 0;
|
75
|
-
word = new StringBuilder();
|
76
|
-
}
|
77
|
-
else if(currentChar == '"')
|
78
|
-
{
|
79
|
-
openQuote = 1;
|
80
|
-
}
|
81
|
-
else if(currentChar == '{')
|
82
|
-
{
|
83
|
-
index++;
|
84
|
-
array.append(readArray());
|
85
|
-
escapeNext = true;
|
86
|
-
}
|
87
|
-
else
|
88
|
-
{
|
89
|
-
word.append(String.valueOf(currentChar));
|
90
|
-
}
|
91
|
-
}
|
92
|
-
else if(escapeNext)
|
93
|
-
{
|
94
|
-
word.append(String.valueOf(currentChar));
|
95
|
-
escapeNext = false;
|
96
|
-
}
|
97
|
-
else if(currentChar == '\\')
|
98
|
-
{
|
99
|
-
escapeNext = true;
|
37
|
+
|
100
38
|
}
|
101
|
-
|
102
|
-
|
103
|
-
|
39
|
+
|
40
|
+
return items;
|
41
|
+
}
|
42
|
+
|
43
|
+
private static int parseArrayContents( ThreadContext context, RubyArray items, String content, int index ) {
|
44
|
+
|
45
|
+
StringBuilder currentItem = new StringBuilder();
|
46
|
+
boolean isEscaping = false;
|
47
|
+
boolean isQuoted = false;
|
48
|
+
boolean wasQuoted = false;
|
49
|
+
|
50
|
+
int x = index;
|
51
|
+
|
52
|
+
for(; x < content.length(); x++ ) {
|
53
|
+
|
54
|
+
char token = content.charAt(x);
|
55
|
+
|
56
|
+
if ( isEscaping ) {
|
57
|
+
currentItem.append( token );
|
58
|
+
isEscaping = false;
|
59
|
+
} else {
|
60
|
+
if ( isQuoted ) {
|
61
|
+
switch (token) {
|
62
|
+
case '"':
|
63
|
+
isQuoted = false;
|
64
|
+
wasQuoted = true;
|
65
|
+
break;
|
66
|
+
case '\\':
|
67
|
+
isEscaping = true;
|
68
|
+
break;
|
69
|
+
default:
|
70
|
+
currentItem.append(token);
|
71
|
+
}
|
72
|
+
} else {
|
73
|
+
switch (token) {
|
74
|
+
case '\\':
|
75
|
+
isEscaping = true;
|
76
|
+
break;
|
77
|
+
case ',':
|
78
|
+
addItem(context, items, currentItem, wasQuoted);
|
79
|
+
currentItem = new StringBuilder();
|
80
|
+
wasQuoted = false;
|
81
|
+
break;
|
82
|
+
case '"':
|
83
|
+
isQuoted = true;
|
84
|
+
break;
|
85
|
+
case '{':
|
86
|
+
RubyArray internalItems = RubyArray.newArray(context.getRuntime());
|
87
|
+
x = parseArrayContents( context, internalItems, content, x + 1 );
|
88
|
+
items.add(internalItems);
|
89
|
+
break;
|
90
|
+
case '}':
|
91
|
+
addItem(context, items, currentItem, wasQuoted);
|
92
|
+
return x;
|
93
|
+
default:
|
94
|
+
currentItem.append(token);
|
95
|
+
}
|
96
|
+
}
|
97
|
+
}
|
98
|
+
|
104
99
|
}
|
105
|
-
|
106
|
-
|
107
|
-
|
100
|
+
|
101
|
+
return x;
|
102
|
+
}
|
103
|
+
|
104
|
+
private static void addItem( ThreadContext context, RubyArray items, StringBuilder builder, boolean quoted ) {
|
105
|
+
String value = builder.toString();
|
106
|
+
|
107
|
+
if ( value.length() == 0 ) {
|
108
|
+
return;
|
108
109
|
}
|
109
|
-
}
|
110
110
|
|
111
|
-
|
111
|
+
if ( !quoted && "NULL".equalsIgnoreCase( value ) ) {
|
112
|
+
items.add(context.getRuntime().getNil());
|
113
|
+
} else {
|
114
|
+
items.add(RubyString.newString( context.getRuntime(), value ));
|
115
|
+
}
|
112
116
|
}
|
113
|
-
|
117
|
+
|
118
|
+
}
|
@@ -1,32 +1,26 @@
|
|
1
1
|
package pgarrayparser;
|
2
2
|
|
3
|
-
import java.lang.Long;
|
4
|
-
import java.io.IOException;
|
5
|
-
|
6
3
|
import org.jruby.Ruby;
|
7
|
-
import org.jruby.RubyArray;
|
8
4
|
import org.jruby.RubyClass;
|
9
|
-
import org.jruby.RubyFixnum;
|
10
5
|
import org.jruby.RubyModule;
|
11
|
-
import org.jruby.RubyObject;
|
12
|
-
import org.jruby.anno.JRubyMethod;
|
13
6
|
import org.jruby.runtime.ObjectAllocator;
|
14
|
-
import org.jruby.runtime.ThreadContext;
|
15
7
|
import org.jruby.runtime.builtin.IRubyObject;
|
16
8
|
import org.jruby.runtime.load.BasicLibraryService;
|
17
9
|
|
10
|
+
import java.io.IOException;
|
11
|
+
|
18
12
|
public class PgArrayParserEngineService implements BasicLibraryService {
|
19
13
|
|
20
|
-
|
14
|
+
public boolean basicLoad(Ruby runtime) throws IOException {
|
21
15
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
16
|
+
RubyModule pgArrayParser = runtime.defineModule("PgArrayParser");
|
17
|
+
RubyClass pgArrayParserEngine = pgArrayParser.defineClassUnder("PgArrayParserEngine", runtime.getObject(), new ObjectAllocator() {
|
18
|
+
public IRubyObject allocate(Ruby runtime, RubyClass rubyClass) {
|
19
|
+
return new PgArrayParserEngine(runtime, rubyClass);
|
20
|
+
}
|
21
|
+
});
|
28
22
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
}
|
23
|
+
pgArrayParserEngine.defineAnnotatedMethods(PgArrayParserEngine.class);
|
24
|
+
return true;
|
25
|
+
}
|
26
|
+
}
|
data/lib/pg_array_parser.jar
CHANGED
Binary file
|
data/lib/pg_array_parser.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
require File.expand_path('../pg_array_parser/version', __FILE__)
|
2
|
-
require File.expand_path('../pg_array_parser', __FILE__)
|
3
2
|
|
4
3
|
if RUBY_PLATFORM =~ /java/
|
5
4
|
module PgArrayParser
|
@@ -13,6 +12,10 @@ if RUBY_PLATFORM =~ /java/
|
|
13
12
|
end
|
14
13
|
end
|
15
14
|
else
|
16
|
-
|
15
|
+
begin
|
16
|
+
require "pg_array_parser/pg_array_parser.#{RbConfig::CONFIG['DLEXT']}"
|
17
|
+
rescue LoadError
|
18
|
+
require "pg_array_parser.#{RbConfig::CONFIG['DLEXT']}"
|
19
|
+
end
|
17
20
|
end
|
18
21
|
|
metadata
CHANGED
@@ -1,77 +1,75 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pg_array_parser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.3
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Dan McClain
|
9
|
-
autorequire:
|
9
|
+
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
date: 2012-09-04 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
|
17
|
-
none: false
|
16
|
+
version_requirements: !ruby/object:Gem::Requirement
|
18
17
|
requirements:
|
19
18
|
- - ~>
|
20
19
|
- !ruby/object:Gem::Version
|
21
20
|
version: 2.11.0
|
22
|
-
type: :development
|
23
|
-
prerelease: false
|
24
|
-
version_requirements: !ruby/object:Gem::Requirement
|
25
21
|
none: false
|
22
|
+
requirement: !ruby/object:Gem::Requirement
|
26
23
|
requirements:
|
27
24
|
- - ~>
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: 2.11.0
|
27
|
+
none: false
|
28
|
+
prerelease: false
|
29
|
+
type: :development
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
31
|
name: rake
|
32
|
-
|
33
|
-
none: false
|
32
|
+
version_requirements: !ruby/object:Gem::Requirement
|
34
33
|
requirements:
|
35
34
|
- - ~>
|
36
35
|
- !ruby/object:Gem::Version
|
37
36
|
version: 0.9.2.2
|
38
|
-
type: :development
|
39
|
-
prerelease: false
|
40
|
-
version_requirements: !ruby/object:Gem::Requirement
|
41
37
|
none: false
|
38
|
+
requirement: !ruby/object:Gem::Requirement
|
42
39
|
requirements:
|
43
40
|
- - ~>
|
44
41
|
- !ruby/object:Gem::Version
|
45
42
|
version: 0.9.2.2
|
43
|
+
none: false
|
44
|
+
prerelease: false
|
45
|
+
type: :development
|
46
46
|
- !ruby/object:Gem::Dependency
|
47
47
|
name: rake-compiler
|
48
|
-
|
49
|
-
none: false
|
48
|
+
version_requirements: !ruby/object:Gem::Requirement
|
50
49
|
requirements:
|
51
50
|
- - ! '>='
|
52
51
|
- !ruby/object:Gem::Version
|
53
52
|
version: '0'
|
54
|
-
type: :development
|
55
|
-
prerelease: false
|
56
|
-
version_requirements: !ruby/object:Gem::Requirement
|
57
53
|
none: false
|
54
|
+
requirement: !ruby/object:Gem::Requirement
|
58
55
|
requirements:
|
59
56
|
- - ! '>='
|
60
57
|
- !ruby/object:Gem::Version
|
61
58
|
version: '0'
|
59
|
+
none: false
|
60
|
+
prerelease: false
|
61
|
+
type: :development
|
62
62
|
description: Simple library to parse PostgreSQL arrays into a array of strings
|
63
63
|
email:
|
64
64
|
- git@danmcclain.net
|
65
65
|
executables: []
|
66
|
-
extensions:
|
67
|
-
- ext/pg_array_parser/extconf.rb
|
66
|
+
extensions: []
|
68
67
|
extra_rdoc_files: []
|
69
68
|
files:
|
70
69
|
- .gitignore
|
71
70
|
- .travis.yml
|
72
71
|
- CHANGELOG.md
|
73
72
|
- Gemfile
|
74
|
-
- LICENSE
|
75
73
|
- README.md
|
76
74
|
- Rakefile
|
77
75
|
- ext/pg_array_parser/PgArrayParserEngine.java
|
@@ -86,29 +84,30 @@ files:
|
|
86
84
|
- spec/spec_helper.rb
|
87
85
|
homepage: ''
|
88
86
|
licenses: []
|
89
|
-
post_install_message:
|
87
|
+
post_install_message:
|
90
88
|
rdoc_options: []
|
91
89
|
require_paths:
|
92
90
|
- lib
|
93
91
|
required_ruby_version: !ruby/object:Gem::Requirement
|
94
|
-
none: false
|
95
92
|
requirements:
|
96
93
|
- - ! '>='
|
97
94
|
- !ruby/object:Gem::Version
|
98
95
|
version: '0'
|
99
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
96
|
none: false
|
97
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
98
|
requirements:
|
102
99
|
- - ! '>='
|
103
100
|
- !ruby/object:Gem::Version
|
104
101
|
version: '0'
|
102
|
+
none: false
|
105
103
|
requirements: []
|
106
|
-
rubyforge_project:
|
107
|
-
rubygems_version: 1.8.
|
108
|
-
signing_key:
|
104
|
+
rubyforge_project:
|
105
|
+
rubygems_version: 1.8.24
|
106
|
+
signing_key:
|
109
107
|
specification_version: 3
|
110
108
|
summary: Converts PostgreSQL array strings into arrays of strings
|
111
109
|
test_files:
|
112
110
|
- spec/parser_spec.rb
|
113
111
|
- spec/spec_helper.rb
|
114
|
-
has_rdoc:
|
112
|
+
has_rdoc:
|
113
|
+
...
|
data/LICENSE
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
Copyright (c) 2012 Dan McClain
|
2
|
-
|
3
|
-
MIT License
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
-
a copy of this software and associated documentation files (the
|
7
|
-
"Software"), to deal in the Software without restriction, including
|
8
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
-
permit persons to whom the Software is furnished to do so, subject to
|
11
|
-
the following conditions:
|
12
|
-
|
13
|
-
The above copyright notice and this permission notice shall be
|
14
|
-
included in all copies or substantial portions of the Software.
|
15
|
-
|
16
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|