mongo-ejson 0.2.0 → 0.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ad82ad33cec308c20018042c44a50361619d79813bb866e830126794f35daed1
4
- data.tar.gz: 7d2bec415b3328b6c112e382819f3d6c9b0b97fbdbbbf3d40ec4779a8926b36c
3
+ metadata.gz: c98ad3da7747bd6271099b7813fce22ceced579a27dba30492e01a8de63a1a6e
4
+ data.tar.gz: 41e98def1985407533d220c4453beb3bca2a8cde1482e975298e11fec5ea56bc
5
5
  SHA512:
6
- metadata.gz: 7fcd47f32cbb62d40ea9d268746f4bd7ebb8611a5c044297c16bb4a9dbd14d7d79933f6a0bf4b58d731c93d7bc7abe2dac3cf281ce1a62ea3d956abec3c8a826
7
- data.tar.gz: 412d8ed39076c303b704016dfda59d25ad05a7e40a5314a430d59b5fdaf7902fe0a18f019100b9ebbf77a0715f5a455c1a01559d7247f6a758fe130871243199
6
+ metadata.gz: b1d75937eaea35dedab3ff4a324a190d060baa5abdcc17727890bc6b2bac99481f8bdd79185b006957dfe051f0ce2da0c36b441ff3385adc1d41135eccbdc2d3
7
+ data.tar.gz: 2a176c418b1ba1a6bdd1394932f764a7cd110ae2b099a8af6338815998c401c325e3c6b52965c55b78d377e21c10829ca79f5b5b59d31f2054589a3f0cf5800f
data/.gitignore CHANGED
@@ -6,6 +6,7 @@
6
6
  /pkg/
7
7
  /spec/reports/
8
8
  /tmp/
9
+ *.gem
9
10
 
10
11
  # rspec failure tracking
11
12
  .rspec_status
@@ -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
@@ -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
@@ -0,0 +1 @@
1
+ 2.6.1
@@ -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: gem install bundler -v 2.0.1
9
+ before_install:
10
+ - gem install bundler -v 2.0.1
11
+ script:
12
+ - bundle exec rspec
13
+ - bundle exec rubocop
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source "https://rubygems.org"
1
+ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in mongo-ejson.gemspec
4
4
  gemspec
@@ -1,28 +1,48 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mongo-ejson (0.2.0)
4
+ mongo-ejson (0.2.5)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
- bson (4.4.2)
10
- bson (4.4.2-java)
11
- diff-lcs (1.3)
12
- rake (10.5.0)
13
- rspec (3.8.0)
14
- rspec-core (~> 3.8.0)
15
- rspec-expectations (~> 3.8.0)
16
- rspec-mocks (~> 3.8.0)
17
- rspec-core (3.8.0)
18
- rspec-support (~> 3.8.0)
19
- rspec-expectations (3.8.2)
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.8.0)
22
- rspec-mocks (3.8.0)
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.8.0)
25
- rspec-support (3.8.0)
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 (~> 10.0)
55
+ rake (~> 13.0)
36
56
  rspec (~> 3.0)
57
+ rubocop (~> 0.63)
37
58
 
38
59
  BUNDLED WITH
39
- 2.0.1
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
- * Ruby 2.5+
13
- * JRuby 9.2+
45
+
46
+ - Ruby 2.5+
47
+ - JRuby 9.2+
14
48
 
15
49
  Development:
16
- * [canopy](https://github.com/jcoglan/canopy) from master branch
50
+
51
+ - [canopy](https://github.com/jcoglan/canopy) from master branch
17
52
 
18
53
  ## Supported literals
19
54
 
20
- * `undefined`
21
- * `MinKey`
22
- * `MaxKey`
23
- * `ObjectId(<object_id_hex_string>)`
24
- * `BinData(<type_string>, <bindata_base64_string>)`
25
- * `BinData(<type_integer>, <base64_bindata>)`
26
- * `Timestamp(<time_interger>, <increment_integer>)`
27
- * `NumberLong(<value_string>)`
28
- * `NumberLong(<value_integer>)`
29
- * `NumberDecimal(<value_string>)`
30
- * `NumberDecimal(<value_number>)`
31
- * `ISODate(<time_iso8601_string>)`
32
- * `ISODate(<time_interger>)`
33
- * `new Date(<time_iso8601_string>)`
34
- * `new Date(<time_interger>)`
35
- * `/<regexp>/<options>`
36
- * `DBRef(<name_string>, <object_id_hex_string>)`
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
- * Single quoted strings
41
- * Single line comments `//`
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
- * Multi-line comments: `/* */`
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 "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
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 :default => :spec
9
+ task default: :spec
10
10
 
11
11
  task :compile_js do
12
- sh %{ #{CANOPY_BIN} src/ejson.peg --lang javascript }
12
+ sh %( #{CANOPY_BIN} src/ejson.peg --lang javascript )
13
13
  end
14
14
 
15
15
  task :compile_ruby do
16
- sh %{ #{CANOPY_BIN} src/ejson.peg --lang ruby }
16
+ sh %( #{CANOPY_BIN} src/ejson.peg --lang ruby )
17
17
  end
18
18
 
19
- desc "Build and run test suite"
20
- task :test => [:compile_ruby, :spec] do
19
+ desc 'Build and run test suite'
20
+ task test: [:compile_ruby, :spec] do
21
21
  end
22
22
 
23
- desc "Prepare assets"
24
- task :assets => [:test, :compile_js] do
25
- mv 'src/ejson.js', 'lib/assets/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
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require "bundler/setup"
4
- require "ejson"
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 "irb"
13
+ require 'irb'
14
14
  IRB.start(__FILE__)
@@ -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 "ejson/version"
3
+ require 'ejson/version'
5
4
 
6
5
  Gem::Specification.new do |spec|
7
- spec.name = "mongo-ejson"
6
+ spec.name = 'mongo-ejson'
8
7
  spec.version = EJSON::VERSION
9
- spec.authors = ["Alex Bondar"]
10
- spec.email = ["mongo-ejson-gem@db-ai.co"]
8
+ spec.authors = ['Alex Bondar']
9
+ spec.email = ['mongo-ejson-gem@db-ai.co']
11
10
 
12
- spec.summary = %q{MongoDB Extended JS(ON) parser}
13
- spec.description = %q{Parses MongoDB favoured JS(ON) string into objects}
14
- spec.homepage = "https://gibhub.com/db-ai/mongo-ejson"
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["allowed_push_host"] = "https://rubygems.org/"
19
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org/'
21
20
 
22
- spec.metadata["homepage_uri"] = spec.homepage
23
- spec.metadata["source_code_uri"] = "https://gibhub.com/db-ai/mongo-ejson"
24
- spec.metadata["changelog_uri"] = "https://gibhub.com/db-ai/mongo-ejson"
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 "RubyGems 2.0 or newer is required to protect against " \
27
- "public gem pushes."
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 = Dir.chdir(File.expand_path('..', __FILE__)) do
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 = "exe"
37
+ spec.bindir = 'exe'
39
38
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
40
- spec.require_paths = ["lib"]
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 "bundler", "~> 2.0"
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
@@ -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
- unless defined? ::BSON
31
- raise "Can't find constant ::BSON. Seems like gem 'bson' is not " \
32
- "loaded. Make sure it's available in your bundle."
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, start, _end, elements)
4
+ def make_root(input, starts_at, _ends_at, elements)
5
5
  end
6
6
 
7
- def make_object(input, start, _end, elements)
7
+ def make_object(input, starts_at, _ends_at, elements)
8
8
  end
9
9
 
10
- def make_pair(input, start, _end, elements)
10
+ def make_pair(input, starts_at, _ends_at, elements)
11
11
  end
12
12
 
13
- def make_empty_object(input, start, _end, elements)
13
+ def make_empty_object(input, starts_at, _ends_at, elements)
14
14
  end
15
15
 
16
- def make_string(input, start, _end, elements)
16
+ def make_string(input, starts_at, _ends_at, elements)
17
17
  end
18
18
 
19
- def make_array(input, start, _end, elements)
19
+ def make_identifier(input, starts_at, _ends_at, elements)
20
20
  end
21
21
 
22
- def make_empty_array(input, start, _end, elements)
22
+ def make_array(input, starts_at, _ends_at, elements)
23
23
  end
24
24
 
25
- def make_number(input, start, _end, elements)
25
+ def make_empty_array(input, starts_at, _ends_at, elements)
26
26
  end
27
27
 
28
- def make_null(input, start, _end)
28
+ def make_number(input, starts_at, _ends_at, elements)
29
29
  end
30
30
 
31
- def make_true(input, start, _end)
31
+ def make_null(input, starts_at, _ends_at)
32
32
  end
33
33
 
34
- def make_false(input, start, _end)
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