redi_search 4.0.0 → 4.1.0

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: 80c2f21d79b96177bfd7c5ea162aaee7bbf0d4034cc2481378c05da6abba5658
4
- data.tar.gz: 7fbd1ea8542c4149bea54eff5f25d7e10f3e80ae9cae07d3f0e6203897035c63
3
+ metadata.gz: 5ae66b8370802c6acf6c50487cc751e526bd7afa69be14bf56e0e5b8db416511
4
+ data.tar.gz: ccffbbb3db86598eb132225091cf3cfae3bfac692bca430d2484e7c97f0ab81c
5
5
  SHA512:
6
- metadata.gz: 1a54204869d964261321d808c5a721b8185b05f22af6c484486492b5975539e94c4bf926bc57eb240c2a15f1bf3ced3842b32900a72244a5c007831896b3ca40
7
- data.tar.gz: 1960a094f4d3aac5dd2ea02735d450d1dd67bab8bbb270c315048553a478c7413d766c06a6ffd8f1e8fa216f15ec84936817425e48d6462994d214d24083da29
6
+ metadata.gz: 037fd2b21e9e296e3b143f4d878a9e9cb37406f99c66b22f54a218d1a3d12c046034b19d011b875b2cd5ab3d9a1bb81c4f10b4c862196d01e8a408a2d6436156
7
+ data.tar.gz: 17e0f4dccd59d130c3d76314cff4b2a94da725b1b5bdc2478aaf39dde5c3a34d178cbafb04db45bf5488a8a7006bb043ed14247e46a47a64d362cc94b6fe52f1
@@ -17,6 +17,6 @@ jobs:
17
17
  ruby-version: 3.0
18
18
  - name: Install rubocop
19
19
  run: |
20
- gem install rubocop rubocop-performance rubocop-minitest
20
+ gem install rubocop rubocop-performance rubocop-minitest rubocop-rake
21
21
  - name: Lint
22
22
  run: rubocop --config=./.rubocop.yml --parallel
data/.rubocop.yml CHANGED
@@ -1,6 +1,7 @@
1
1
  require:
2
2
  - rubocop-minitest
3
3
  - rubocop-performance
4
+ - rubocop-rake
4
5
  AllCops:
5
6
  NewCops: enable
6
7
  Exclude:
data/Gemfile CHANGED
@@ -9,10 +9,10 @@ gemspec
9
9
  gem "appraisal", "~> 2.2"
10
10
  gem "faker"
11
11
  gem "mocha"
12
- gem "pry"
13
12
  gem "rubocop"
14
13
  gem "rubocop-minitest"
15
14
  gem "rubocop-performance"
15
+ gem "rubocop-rake"
16
16
  gem "simplecov"
17
17
  gem "sqlite3"
18
18
 
data/Rakefile CHANGED
@@ -20,5 +20,6 @@ Rake::TestTask.new("test:integration") do |t|
20
20
  t.test_files = FileList["test/integration/**/*_test.rb"]
21
21
  end
22
22
 
23
+ desc "run all tests"
23
24
  task test: [:default]
24
25
  task default: ["test:integration", "test:unit", :rubocop]
data/bin/console CHANGED
@@ -5,7 +5,7 @@ require "bundler/setup"
5
5
  require "redi_search"
6
6
 
7
7
  require "faker"
8
- require "pry"
8
+ require "irb"
9
9
  require "active_support/logger"
10
10
  require "active_record"
11
11
 
@@ -34,4 +34,8 @@ def seed_users(count = 10_000)
34
34
  User.reindex
35
35
  end
36
36
 
37
- Pry.start
37
+ def reload!
38
+ exec($0)
39
+ end
40
+
41
+ IRB.start
@@ -5,7 +5,6 @@ source "https://rubygems.org"
5
5
  gem "appraisal", "~> 2.2"
6
6
  gem "faker"
7
7
  gem "mocha"
8
- gem "pry"
9
8
  gem "rubocop"
10
9
  gem "rubocop-minitest"
11
10
  gem "rubocop-performance"
@@ -5,7 +5,6 @@ source "https://rubygems.org"
5
5
  gem "appraisal", "~> 2.2"
6
6
  gem "faker"
7
7
  gem "mocha"
8
- gem "pry"
9
8
  gem "rubocop"
10
9
  gem "rubocop-minitest"
11
10
  gem "rubocop-performance"
@@ -29,7 +29,7 @@ module RediSearch
29
29
  end
30
30
 
31
31
  def field_schema
32
- @field_schema ||= Schema.make_field(field_name, raw_schema)
32
+ @field_schema ||= Schema.make_field(field_name, raw_schema).to_a
33
33
  end
34
34
  end
35
35
  end
@@ -11,8 +11,8 @@ module RediSearch
11
11
  def for_object(index, record, serializer: nil, only: [])
12
12
  object_to_serialize = serializer&.new(record) || record
13
13
 
14
- field_values = index.schema.fields.map do |field|
15
- next unless only.empty? || only.include?(field.to_sym)
14
+ field_values = index.schema.fields.map(&:name).map do |field|
15
+ next unless only.empty? || only.include?(field)
16
16
 
17
17
  [field.to_s, object_to_serialize.public_send(field)]
18
18
  end.compact.to_h
@@ -41,11 +41,15 @@ module RediSearch
41
41
  end
42
42
 
43
43
  def schema_fields
44
- @schema_fields ||= index.schema.fields.map(&:to_s)
44
+ @schema_fields ||= index.schema.fields.map do |field|
45
+ field.name.to_s
46
+ end
45
47
  end
46
48
 
47
49
  def redis_attributes
48
- attributes.to_a.flatten
50
+ attributes.flat_map do |field, value|
51
+ [field, index.schema[field.to_sym].serialize(value)]
52
+ end
49
53
  end
50
54
 
51
55
  def document_id
@@ -80,7 +80,7 @@ module RediSearch
80
80
  end
81
81
 
82
82
  def fields
83
- schema.fields.map(&:to_s)
83
+ schema.fields.map { |field| field.name.to_s }
84
84
  end
85
85
 
86
86
  def reindex(documents, recreate: false)
@@ -12,7 +12,7 @@ module RediSearch
12
12
  schema, options = options.to_a.flatten
13
13
 
14
14
  Object.const_get("RediSearch::Schema::#{schema.to_s.capitalize}Field").
15
- new(field_name, **options.to_h).to_a
15
+ new(field_name, **options.to_h)
16
16
  end
17
17
 
18
18
  def initialize(raw)
@@ -20,17 +20,22 @@ module RediSearch
20
20
  end
21
21
 
22
22
  def to_a
23
- raw.map do |field_name, options|
24
- self.class.make_field(field_name, options)
25
- end.flatten
23
+ fields.map(&:to_a).flatten
24
+ end
25
+
26
+ def [](field)
27
+ fields.group_by(&:name)[field]&.first
26
28
  end
27
29
 
28
30
  def fields
29
- raw.keys
31
+ @fields ||= raw.map do |field_name, options|
32
+ self.class.make_field(field_name, options)
33
+ end.flatten
30
34
  end
31
35
 
32
36
  def add_field(field_name, options)
33
37
  raw[field_name] = options
38
+ @fields = nil
34
39
  self
35
40
  end
36
41
 
@@ -3,6 +3,14 @@
3
3
  module RediSearch
4
4
  class Schema
5
5
  class Field
6
+ def name
7
+ @name&.to_sym
8
+ end
9
+
10
+ def serialize(value)
11
+ value
12
+ end
13
+
6
14
  private
7
15
 
8
16
  FALSES = [
@@ -20,7 +20,7 @@ module RediSearch
20
20
 
21
21
  private
22
22
 
23
- attr_reader :name, :sortable, :no_index
23
+ attr_reader :sortable, :no_index
24
24
 
25
25
  def boolean_options
26
26
  %i(sortable no_index)
@@ -20,7 +20,7 @@ module RediSearch
20
20
 
21
21
  private
22
22
 
23
- attr_reader :name, :sortable, :no_index
23
+ attr_reader :sortable, :no_index
24
24
 
25
25
  def boolean_options
26
26
  %i(sortable no_index)
@@ -20,9 +20,13 @@ module RediSearch
20
20
  query
21
21
  end
22
22
 
23
+ def serialize(value)
24
+ value.join(separator)
25
+ end
26
+
23
27
  private
24
28
 
25
- attr_reader :name, :separator, :sortable, :no_index
29
+ attr_reader :separator, :sortable, :no_index
26
30
 
27
31
  def boolean_options
28
32
  %i(sortable no_index)
@@ -24,7 +24,7 @@ module RediSearch
24
24
 
25
25
  private
26
26
 
27
- attr_reader :name, :weight, :phonetic, :sortable, :no_index, :no_stem
27
+ attr_reader :weight, :phonetic, :sortable, :no_index, :no_stem
28
28
 
29
29
  def boolean_options
30
30
  %i(sortable no_index no_stem)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RediSearch
4
- VERSION = "4.0.0"
4
+ VERSION = "4.1.0"
5
5
  end
data/redi_search.gemspec CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |spec|
8
8
  spec.name = "redi_search"
9
9
  spec.version = RediSearch::VERSION
10
10
  spec.authors = "Nick Pezza"
11
- spec.email = "npezza93@gmail.com"
11
+ spec.email = "pezza@hey.com"
12
12
 
13
13
  spec.summary = %q(RediSearch ruby wrapper that can integrate with Rails)
14
14
  spec.homepage = "https://github.com/npezza93/redi_search"
@@ -26,7 +26,7 @@ Gem::Specification.new do |spec|
26
26
 
27
27
  spec.required_ruby_version = ">= 2.5.0"
28
28
 
29
- spec.add_runtime_dependency "activesupport", ">= 5.2", "< 6.2"
29
+ spec.add_runtime_dependency "activesupport", ">= 5.1", "< 6.2"
30
30
  spec.add_runtime_dependency "redis", ">= 4.0", "< 5.0"
31
31
 
32
32
  spec.add_development_dependency "bundler", ">= 1.17", "< 3"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redi_search
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.0
4
+ version: 4.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Pezza
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-03-05 00:00:00.000000000 Z
11
+ date: 2021-03-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -16,7 +16,7 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '5.2'
19
+ version: '5.1'
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
22
  version: '6.2'
@@ -26,7 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
- version: '5.2'
29
+ version: '5.1'
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
32
  version: '6.2'
@@ -99,7 +99,7 @@ dependencies:
99
99
  - !ruby/object:Gem::Version
100
100
  version: '13.0'
101
101
  description:
102
- email: npezza93@gmail.com
102
+ email: pezza@hey.com
103
103
  executables: []
104
104
  extensions: []
105
105
  extra_rdoc_files: []