rejson-rb 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
  SHA256:
3
- metadata.gz: dd7a76d54e046c3ba8880b0aaeb7d3df2849b95aad7d5097c321b46d3d82844a
4
- data.tar.gz: 371f4e666bb970f311e24cc9b571ba75a76d16d67fd3fe7c5470c85a512538af
3
+ metadata.gz: 11987003b0b1b4bef4b31354a6c9bbd962351efdfe258ce098b1fa0f64f3ce8f
4
+ data.tar.gz: ff94bae68b52dc5ed825072739024b70db8c5c8d1958beece3f22f979eb9398c
5
5
  SHA512:
6
- metadata.gz: 36a5c940c8efe4c9da419fb23abfdaa5b472bbbc2b87ede905fb74a371d29ab7591c150b43c801cecea8a5b26d78d220594f2dcc28e6fbe3abc82dbcf3aa6ae1
7
- data.tar.gz: 3fafa39182f902bcaf469738666da400ba87258c03dbeec3a4426fc4e47687c337a4d06dacd1377cb0bd2a35e77bb5e66366ddbd1700b380346278fc4c794d6f
6
+ metadata.gz: 0c5355cf126b61fd104f99ef1c2f4950626b33198ee0c13663b4296c95dc34061fce068f09656b6e2d5d6963e277666cbed2d4eb044ad125c12d684fa54595da
7
+ data.tar.gz: 62bfe041a7faa6c50394c634757803f4fffdfb028c580760f355cdadd41f5d34585a260bac2529881d584f2bebdab836e437fbfa33d15aa67716eceb0652b1b8
@@ -0,0 +1,58 @@
1
+ AllCops:
2
+ Exclude:
3
+ - bin/**/*
4
+ - coverage/**/*
5
+ DisplayCopNames: true
6
+ TargetRubyVersion: 2.6
7
+
8
+ Style/Documentation:
9
+ Enabled: false
10
+
11
+ Style/StringLiterals:
12
+ EnforcedStyle: double_quotes
13
+
14
+ Style/GuardClause:
15
+ Enabled: false
16
+
17
+ Style/SlicingWithRange:
18
+ Enabled: true
19
+
20
+ Style/RedundantRegexpEscape:
21
+ Enabled: true
22
+
23
+ Style/RedundantFetchBlock:
24
+ Enabled: true
25
+
26
+ Style/HashEachMethods:
27
+ Enabled: true
28
+
29
+ Style/HashTransformValues:
30
+ Enabled: true
31
+
32
+ Style/HashTransformKeys:
33
+ Enabled: true
34
+
35
+ Metrics/CyclomaticComplexity:
36
+ Max: 9
37
+
38
+ Metrics/PerceivedComplexity:
39
+ Max: 9
40
+
41
+ Metrics/MethodLength:
42
+ Max: 15
43
+
44
+ Metrics/ClassLength:
45
+ Max: 150
46
+
47
+ Metrics/BlockLength:
48
+ Exclude:
49
+ - spec/*
50
+
51
+ Lint/RaiseException:
52
+ Enabled: true
53
+
54
+ Layout/SpaceAroundMethodCallOperator:
55
+ Enabled: true
56
+
57
+ Layout/EmptyLinesAroundAttributeAccessor:
58
+ Enabled: true
@@ -1,22 +1,25 @@
1
1
  ---
2
2
  language: ruby
3
+
4
+ services: docker
3
5
  cache: bundler
4
6
  rvm:
5
7
  - 2.5.5
6
8
  - 2.6.3
7
- before_install: gem install bundler -v 2.0.0
9
+ - ruby-head
10
+
11
+ before_install:
12
+ - gem install bundler -v 2.0.0
13
+ - docker pull redislabs/rejson:edge
14
+ - docker run -d -p 6379:6379 redislabs/rejson:edge
8
15
 
9
16
  install:
10
- # Get Redis
11
- - git clone --depth=1 https://github.com/antirez/redis.git && cd redis && make && cd ..
12
- # Get ReJSON
13
- - git clone --depth=1 https://github.com/RedisLabsModules/ReJSON.git && cd ReJSON && make && cd ..
14
17
  # Install dependency gems
15
18
  - bundle install
16
19
 
17
20
  before_script:
18
- - ./redis/src/redis-server --loadmodule ReJSON/src/rejson.so &
19
21
  - bundle install
20
22
 
21
23
  script:
22
- - bundle exec rspec
24
+ - bundle exec rake rubocop
25
+ - bundle exec rspec
data/Gemfile CHANGED
@@ -5,4 +5,4 @@ source "https://rubygems.org"
5
5
  # Specify your gem's dependencies in rejson-rb.gemspec
6
6
  gemspec
7
7
 
8
- gem "rake", "~> 12.0"
8
+ gem "rake", "~> 12.0"
data/README.md CHANGED
@@ -18,15 +18,57 @@ Or install it yourself as:
18
18
 
19
19
  $ gem install rejson-rb
20
20
 
21
+ ## Usage
22
+
23
+ Make sure you have loaded rejson module in `redis.conf`
24
+ ```ruby
25
+ require 'rejson'
26
+
27
+ rcl = Redis.new # Get a redis client
28
+
29
+ # Get/Set/Delete keys
30
+ obj = {
31
+ 'foo': 42,
32
+ 'arr': [nil, true, 3.14],
33
+ 'truth': {
34
+ 'coord': "out there"
35
+ }
36
+ }
37
+
38
+ rcl.json_set("root", Rejson::Path.root_path, obj)
39
+ # => "OK"
40
+
41
+ rcl.json_set("root", Rejson::Path.new(".foo"), 56)
42
+ # => "OK"
43
+
44
+ rcl.json_get "root", Rejson::Path.root_path
45
+ # => {"foo"=>56, "arr"=>[nil, true, 3.14], "truth"=>{"coord"=>"out there"}}
46
+
47
+ rcl.json_del "root", ".truth.coord"
48
+ # => 1
49
+
50
+ # Use similar to redis-rb client
51
+ rj = rcl.pipelined do
52
+ rcl.set "foo", "bar"
53
+ rcl.json_set "test", ".", "{:foo => 'bar', :baz => 'qux'}"
54
+ end
55
+ # => ["OK", "OK"]
56
+ ```
57
+
58
+ Path to JSON can be passed as `Rejson::Path.new("<path>")` or `Rejson::Path.root_path`. `<path>` syntax can be as mentioned [here](https://oss.redislabs.com/redisjson/path).
59
+
60
+ ### Refer project WIKI for more detailed documentation.
61
+
21
62
  ## Contributing
22
63
 
23
64
  Bug reports and pull requests are welcome on GitHub at https://github.com/vachhanihpavan/rejson-rb. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/vachhanihpavan/rejson-rb/blob/master/CODE_OF_CONDUCT.md).
24
65
 
25
66
  For complete documentation about ReJSON's commands, refer to ReJSON's website.
67
+
26
68
  ## License
27
69
 
28
70
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
29
71
 
30
72
  ## Code of Conduct
31
73
 
32
- Everyone interacting in the Rejson::Rb project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/vachhanihpavan/rejson-rb/blob/master/CODE_OF_CONDUCT.md).
74
+ Everyone interacting in the Rejson project's codebase, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/vachhanihpavan/rejson-rb/blob/master/CODE_OF_CONDUCT.md).#
data/Rakefile CHANGED
@@ -1,13 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "bundler/gem_tasks"
4
+ require "rubocop/rake_task"
5
+
6
+ RuboCop::RakeTask.new
4
7
 
5
8
  begin
6
- require 'rspec/core/rake_task'
9
+ require "rspec/core/rake_task"
7
10
 
8
11
  RSpec::Core::RakeTask.new(:spec)
9
12
 
10
- task :default => :spec
13
+ task default: :spec
11
14
  rescue LoadError
12
15
  # no rspec available
13
16
  end
@@ -2,7 +2,8 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require "bundler/setup"
5
- require "rejson/rb"
5
+ require "rejson/path"
6
+ require "rejson/client"
6
7
 
7
8
  # You can add fixtures and/or initialization code here to make experimenting
8
9
  # with your gem easier. You can also use a different console, if you like.
@@ -5,6 +5,7 @@ require "json"
5
5
 
6
6
  # Extends Redis class to add JSON functions
7
7
  class Redis
8
+ # rubocop:disable Metrics/AbcSize
8
9
  def json_set(key, path, data, options = {})
9
10
  pieces = [key, str_path(path), json_encode(data)]
10
11
  options[:nx] ||= false if options.dig(:nx)
@@ -12,7 +13,7 @@ class Redis
12
13
  options[:xx] ||= false if options.dig(:xx)
13
14
 
14
15
  if options[:nx] && options[:xx]
15
- raise Exception, "nx and xx are mutually exclusive: use one, the other or neither - but not both"
16
+ raise ArgumentError, "nx and xx are mutually exclusive: use one, the other or neither - but not both"
16
17
  elsif options[:nx]
17
18
  pieces.append("NX")
18
19
  elsif options[:xx]
@@ -21,6 +22,7 @@ class Redis
21
22
 
22
23
  call_client(:set, pieces)
23
24
  end
25
+ # rubocop:enable Metrics/AbcSize
24
26
 
25
27
  def json_get(key, *args)
26
28
  pieces = [key]
@@ -43,26 +45,21 @@ class Redis
43
45
  def json_mget(key, *args)
44
46
  pieces = [key]
45
47
 
46
- if args.empty?
47
- raise ArgumentError "Invalid arguments"
48
- else
49
- pieces.append(args)
50
- end
48
+ raise ArgumentError, "Invalid arguments: Missing path" if args.empty?
51
49
 
50
+ pieces.append(args)
52
51
  json_bulk_decode call_client(:mget, pieces)
53
52
  end
54
53
 
55
- def json_del(key, *args)
56
- pieces = [key]
57
- pieces.append(str_path(args))
54
+ def json_del(key, path = Rejson::Path.root_path)
55
+ pieces = [key, str_path(path)]
58
56
  call_client(:del, pieces).to_i
59
57
  end
60
58
 
61
59
  alias json_forget json_del
62
60
 
63
- def json_type(key, *args)
64
- pieces = [key]
65
- pieces.append(str_path(args))
61
+ def json_type(key, path = Rejson::Path.root_path)
62
+ pieces = [key, str_path(path)]
66
63
  call_client(:type, pieces).to_s
67
64
  end
68
65
 
@@ -137,11 +134,11 @@ class Redis
137
134
 
138
135
  private
139
136
 
140
- def str_path(p)
141
- if p.instance_of?(Rejson::Path)
142
- p.str_path
137
+ def str_path(path)
138
+ if path.instance_of?(Rejson::Path)
139
+ path.str_path
143
140
  else
144
- p
141
+ path
145
142
  end
146
143
  end
147
144
 
@@ -167,6 +164,6 @@ class Redis
167
164
 
168
165
  def call_client(cmd, pieces)
169
166
  pieces.prepend("JSON.#{cmd.upcase}").join(" ")
170
- client.call pieces
167
+ @client.call pieces
171
168
  end
172
169
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Rejson
4
- VERSION = "1.0.0"
4
+ VERSION = "1.0.1"
5
5
  end
@@ -9,7 +9,8 @@ Gem::Specification.new do |spec|
9
9
  spec.email = ["vachhanihpavan@gmail.com"]
10
10
 
11
11
  spec.summary = "Redis JSON Ruby Client"
12
- spec.description = "rejson-rb is a package that allows storing, updating and querying objects as JSON documents in Redis database that is intended with RedisJSON module."
12
+ spec.description = "rejson-rb is a package that allows storing, updating and querying objects as JSON documents
13
+ in Redis database that is intended with RedisJSON module."
13
14
  spec.homepage = "https://github.com/vachhanihpavan/rejson-rb"
14
15
  spec.license = "MIT"
15
16
  spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
@@ -27,9 +28,11 @@ Gem::Specification.new do |spec|
27
28
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
29
  spec.require_paths = ["lib"]
29
30
 
30
- spec.add_runtime_dependency "redis", "~> 3.0"
31
- spec.add_runtime_dependency "json", "~> 2.0"
32
- spec.add_development_dependency "bundler", "~> 2.0"
33
- spec.add_development_dependency "rspec", "~> 3.0"
34
- spec.add_development_dependency "simplecov","~> 0.17"
31
+ spec.add_runtime_dependency "json", "~> 2.0"
32
+ spec.add_runtime_dependency "redis", "~> 4.2.1"
33
+
34
+ spec.add_development_dependency "bundler", "~> 2.0"
35
+ spec.add_development_dependency "rspec", "~> 3.0"
36
+ spec.add_development_dependency "rubocop", "=0.86.0"
37
+ spec.add_development_dependency "simplecov", "~> 0.17"
35
38
  end
metadata CHANGED
@@ -1,43 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rejson-rb
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
  - Pavan Vachhani
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-12-23 00:00:00.000000000 Z
11
+ date: 2020-06-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: redis
14
+ name: json
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '3.0'
19
+ version: '2.0'
20
20
  type: :runtime
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: '3.0'
26
+ version: '2.0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: json
28
+ name: redis
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '2.0'
33
+ version: 4.2.1
34
34
  type: :runtime
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: '2.0'
40
+ version: 4.2.1
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '='
74
+ - !ruby/object:Gem::Version
75
+ version: 0.86.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '='
81
+ - !ruby/object:Gem::Version
82
+ version: 0.86.0
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: simplecov
71
85
  requirement: !ruby/object:Gem::Requirement
@@ -80,8 +94,9 @@ dependencies:
80
94
  - - "~>"
81
95
  - !ruby/object:Gem::Version
82
96
  version: '0.17'
83
- description: rejson-rb is a package that allows storing, updating and querying objects
84
- as JSON documents in Redis database that is intended with RedisJSON module.
97
+ description: |-
98
+ rejson-rb is a package that allows storing, updating and querying objects as JSON documents
99
+ in Redis database that is intended with RedisJSON module.
85
100
  email:
86
101
  - vachhanihpavan@gmail.com
87
102
  executables: []
@@ -89,6 +104,7 @@ extensions: []
89
104
  extra_rdoc_files: []
90
105
  files:
91
106
  - ".gitignore"
107
+ - ".rubocop.yml"
92
108
  - ".travis.yml"
93
109
  - CODE_OF_CONDUCT.md
94
110
  - Gemfile
@@ -124,7 +140,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
124
140
  - !ruby/object:Gem::Version
125
141
  version: '0'
126
142
  requirements: []
127
- rubygems_version: 3.0.3
143
+ rubygems_version: 3.0.8
128
144
  signing_key:
129
145
  specification_version: 4
130
146
  summary: Redis JSON Ruby Client