mongo-ejson 0.2.0 → 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rubocop.yml +34 -0
- data/.rubocop_todo.yml +13 -0
- data/.ruby-version +1 -0
- data/.travis.yml +6 -2
- data/Gemfile +1 -1
- data/Gemfile.lock +39 -18
- data/README.md +60 -36
- data/Rakefile +10 -10
- data/bin/console +3 -3
- data/ejson.gemspec +23 -22
- data/lib/ejson.rb +10 -4
- data/lib/ejson/parser_action/abstract_json.rb +14 -11
- data/lib/ejson/parser_action/abstract_mongo.rb +11 -11
- data/lib/ejson/parser_action/bson.rb +20 -22
- data/lib/ejson/parser_action/ruby.rb +31 -24
- data/lib/ejson/parser_action/wrap.rb +8 -8
- data/lib/ejson/parser_action/wrap_types.rb +4 -4
- data/lib/ejson/version.rb +1 -1
- data/src/ejson.peg +23 -4
- data/src/ejson.rb +449 -48
- data/{lib/assets → vendor/assets/javascripts}/ejson.js +450 -49
- metadata +26 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c98ad3da7747bd6271099b7813fce22ceced579a27dba30492e01a8de63a1a6e
|
4
|
+
data.tar.gz: 41e98def1985407533d220c4453beb3bca2a8cde1482e975298e11fec5ea56bc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b1d75937eaea35dedab3ff4a324a190d060baa5abdcc17727890bc6b2bac99481f8bdd79185b006957dfe051f0ce2da0c36b441ff3385adc1d41135eccbdc2d3
|
7
|
+
data.tar.gz: 2a176c418b1ba1a6bdd1394932f764a7cd110ae2b099a8af6338815998c401c325e3c6b52965c55b78d377e21c10829ca79f5b5b59d31f2054589a3f0cf5800f
|
data/.gitignore
CHANGED
data/.rubocop.yml
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
inherit_from: .rubocop_todo.yml
|
2
|
+
|
3
|
+
AllCops:
|
4
|
+
Exclude:
|
5
|
+
- 'src/**/*'
|
6
|
+
- 'vendor/bundle/**/*'
|
7
|
+
|
8
|
+
Metrics/LineLength:
|
9
|
+
Max: 120
|
10
|
+
|
11
|
+
Layout/EndOfLine:
|
12
|
+
EnforcedStyle: lf
|
13
|
+
|
14
|
+
Style/SymbolArray:
|
15
|
+
EnforcedStyle: brackets
|
16
|
+
|
17
|
+
Style/TrailingCommaInHashLiteral:
|
18
|
+
EnforcedStyleForMultiline: consistent_comma
|
19
|
+
|
20
|
+
Style/EmptyMethod:
|
21
|
+
EnforcedStyle: expanded
|
22
|
+
|
23
|
+
Metrics/BlockLength:
|
24
|
+
Exclude:
|
25
|
+
- '*.gemspec'
|
26
|
+
ExcludedMethods:
|
27
|
+
- describe
|
28
|
+
|
29
|
+
Style/FrozenStringLiteralComment:
|
30
|
+
EnforcedStyle: when_needed
|
31
|
+
|
32
|
+
Layout/AlignHash:
|
33
|
+
EnforcedHashRocketStyle: table
|
34
|
+
EnforcedColonStyle: table
|
data/.rubocop_todo.yml
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# This configuration was generated by
|
2
|
+
# `rubocop --auto-gen-config`
|
3
|
+
# on 2019-02-07 17:38:30 +0300 using RuboCop version 0.63.1.
|
4
|
+
# The point is for the user to remove these configuration records
|
5
|
+
# one by one as the offenses are removed from the code base.
|
6
|
+
# Note that changes in the inspected code, or installation of new
|
7
|
+
# versions of RuboCop, may require this file to be generated again.
|
8
|
+
|
9
|
+
Style/FrozenStringLiteralComment:
|
10
|
+
Enabled: false
|
11
|
+
|
12
|
+
Style/Documentation:
|
13
|
+
Enabled: false
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.6.1
|
data/.travis.yml
CHANGED
@@ -1,9 +1,13 @@
|
|
1
|
-
---
|
2
1
|
sudo: false
|
3
2
|
language: ruby
|
4
3
|
cache: bundler
|
5
4
|
rvm:
|
5
|
+
- 2.7
|
6
6
|
- 2.6
|
7
7
|
- 2.5
|
8
8
|
- jruby-9.2
|
9
|
-
before_install:
|
9
|
+
before_install:
|
10
|
+
- gem install bundler -v 2.0.1
|
11
|
+
script:
|
12
|
+
- bundle exec rspec
|
13
|
+
- bundle exec rubocop
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,28 +1,48 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
mongo-ejson (0.2.
|
4
|
+
mongo-ejson (0.2.5)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
|
-
|
10
|
-
bson (4.
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
9
|
+
ast (2.4.1)
|
10
|
+
bson (4.9.2)
|
11
|
+
bson (4.9.2-java)
|
12
|
+
diff-lcs (1.4.2)
|
13
|
+
parallel (1.19.2)
|
14
|
+
parser (2.7.1.4)
|
15
|
+
ast (~> 2.4.1)
|
16
|
+
rainbow (3.0.0)
|
17
|
+
rake (13.0.1)
|
18
|
+
regexp_parser (1.7.1)
|
19
|
+
rexml (3.2.4)
|
20
|
+
rspec (3.9.0)
|
21
|
+
rspec-core (~> 3.9.0)
|
22
|
+
rspec-expectations (~> 3.9.0)
|
23
|
+
rspec-mocks (~> 3.9.0)
|
24
|
+
rspec-core (3.9.2)
|
25
|
+
rspec-support (~> 3.9.3)
|
26
|
+
rspec-expectations (3.9.2)
|
20
27
|
diff-lcs (>= 1.2.0, < 2.0)
|
21
|
-
rspec-support (~> 3.
|
22
|
-
rspec-mocks (3.
|
28
|
+
rspec-support (~> 3.9.0)
|
29
|
+
rspec-mocks (3.9.1)
|
23
30
|
diff-lcs (>= 1.2.0, < 2.0)
|
24
|
-
rspec-support (~> 3.
|
25
|
-
rspec-support (3.
|
31
|
+
rspec-support (~> 3.9.0)
|
32
|
+
rspec-support (3.9.3)
|
33
|
+
rubocop (0.86.0)
|
34
|
+
parallel (~> 1.10)
|
35
|
+
parser (>= 2.7.0.1)
|
36
|
+
rainbow (>= 2.2.2, < 4.0)
|
37
|
+
regexp_parser (>= 1.7)
|
38
|
+
rexml
|
39
|
+
rubocop-ast (>= 0.0.3, < 1.0)
|
40
|
+
ruby-progressbar (~> 1.7)
|
41
|
+
unicode-display_width (>= 1.4.0, < 2.0)
|
42
|
+
rubocop-ast (0.0.3)
|
43
|
+
parser (>= 2.7.0.1)
|
44
|
+
ruby-progressbar (1.10.1)
|
45
|
+
unicode-display_width (1.7.0)
|
26
46
|
|
27
47
|
PLATFORMS
|
28
48
|
java
|
@@ -32,8 +52,9 @@ DEPENDENCIES
|
|
32
52
|
bson
|
33
53
|
bundler (~> 2.0)
|
34
54
|
mongo-ejson!
|
35
|
-
rake (~>
|
55
|
+
rake (~> 13.0)
|
36
56
|
rspec (~> 3.0)
|
57
|
+
rubocop (~> 0.63)
|
37
58
|
|
38
59
|
BUNDLED WITH
|
39
|
-
2.
|
60
|
+
2.1.4
|
data/README.md
CHANGED
@@ -1,57 +1,81 @@
|
|
1
1
|
# mongo-ejson
|
2
2
|
|
3
|
-
[![Build Status](https://travis-ci.org/db-ai/mongo-ejson.svg?branch=master)](https://travis-ci.org/db-ai/mongo-ejson)
|
3
|
+
[![Build Status](https://travis-ci.org/db-ai/mongo-ejson.svg?branch=master)](https://travis-ci.org/db-ai/mongo-ejson) [![Gem Version](https://badge.fury.io/rb/mongo-ejson.svg)](https://badge.fury.io/rb/mongo-ejson)
|
4
4
|
|
5
5
|
This is a parser for mongo "flavoured" JSON, that supports mongo specific literals like `ISODate` or `ObjectId`, as well as some other nasty non-json things.
|
6
6
|
|
7
7
|
It can instantiate corresponding BSON objects or produce Extended JSON objects.
|
8
8
|
|
9
|
+
## Usage
|
10
|
+
|
11
|
+
Add gem to your Gemfile:
|
12
|
+
|
13
|
+
gem 'mongo-ejson'
|
14
|
+
|
15
|
+
Require when needed:
|
16
|
+
|
17
|
+
require 'ejson'
|
18
|
+
|
19
|
+
You can parse files in two modes: `Wrap` and `BSON`.
|
20
|
+
|
21
|
+
In `Wrap` mode, parser will instantiate Struct classes. It's useful when you
|
22
|
+
only need to validate provided EJSON code.
|
23
|
+
|
24
|
+
EJSON.parse_wrap(%q|{ "_id": ObjectId('5c520a538628ea8c13261c64') }|)
|
25
|
+
=> {"_id"=>#<struct Struct::ObjectId hex="5c520a538628ea8c13261c64">}
|
26
|
+
|
27
|
+
To use `BSON` mode you need to install `bson` gem. In this case parser will
|
28
|
+
instantiate real BSON objects.
|
29
|
+
|
30
|
+
require 'bson'
|
31
|
+
EJSON.parse_bson(%q|{ "_id": ObjectId('5c520a538628ea8c13261c64') }|)
|
32
|
+
=> {"_id"=>BSON::ObjectId('5c520a538628ea8c13261c64')}
|
33
|
+
|
34
|
+
You can also use JavaScript parser in your Rails application. At the moment it
|
35
|
+
does not build JavaScript object and returns raw parse tree. It is useful only
|
36
|
+
for validating the syntax.
|
37
|
+
|
38
|
+
Just add it to your `application.js`
|
39
|
+
|
40
|
+
//= require 'ejson'
|
41
|
+
|
9
42
|
## Requirements
|
10
43
|
|
11
44
|
Runtime:
|
12
|
-
|
13
|
-
|
45
|
+
|
46
|
+
- Ruby 2.5+
|
47
|
+
- JRuby 9.2+
|
14
48
|
|
15
49
|
Development:
|
16
|
-
|
50
|
+
|
51
|
+
- [canopy](https://github.com/jcoglan/canopy) from master branch
|
17
52
|
|
18
53
|
## Supported literals
|
19
54
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
55
|
+
- `undefined`
|
56
|
+
- `MinKey`
|
57
|
+
- `MaxKey`
|
58
|
+
- `ObjectId(<object_id_hex_string>)`
|
59
|
+
- `BinData(<type_string>, <bindata_base64_string>)`
|
60
|
+
- `BinData(<type_integer>, <base64_bindata>)`
|
61
|
+
- `Timestamp(<time_interger>, <increment_integer>)`
|
62
|
+
- `NumberLong(<value_string>)`
|
63
|
+
- `NumberLong(<value_integer>)`
|
64
|
+
- `NumberDecimal(<value_string>)`
|
65
|
+
- `NumberDecimal(<value_number>)`
|
66
|
+
- `ISODate(<time_iso8601_string>)`
|
67
|
+
- `ISODate(<time_interger>)`
|
68
|
+
- `new Date(<time_iso8601_string>)`
|
69
|
+
- `new Date(<time_interger>)`
|
70
|
+
- `/<regexp>/<options>`
|
71
|
+
- `DBRef(<name_string>, <object_id_hex_string>)`
|
37
72
|
|
38
73
|
## Supported JSON extensions:
|
39
74
|
|
40
|
-
|
41
|
-
|
75
|
+
- Single quoted strings
|
76
|
+
- Single line comments `//`
|
77
|
+
- Non-quoted key names: `{_id: 123}`
|
42
78
|
|
43
79
|
## Planned JSON extensions:
|
44
80
|
|
45
|
-
|
46
|
-
|
47
|
-
## Issues
|
48
|
-
|
49
|
-
* String: following not escaped chars should fail, but pass
|
50
|
-
|
51
|
-
* Backspace (must be replaced with `\b`). no fixture
|
52
|
-
* Form feed (must be replaced with `\f`), no fixture
|
53
|
-
* Newline (must be replaced with `\n`)
|
54
|
-
* Carriage return (must be replaced with `\r`), no fixture
|
55
|
-
* Tab (must be replaced with `\t`)
|
56
|
-
|
57
|
-
|
81
|
+
- Multi-line comments: `/* */`
|
data/Rakefile
CHANGED
@@ -1,26 +1,26 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require 'rspec/core/rake_task'
|
3
3
|
require 'fileutils'
|
4
4
|
|
5
5
|
CANOPY_BIN = ENV.fetch('CANOPY_BIN') { 'canopy' }
|
6
6
|
|
7
7
|
RSpec::Core::RakeTask.new(:spec)
|
8
8
|
|
9
|
-
task :
|
9
|
+
task default: :spec
|
10
10
|
|
11
11
|
task :compile_js do
|
12
|
-
sh %
|
12
|
+
sh %( #{CANOPY_BIN} src/ejson.peg --lang javascript )
|
13
13
|
end
|
14
14
|
|
15
15
|
task :compile_ruby do
|
16
|
-
sh %
|
16
|
+
sh %( #{CANOPY_BIN} src/ejson.peg --lang ruby )
|
17
17
|
end
|
18
18
|
|
19
|
-
desc
|
20
|
-
task :
|
19
|
+
desc 'Build and run test suite'
|
20
|
+
task test: [:compile_ruby, :spec] do
|
21
21
|
end
|
22
22
|
|
23
|
-
desc
|
24
|
-
task :
|
25
|
-
mv 'src/ejson.js', '
|
23
|
+
desc 'Prepare assets'
|
24
|
+
task assets: [:test, :compile_js, :compile_ruby] do
|
25
|
+
mv 'src/ejson.js', 'vendor/assets/javascripts/ejson.js'
|
26
26
|
end
|
data/bin/console
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'ejson'
|
5
5
|
|
6
6
|
# You can add fixtures and/or initialization code here to make experimenting
|
7
7
|
# with your gem easier. You can also use a different console, if you like.
|
@@ -10,5 +10,5 @@ require "ejson"
|
|
10
10
|
# require "pry"
|
11
11
|
# Pry.start
|
12
12
|
|
13
|
-
require
|
13
|
+
require 'irb'
|
14
14
|
IRB.start(__FILE__)
|
data/ejson.gemspec
CHANGED
@@ -1,46 +1,47 @@
|
|
1
|
-
|
2
|
-
lib = File.expand_path("../lib", __FILE__)
|
1
|
+
lib = File.expand_path('lib', __dir__)
|
3
2
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require
|
3
|
+
require 'ejson/version'
|
5
4
|
|
6
5
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
6
|
+
spec.name = 'mongo-ejson'
|
8
7
|
spec.version = EJSON::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
8
|
+
spec.authors = ['Alex Bondar']
|
9
|
+
spec.email = ['mongo-ejson-gem@db-ai.co']
|
11
10
|
|
12
|
-
spec.summary =
|
13
|
-
spec.description =
|
14
|
-
spec.homepage =
|
11
|
+
spec.summary = 'MongoDB Extended JS(ON) parser'
|
12
|
+
spec.description = 'Parses MongoDB favoured JS(ON) string into objects'
|
13
|
+
spec.homepage = 'https://gibhub.com/db-ai/mongo-ejson'
|
15
14
|
|
16
15
|
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the
|
17
16
|
# 'allowed_push_host' to allow pushing to a single host or delete this
|
18
17
|
# section to allow pushing to any host.
|
19
18
|
if spec.respond_to?(:metadata)
|
20
|
-
spec.metadata[
|
19
|
+
spec.metadata['allowed_push_host'] = 'https://rubygems.org/'
|
21
20
|
|
22
|
-
spec.metadata[
|
23
|
-
spec.metadata[
|
24
|
-
spec.metadata[
|
21
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
22
|
+
spec.metadata['source_code_uri'] = 'https://gibhub.com/db-ai/mongo-ejson'
|
23
|
+
spec.metadata['changelog_uri'] = 'https://gibhub.com/db-ai/mongo-ejson'
|
25
24
|
else
|
26
|
-
raise
|
27
|
-
|
25
|
+
raise 'RubyGems 2.0 or newer is required to protect against ' \
|
26
|
+
'public gem pushes.'
|
28
27
|
end
|
29
28
|
|
30
29
|
# Specify which files should be added to the gem when it is released.
|
31
30
|
# The `git ls-files -z` loads the files in the RubyGem that have been
|
32
31
|
# added into git.
|
33
|
-
spec.files
|
32
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
34
33
|
`git ls-files -z`
|
35
34
|
.split("\x0")
|
36
35
|
.reject { |f| f.match(%r{^(test|spec|features)/}) }
|
37
36
|
end
|
38
|
-
spec.bindir =
|
37
|
+
spec.bindir = 'exe'
|
39
38
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
40
|
-
spec.require_paths = [
|
39
|
+
spec.require_paths = ['lib']
|
40
|
+
|
41
|
+
spec.add_development_dependency 'bundler', '~> 2.0'
|
42
|
+
spec.add_development_dependency 'rake', '~> 13.0'
|
43
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
44
|
+
spec.add_development_dependency 'rubocop', '~> 0.63'
|
41
45
|
|
42
|
-
spec.add_development_dependency
|
43
|
-
spec.add_development_dependency "rake", "~> 10.0"
|
44
|
-
spec.add_development_dependency "rspec", "~> 3.0"
|
45
|
-
spec.add_development_dependency "bson"
|
46
|
+
spec.add_development_dependency 'bson'
|
46
47
|
end
|
data/lib/ejson.rb
CHANGED
@@ -23,14 +23,20 @@ class EJSON
|
|
23
23
|
end
|
24
24
|
|
25
25
|
private
|
26
|
+
|
26
27
|
def boot_bson
|
27
28
|
return if defined? ::BSON
|
28
|
-
require 'bson' rescue nil
|
29
29
|
|
30
|
-
|
31
|
-
|
32
|
-
|
30
|
+
begin
|
31
|
+
require 'bson'
|
32
|
+
rescue StandardError
|
33
|
+
nil
|
33
34
|
end
|
35
|
+
|
36
|
+
return if defined? ::BSON
|
37
|
+
|
38
|
+
raise "Can't find constant ::BSON. Seems like gem 'bson' is not " \
|
39
|
+
"loaded. Make sure it's available in your bundle."
|
34
40
|
end
|
35
41
|
end
|
36
42
|
end
|
@@ -1,37 +1,40 @@
|
|
1
1
|
module ParserAction
|
2
2
|
module AbstractJSON
|
3
3
|
# JSON Entities
|
4
|
-
def make_root(input,
|
4
|
+
def make_root(input, starts_at, _ends_at, elements)
|
5
5
|
end
|
6
6
|
|
7
|
-
def make_object(input,
|
7
|
+
def make_object(input, starts_at, _ends_at, elements)
|
8
8
|
end
|
9
9
|
|
10
|
-
def make_pair(input,
|
10
|
+
def make_pair(input, starts_at, _ends_at, elements)
|
11
11
|
end
|
12
12
|
|
13
|
-
def make_empty_object(input,
|
13
|
+
def make_empty_object(input, starts_at, _ends_at, elements)
|
14
14
|
end
|
15
15
|
|
16
|
-
def make_string(input,
|
16
|
+
def make_string(input, starts_at, _ends_at, elements)
|
17
17
|
end
|
18
18
|
|
19
|
-
def
|
19
|
+
def make_identifier(input, starts_at, _ends_at, elements)
|
20
20
|
end
|
21
21
|
|
22
|
-
def
|
22
|
+
def make_array(input, starts_at, _ends_at, elements)
|
23
23
|
end
|
24
24
|
|
25
|
-
def
|
25
|
+
def make_empty_array(input, starts_at, _ends_at, elements)
|
26
26
|
end
|
27
27
|
|
28
|
-
def
|
28
|
+
def make_number(input, starts_at, _ends_at, elements)
|
29
29
|
end
|
30
30
|
|
31
|
-
def
|
31
|
+
def make_null(input, starts_at, _ends_at)
|
32
32
|
end
|
33
33
|
|
34
|
-
def
|
34
|
+
def make_true(input, starts_at, _ends_at)
|
35
|
+
end
|
36
|
+
|
37
|
+
def make_false(input, starts_at, _ends_at)
|
35
38
|
end
|
36
39
|
end
|
37
40
|
end
|