elastics-models 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.0
1
+ 1.1.1
@@ -2,8 +2,6 @@ require 'elastics-client'
2
2
  require 'elastics-scopes'
3
3
  require 'active_attr'
4
4
 
5
- require 'elastics/struct/mergeable'
6
-
7
5
  require 'elastics/class_proxy/model_syncer'
8
6
  require 'elastics/instance_proxy/model_syncer'
9
7
  require 'elastics/model_syncer'
@@ -28,13 +26,22 @@ require 'elastics/result/document_loader'
28
26
  require 'elastics/result/search_loader'
29
27
  require 'elastics/result/active_model'
30
28
 
29
+ require 'elastics/models_indices'
31
30
  require 'elastics/model_tasks'
32
31
 
33
32
  Elastics::LIB_PATHS << File.dirname(__FILE__)
34
33
 
35
34
  # get_docs calls super so we make sure the result is extended by Scope first
36
- Elastics::Conf.result_extenders |= [ Elastics::Result::DocumentLoader,
37
- Elastics::Result::SearchLoader,
38
- Elastics::Result::ActiveModel ]
35
+ Elastics::Conf.result_extenders |= [ Elastics::Result::DocumentLoader,
36
+ Elastics::Result::SearchLoader,
37
+ Elastics::Result::ActiveModel ]
39
38
  Elastics::Conf.elastics_models = []
40
39
  Elastics::Conf.elastics_active_models = []
40
+
41
+ Elastics::Conf.instance_eval do
42
+
43
+ def indices
44
+ @indices ||= Elastics::ModelsIndices.new(config_file)
45
+ end
46
+
47
+ end
@@ -1,23 +1,5 @@
1
- require 'elastics/tasks'
2
-
3
1
  module Elastics
4
2
 
5
- class Tasks
6
- # patches the Elastics::Tasks#config_hash so it evaluates also the default mapping for models
7
- # it modifies also the index:create task
8
- alias_method :original_config_hash, :config_hash
9
- def config_hash
10
- @config_hash ||= begin
11
- default = {}.extend Struct::Mergeable
12
- (Conf.elastics_models + Conf.elastics_active_models).each do |m|
13
- m = eval"::#{m}" if m.is_a?(String)
14
- default.deep_merge! m.elastics.default_mapping
15
- end
16
- default.deep_merge(original_config_hash)
17
- end
18
- end
19
- end
20
-
21
3
  class ModelTasks < Elastics::Tasks
22
4
 
23
5
  attr_reader :options
@@ -29,15 +11,6 @@ module Elastics
29
11
  options[:batch_size] = options[:batch_size].to_i if options[:batch_size]
30
12
  options[:models] = options[:models].split(',') if options[:models]
31
13
 
32
- if options[:import_options]
33
- import_options = {}
34
- options[:import_options].split('&').each do |pair|
35
- k, v = pair.split('=')
36
- import_options[k.to_sym] = v
37
- end
38
- options[:import_options] = import_options
39
- end
40
-
41
14
  @options = default_options.merge(options).merge(overrides)
42
15
  end
43
16
 
@@ -45,9 +18,7 @@ module Elastics
45
18
  @default_options ||= { :force => false,
46
19
  :timeout => 60,
47
20
  :batch_size => 500,
48
- :import_options => { },
49
21
  :models => Conf.elastics_models,
50
- :config_file => Conf.config_file,
51
22
  :verbose => true }
52
23
  end
53
24
 
@@ -64,22 +35,22 @@ module Elastics
64
35
  # block never called during live-reindex, since it doesn't exist
65
36
  if options[:force]
66
37
  unless deleted.include?(index)
67
- delete_index(index)
38
+ Elastics.delete_index(:index => index)
68
39
  deleted << index
69
40
  Prompter.say_warning "#{index} index deleted" if options[:verbose]
70
41
  end
71
42
  end
72
43
 
73
44
  # block never called during live-reindex, since prefix_index creates it
74
- unless exist?(index)
75
- create(index)
45
+ unless Elastics.exist?(:index => index)
46
+ Conf.indices.create_index(index)
76
47
  Prompter.say_ok "#{index} index created" if options[:verbose]
77
48
  end
78
49
 
79
50
  pbar = ProgBar.new(model.count, options[:batch_size], "Model #{model}: ") if options[:verbose]
80
51
 
81
52
  model.elastics_in_batches(:batch_size => options[:batch_size]) do |batch|
82
- result = Elastics.post_bulk_collection(batch, options[:import_options]) || next
53
+ result = Elastics.post_bulk_collection(batch) || next
83
54
  pbar.process_result(result, batch.size) if options[:verbose]
84
55
  end
85
56
 
@@ -91,7 +62,7 @@ module Elastics
91
62
 
92
63
  def models
93
64
  @models ||= begin
94
- models = options[:models] || Conf.elastics_models
65
+ models = options[:models]
95
66
  raise ArgumentError, 'no class defined. Please use MODELS=ClassA,ClassB ' +
96
67
  'or set the Elastics::Configuration.elastics_models properly' \
97
68
  if models.nil? || models.empty?
@@ -0,0 +1,14 @@
1
+ module Elastics
2
+ class ModelsIndices < Indices
3
+
4
+ def initialize(config_path)
5
+ default = {}.extend Struct::Mergeable
6
+ (Conf.elastics_models + Conf.elastics_active_models).each do |m|
7
+ m = eval"::#{m}" if m.is_a?(String)
8
+ default.deep_merge! m.elastics.default_mapping
9
+ end
10
+ replace default.deep_merge(super)
11
+ end
12
+
13
+ end
14
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elastics-models
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-09-13 00:00:00.000000000 Z
12
+ date: 2013-09-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: elastics-client
@@ -18,7 +18,7 @@ dependencies:
18
18
  requirements:
19
19
  - - '='
20
20
  - !ruby/object:Gem::Version
21
- version: 1.1.0
21
+ version: 1.1.1
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
@@ -26,7 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - '='
28
28
  - !ruby/object:Gem::Version
29
- version: 1.1.0
29
+ version: 1.1.1
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: elastics-scopes
32
32
  requirement: !ruby/object:Gem::Requirement
@@ -34,7 +34,7 @@ dependencies:
34
34
  requirements:
35
35
  - - '='
36
36
  - !ruby/object:Gem::Version
37
- version: 1.1.0
37
+ version: 1.1.1
38
38
  type: :runtime
39
39
  prerelease: false
40
40
  version_requirements: !ruby/object:Gem::Requirement
@@ -42,7 +42,7 @@ dependencies:
42
42
  requirements:
43
43
  - - '='
44
44
  - !ruby/object:Gem::Version
45
- version: 1.1.0
45
+ version: 1.1.1
46
46
  - !ruby/object:Gem::Dependency
47
47
  name: active_attr
48
48
  requirement: !ruby/object:Gem::Requirement
@@ -84,12 +84,12 @@ files:
84
84
  - lib/elastics/model_indexer.rb
85
85
  - lib/elastics/model_syncer.rb
86
86
  - lib/elastics/model_tasks.rb
87
+ - lib/elastics/models_indices.rb
87
88
  - lib/elastics/models_live_reindex.rb
88
89
  - lib/elastics/refresh_callbacks.rb
89
90
  - lib/elastics/result/active_model.rb
90
91
  - lib/elastics/result/document_loader.rb
91
92
  - lib/elastics/result/search_loader.rb
92
- - lib/elastics/struct/mergeable.rb
93
93
  - lib/tasks.rake
94
94
  - VERSION
95
95
  - LICENSE
@@ -1,38 +0,0 @@
1
- module Elastics
2
- module Struct
3
- # allows deep merge between Hashes
4
- module Mergeable
5
-
6
- def deep_merge(*hashes)
7
- merged = deep_dup
8
- hashes.each {|h2| merged.replace(deep_merge_hash(merged,h2))}
9
- merged
10
- end
11
-
12
- def deep_merge!(*hashes)
13
- replace deep_merge(*hashes)
14
- end
15
-
16
- def deep_dup
17
- Marshal.load(Marshal.dump(self))
18
- end
19
-
20
- private
21
-
22
- def deep_merge_hash(h1, h2)
23
- h2 ||= {}
24
- h1.merge(h2) do |key, oldval, newval|
25
- case
26
- when oldval.is_a?(::Hash) && newval.is_a?(::Hash)
27
- deep_merge_hash(oldval, newval)
28
- when oldval.is_a?(::Array) && newval.is_a?(::Array)
29
- oldval + newval
30
- else
31
- newval
32
- end
33
- end
34
- end
35
-
36
- end
37
- end
38
- end