chewy 0.6.1 → 0.6.2

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
  SHA1:
3
- metadata.gz: 751edf8eb80e8e5a9f2eaf9dc2d1a1e639427a91
4
- data.tar.gz: 985d1dd1398d00df7f922cf9147cae1a006f9ca0
3
+ metadata.gz: 12e0c49636421098824baf242c46477ec44a1253
4
+ data.tar.gz: d8861ffbacc81ec75d4c9a40b36ec19b345ef3aa
5
5
  SHA512:
6
- metadata.gz: bf632b85c2b0849ef88b549a170deca5d2ac39f2ec6822eabc7f5bd2d9d3c86ccbca2199bdae3ae72990e59f1de8945aee4547b0efe6b84ae789435895af9c10
7
- data.tar.gz: 787052a2a10499f4b0dba7b68292a7a300616cc170c34e264d821e862fe69553bf61ef1fe9c5d9c6419d6b720fd3673b1cbd564c0011119261ed8e80beff600a
6
+ metadata.gz: a29788d87989658ea5a7017554217b21bfdf6a52c7486a740c977261f5a095b591d5f4f352bb1ccbe5f8a26c74f8e355c0f4c2ce4b896a3a71cdb6106974434f
7
+ data.tar.gz: cffc378f5fe51f0a9507c43315491f005b6f1ad9d993946786583a54df95b44bcba56483d186c6356d2fef2168dc692979146a900b8c33870782eb84cc4c6cb6
@@ -1,5 +1,17 @@
1
1
  # master
2
2
 
3
+ # Version 0.6.2
4
+
5
+ ## Changes
6
+
7
+ * document root id custom value option (@baronworks)
8
+
9
+ ## Bugfixes
10
+
11
+ * Removed decay function defaults (@Linuus)
12
+
13
+ * Correct config file handling in case of empty file
14
+
3
15
  # Version 0.6.1
4
16
 
5
17
  ## Changes
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ['kinwizard@gmail.com']
11
11
  spec.summary = %q{Elasticsearch ODM client wrapper}
12
12
  spec.description = %q{Chewy provides functionality for Elasticsearch index handling, documents import mappings and chainable query DSL}
13
- spec.homepage = ''
13
+ spec.homepage = 'https://github.com/toptal/chewy'
14
14
  spec.license = 'MIT'
15
15
 
16
16
  spec.files = `git ls-files`.split($/)
@@ -174,7 +174,8 @@ module Chewy
174
174
 
175
175
  if File.exists?(file)
176
176
  yaml = ERB.new(File.read(file)).result
177
- YAML.load(yaml)[Rails.env].try(:deep_symbolize_keys)
177
+ hash = YAML.load(yaml)
178
+ hash[Rails.env].try(:deep_symbolize_keys) if hash
178
179
  end
179
180
  end || {}
180
181
  end
@@ -2,10 +2,12 @@ module Chewy
2
2
  module Fields
3
3
  class Root < Chewy::Fields::Base
4
4
  attr_reader :dynamic_templates
5
+ attr_reader :id
5
6
  attr_reader :parent
6
7
  attr_reader :parent_id
7
8
 
8
9
  def initialize(name, options = {})
10
+ @id = options.delete(:id) || options.delete(:_id)
9
11
  @parent = options.delete(:parent) || options.delete(:_parent)
10
12
  @parent_id = options.delete(:parent_id)
11
13
  options.reverse_merge!(value: ->(_){_})
@@ -64,6 +66,12 @@ module Chewy
64
66
  parent_id.arity == 0 ? object.instance_exec(&parent_id) : parent_id.call(object)
65
67
  end
66
68
  end
69
+
70
+ def compose_id(object)
71
+ if id
72
+ id.arity == 0 ? object.instance_exec(&id) : id.call(object)
73
+ end
74
+ end
67
75
  end
68
76
  end
69
77
  end
@@ -454,8 +454,8 @@ module Chewy
454
454
  # :field,
455
455
  # origin: '11, 12',
456
456
  # scale: '2km',
457
- # offset: '5km'
458
- # decay: 0.4
457
+ # offset: '5km',
458
+ # decay: 0.4,
459
459
  # filter: { foo: :bar})
460
460
  # # => {body:
461
461
  # query: {
@@ -474,12 +474,7 @@ module Chewy
474
474
  # }]
475
475
  # } } }
476
476
  def decay(function, field, options = {})
477
- field_options = {
478
- origin: options.delete(:origin) || 0,
479
- scale: options.delete(:scale) || 1,
480
- offset: options.delete(:offset) || 0,
481
- decay: options.delete(:decay) || 0.1
482
- }
477
+ field_options = options.extract!(:origin, :scale, :offset, :decay).delete_if { |_, v| v.nil? }
483
478
  scoring = options.merge(function => {
484
479
  field => field_options
485
480
  })
@@ -90,6 +90,10 @@ module Chewy
90
90
  if self.root_object.parent_id
91
91
  entry[:parent] = self.root_object.compose_parent(object) if object.respond_to?(:id)
92
92
  end
93
+
94
+ if self.root_object.id
95
+ entry[:_id] = self.root_object.compose_id(object)
96
+ end
93
97
 
94
98
  indexed_object = indexed_objects && indexed_objects[entry[:_id].to_s]
95
99
 
@@ -1,3 +1,3 @@
1
1
  module Chewy
2
- VERSION = '0.6.1'
2
+ VERSION = '0.6.2'
3
3
  end
@@ -138,12 +138,7 @@ describe Chewy::Query do
138
138
  specify { expect(subject.decay(:gauss, :field)).not_to eq(subject) }
139
139
  specify { expect(subject.decay(:gauss, :field).criteria.scores).to eq([ {
140
140
  gauss: {
141
- field: {
142
- origin: 0,
143
- scale: 1,
144
- offset: 0,
145
- decay: 0.1
146
- }
141
+ field: {}
147
142
  }
148
143
  }]) }
149
144
  specify { expect { subject.decay(:gauss, :field) }.not_to change { subject.criteria.scores } }
@@ -4,6 +4,6 @@ describe Chewy::Runtime do
4
4
  describe '.version' do
5
5
  specify { expect(described_class.version).to be_a(described_class::Version) }
6
6
  specify { expect(described_class.version).to be >= '1.0' }
7
- specify { expect(described_class.version).to be < '1.4' }
7
+ specify { expect(described_class.version).to be < '1.5' }
8
8
  end
9
9
  end
@@ -279,6 +279,58 @@ describe Chewy::Type::Import do
279
279
  end
280
280
  end
281
281
  end
282
+
283
+ context 'root id', :orm do
284
+ let(:canada) { Country.create(id: 1, name: 'Canada', country_code: 'CA', rating: 4) }
285
+ let(:country) { CountriesIndex::Country }
286
+
287
+ before do
288
+ stub_model(:country)
289
+ end
290
+
291
+ before do
292
+ stub_index(:countries) do
293
+ define_type Country do
294
+ root _id: -> { country_code } do
295
+ field :name
296
+ field :rating
297
+ end
298
+ end
299
+ end
300
+ end
301
+
302
+ specify { expect( country.import(canada) ).to eq(true) }
303
+ specify { expect { country.import(canada) }.to update_index(country).and_reindex(canada.country_code) }
304
+
305
+ specify do
306
+ expect(CountriesIndex.client).to receive(:bulk).with(hash_including(
307
+ body: [{ index: { _id: canada.country_code, data: { 'name' => 'Canada', 'rating' => 4 } } }]
308
+ ))
309
+
310
+ country.import canada
311
+ end
312
+
313
+ specify do
314
+ canada.update_attributes(rating: 9)
315
+
316
+ expect(CountriesIndex.client).to receive(:bulk).with(hash_including(
317
+ body: [{ index: { _id: canada.country_code, data: { 'name' => 'Canada', 'rating' => 9 } } }]
318
+ ))
319
+
320
+ country.import canada
321
+ end
322
+
323
+ specify do
324
+ canada.destroy
325
+
326
+ expect(CountriesIndex.client).to receive(:bulk).with(hash_including(
327
+ body: [{ delete: { _id: canada.country_code } }]
328
+ ))
329
+
330
+ country.import canada
331
+ end
332
+
333
+ end # END root id
282
334
  end
283
335
 
284
336
  describe '.import!', :orm do
@@ -6,6 +6,7 @@ ActiveRecord::Base.logger = Logger.new('/dev/null')
6
6
  ActiveRecord::Schema.define do
7
7
  create_table :countries do |t|
8
8
  t.column :name, :string
9
+ t.column :country_code, :string
9
10
  t.column :rating, :integer
10
11
  end
11
12
 
@@ -64,6 +64,7 @@ RSpec.configure do |config|
64
64
  include Mongoid::Document
65
65
 
66
66
  field :name, type: String
67
+ field :country_code, type: String
67
68
  field :rating, type: Integer
68
69
 
69
70
  has_many :cities, order: :id.asc
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chewy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - pyromaniac
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-16 00:00:00.000000000 Z
11
+ date: 2014-12-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -284,7 +284,7 @@ files:
284
284
  - spec/support/class_helpers.rb
285
285
  - spec/support/fail_helpers.rb
286
286
  - spec/support/mongoid.rb
287
- homepage: ''
287
+ homepage: https://github.com/toptal/chewy
288
288
  licenses:
289
289
  - MIT
290
290
  metadata: {}