elastics-models 1.1.11 → 1.2.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: cf7d1302d02455603f5895e19b5ff67ccf36ed79
4
+ data.tar.gz: 5059bda21dfcef3a4d6bcfe87b8f034a003d2320
5
+ SHA512:
6
+ metadata.gz: 68ff5dfafa3b857bc60765fc9e268ccd22aedf4a8c2d4862dcc0b6e29e37adc03244e0af6c366810ff25a65fb888978301618dbe97149d3f79cc1af03b5b556a
7
+ data.tar.gz: fc0cffc785b4b50461d1125e623bfe84047cc1866df55fa10c3de3ad2a0425b7bff9bf72bbbb85be75a12a362d9d3228f29976ec41cc3aaedfeaa0089673692c
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.11
1
+ 1.2.0
@@ -1,6 +1,9 @@
1
1
  require 'date'
2
- version_path = %w[../VERSION ../../VERSION].detect{|v| File.exist?(File.expand_path(v, __FILE__))}
3
- version = File.read(File.expand_path(version_path, __FILE__)).strip
2
+ version_path = %w[VERSION ../VERSION].detect{|v| File.exist?(v)}
3
+ version = File.read(version_path).strip
4
+ extra_files = []
5
+ extra_files << 'VERSION' if File.exist?('VERSION')
6
+ extra_files << 'LICENSE' if File.exist?('LICENSE')
4
7
 
5
8
  Gem::Specification.new do |s|
6
9
  s.name = 'elastics-models'
@@ -9,7 +12,7 @@ Gem::Specification.new do |s|
9
12
  s.homepage = 'http://elastics.github.io/elastics'
10
13
  s.authors = ["Domizio Demichelis"]
11
14
  s.email = 'dd.nexus@gmail.com'
12
- s.files = `git ls-files -z`.split("\0") + %w[VERSION LICENSE]
15
+ s.files = `git ls-files -z`.split("\0") + extra_files
13
16
  s.version = version
14
17
  s.date = Date.today.to_s
15
18
  s.required_rubygems_version = ">= 1.3.6"
@@ -26,7 +26,7 @@ module Elastics
26
26
  }
27
27
  props.extend(Struct::Mergeable).deep_merge! args.first if args.first.is_a?(Hash)
28
28
 
29
- scope :"#{name}_scope", fields("#{name}.title",
29
+ scope :"#{name}_scope", source("#{name}.title",
30
30
  "#{name}.author",
31
31
  "#{name}.name",
32
32
  "#{name}.content_type",
@@ -2,7 +2,7 @@ module Elastics
2
2
  module InstanceProxy
3
3
  class ModelIndexer < ModelSyncer
4
4
 
5
- # delegates :index, :is_child?, :is_parent? to class_elastics
5
+ # delegates :is_child?, :is_parent? to class_elastics
6
6
  Utils.define_delegation :to => :class_elastics,
7
7
  :in => self,
8
8
  :by => :module_eval,
@@ -32,10 +32,10 @@ module Elastics
32
32
  Elastics.get(metainfo, *vars)
33
33
  end
34
34
 
35
- # like get, but it returns all the fields after a refresh
35
+ # like get, but it returns all the source fields after a refresh
36
36
  def full_get(*vars)
37
37
  return unless instance.elastics_indexable?
38
- Elastics.search_by_id(metainfo, {:refresh => true, :params => {:fields => '*,_source'}}, *vars)
38
+ Elastics.search_by_id(metainfo, {:refresh => true, :params => {:_source => '*'}}, *vars)
39
39
  end
40
40
 
41
41
  def parent_instance
@@ -76,7 +76,7 @@ module Elastics
76
76
  @routing ||= case
77
77
  when instance.respond_to?(:elastics_routing) then instance.elastics_routing
78
78
  when is_child? then parent_instance.elastics.routing
79
- when is_parent? then create_routing
79
+ when is_parent? then id
80
80
  end
81
81
  end
82
82
  attr_writer :routing
@@ -91,8 +91,8 @@ module Elastics
91
91
  attr_writer :parent
92
92
 
93
93
  def metainfo
94
- meta = Vars.new( :index => index, :type => type, :id => id )
95
- params = {}
94
+ meta = Vars.new( :index => index, :type => type, :id => id )
95
+ params = {}
96
96
  params[:routing] = routing if routing
97
97
  params[:parent] = parent if parent
98
98
  meta.merge!(:params => params) unless params.empty?
@@ -103,23 +103,6 @@ module Elastics
103
103
  instance.destroyed? ? remove : store
104
104
  end
105
105
 
106
- private
107
-
108
- BASE62_DIGITS = ('0'..'9').to_a + ('A'..'Z').to_a + ('a'..'z').to_a
109
-
110
- def create_routing
111
- string = [index, type, id].join
112
- remainder = Digest::MD5.hexdigest(string).to_i(16)
113
- result = []
114
- max_power = ( Math.log(remainder) / Math.log(62) ).floor
115
- max_power.downto(0) do |power|
116
- digit, remainder = remainder.divmod(62**power)
117
- result << digit
118
- end
119
- result << remainder if remainder > 0
120
- result.map{|digit| BASE62_DIGITS[digit]}.join
121
- end
122
-
123
106
  end
124
107
  end
125
108
  end
@@ -42,7 +42,7 @@ module Elastics
42
42
  end
43
43
 
44
44
  # block never called during live-reindex, since prefix_index creates it
45
- unless Elastics.exist?(:index => index)
45
+ unless Elastics.indices_exists(:index => index)
46
46
  Conf.indices.create_index(index)
47
47
  Prompter.say_ok "#{index} index created" if options[:verbose]
48
48
  end
@@ -51,7 +51,7 @@ module Elastics
51
51
 
52
52
  pbar = ProgBar.new(model.count, nil, "Model #{model}: ") if opts[:verbose]
53
53
 
54
- model.find_in_batches({:raw_result => true, :params => {:fields => '*,_source'}}, opts) do |result|
54
+ model.find_in_batches({:raw_result => true, :params => {:_source => '*'}}, opts) do |result|
55
55
  batch = result['hits']['hits']
56
56
  result = process_and_post_batch(batch)
57
57
  pbar.process_result(result, batch.size) if opts[:verbose]
@@ -9,13 +9,13 @@ module Elastics
9
9
  result.variables[:context] && result.variables[:context].include?(Elastics::ActiveModel)
10
10
  end
11
11
 
12
- def get_docs
12
+ def get_docs(should_freeze=false)
13
13
  # super is from elastics-scopes
14
- docs = super
14
+ docs = super()
15
15
  return docs if variables[:raw_result]
16
16
  raw_result = self
17
17
  if docs.is_a?(Array)
18
- res = docs.map {|doc| build_object(doc)}
18
+ res = docs.map {|doc| build_object(doc,should_freeze)}
19
19
  res.extend(Struct::Paginable).setup(raw_result['hits']['total'], variables)
20
20
  class << res; self end.class_eval do
21
21
  define_method(:raw_result){ raw_result }
@@ -25,13 +25,13 @@ module Elastics
25
25
  end
26
26
  res
27
27
  else
28
- build_object docs
28
+ build_object docs, should_freeze
29
29
  end
30
30
  end
31
31
 
32
32
  private
33
33
 
34
- def build_object(doc)
34
+ def build_object(doc, should_freeze)
35
35
  attrs = (doc['_source']||{}).merge(doc['fields']||{})
36
36
  object = variables[:context].new attrs
37
37
  raw_result = self
@@ -51,7 +51,7 @@ module Elastics
51
51
  @highlight = doc['highlight']
52
52
  # load the elastics proxy before freezing
53
53
  elastics
54
- self.freeze if raw_result.variables[:params][:fields] || doc['fields']
54
+ self.freeze if should_freeze
55
55
  end
56
56
  object
57
57
  end
metadata CHANGED
@@ -1,62 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elastics-models
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.11
5
- prerelease:
4
+ version: 1.2.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Domizio Demichelis
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2014-01-17 00:00:00.000000000 Z
11
+ date: 2015-11-21 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: elastics-client
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - '='
20
18
  - !ruby/object:Gem::Version
21
- version: 1.1.11
19
+ version: 1.2.0
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
24
  - - '='
28
25
  - !ruby/object:Gem::Version
29
- version: 1.1.11
26
+ version: 1.2.0
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: elastics-scopes
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
31
  - - '='
36
32
  - !ruby/object:Gem::Version
37
- version: 1.1.11
33
+ version: 1.2.0
38
34
  type: :runtime
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
38
  - - '='
44
39
  - !ruby/object:Gem::Version
45
- version: 1.1.11
40
+ version: 1.2.0
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: active_attr
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ! '>='
45
+ - - ">="
52
46
  - !ruby/object:Gem::Version
53
47
  version: 0.6.0
54
48
  type: :runtime
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ! '>='
52
+ - - ">="
60
53
  - !ruby/object:Gem::Version
61
54
  version: 0.6.0
62
55
  description: Provides ActiveRecord, Mongoid, ActiveModel and elasticsearch-mapper-attachment
@@ -67,7 +60,9 @@ executables: []
67
60
  extensions: []
68
61
  extra_rdoc_files: []
69
62
  files:
63
+ - LICENSE
70
64
  - README.md
65
+ - VERSION
71
66
  - elastics-models.gemspec
72
67
  - lib/elastics-models.rb
73
68
  - lib/elastics/active_model.rb
@@ -91,33 +86,29 @@ files:
91
86
  - lib/elastics/result/document_loader.rb
92
87
  - lib/elastics/result/search_loader.rb
93
88
  - lib/tasks.rake
94
- - VERSION
95
- - LICENSE
96
89
  homepage: http://elastics.github.io/elastics
97
90
  licenses:
98
91
  - MIT
92
+ metadata: {}
99
93
  post_install_message:
100
94
  rdoc_options:
101
- - --charset=UTF-8
95
+ - "--charset=UTF-8"
102
96
  require_paths:
103
97
  - lib
104
98
  required_ruby_version: !ruby/object:Gem::Requirement
105
- none: false
106
99
  requirements:
107
- - - ! '>='
100
+ - - ">="
108
101
  - !ruby/object:Gem::Version
109
102
  version: '0'
110
103
  required_rubygems_version: !ruby/object:Gem::Requirement
111
- none: false
112
104
  requirements:
113
- - - ! '>='
105
+ - - ">="
114
106
  - !ruby/object:Gem::Version
115
107
  version: 1.3.6
116
108
  requirements: []
117
109
  rubyforge_project:
118
- rubygems_version: 1.8.25
110
+ rubygems_version: 2.4.5.1
119
111
  signing_key:
120
- specification_version: 3
112
+ specification_version: 4
121
113
  summary: Transparently integrates your models with one or more elasticsearch indices.
122
114
  test_files: []
123
- has_rdoc: