elasticsearch-model-extensions 0.0.3 → 0.0.4

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
  SHA1:
3
- metadata.gz: 187c414c19b2a65be386cf8c75eb4ee039440b2f
4
- data.tar.gz: 18ef824732bed168ee717707eba28d5717418cde
3
+ metadata.gz: 9a5e049bad3147441c538c4b369b93d438dc431c
4
+ data.tar.gz: 93cee441524ba5c0dcfc77e1c4024fe53be31371
5
5
  SHA512:
6
- metadata.gz: 6c8f14d33a0eb2e91ac6c8aaaa3de81a598e3593fc016690c99ec74e21acde23bdf82d14626ce8829f3aa05361f2398a04e0fee068001a4a5b22537524c8c6bf
7
- data.tar.gz: 69cc264beccef5a22492fe67597a843af325db385e56303739e4a09a51fc896f6a22b73a7799115b692370914a8d2bd1d660986ada30a8f3de7c1d2a8fdbce43
6
+ metadata.gz: a34d4689f80a8676ca79f4bd522c45b8d9f044ecf13fe541632e5bcfb120d220bbca7a75c63648c46e2791d8843316a22799957360d512cd9172776bb386977c
7
+ data.tar.gz: 34b1d5ce206560036aad88adcc71833292f4bf7ae0d53a56a941939f09cb70323852ed7d58829b3a89ce884f900d10ff2d46e2f23f14e70d61a23b4bf6ea84dd
@@ -39,7 +39,7 @@ module Elasticsearch
39
39
  def build_hash
40
40
  child_class = @active_record_class
41
41
 
42
- field_to_update = -> {
42
+ field_to_update = @field_to_update || begin
43
43
  path = child_class.path_from(@parent_class)
44
44
  parent_to_child_path = path.map(&:name)
45
45
 
@@ -47,7 +47,9 @@ module Elasticsearch
47
47
  # そのとき、
48
48
  # 親aから子cへのパスが[:b, :c]だったら、bだけをupdateすればよいので
49
49
  parent_to_child_path.first
50
- }.call || @field_to_update
50
+ end
51
+
52
+ parent_to_child_path ||= [field_to_update]
51
53
 
52
54
  puts "#{child_class.name} updates #{@parent_class.name}'s #{field_to_update}"
53
55
 
@@ -117,12 +117,14 @@ module Elasticsearch
117
117
  delayed = options[:delayed] || nil
118
118
  only_if = options[:if] || (-> r { true })
119
119
  records_to_update_documents = options[:records_to_update_documents] || nil
120
+ field_to_update = options[:field_to_update] || nil
120
121
 
121
122
  initialize_active_record!(
122
123
  self,
123
124
  :parent_class => parent_class,
124
125
  :delayed => delayed,
125
126
  :only_if => only_if,
127
+ :field_to_update => field_to_update,
126
128
  :records_to_update_documents => records_to_update_documents
127
129
  )
128
130
  end
@@ -2,6 +2,8 @@ module Elasticsearch
2
2
  module Model
3
3
  module Extensions
4
4
  class ShortestPath
5
+ MAX_DEPTH = 5
6
+
5
7
  class Node
6
8
  include Enumerable
7
9
 
@@ -59,7 +61,10 @@ module Elasticsearch
59
61
 
60
62
  module ClassMethods
61
63
  def breadth_first_search(node, &block)
62
- paths = node.each.map { |e| [e] }
64
+ original_paths = node.each.map { |e| [e] }
65
+ paths = original_paths
66
+
67
+ depth = 0
63
68
 
64
69
  loop {
65
70
  a = paths.select { |p|
@@ -69,12 +74,15 @@ module Elasticsearch
69
74
  }
70
75
 
71
76
  return a if a.size != 0
77
+ raise RuntimeError, 'Maximum depth exceeded while calculating the shortest path' if depth >= Elasticsearch::Model::Extensions::ShortestPath::MAX_DEPTH
72
78
 
73
79
  paths = paths.flat_map { |p|
74
80
  p.last.destination.each.map { |e|
75
81
  p + [e]
76
82
  }
77
83
  }
84
+
85
+ depth += 1
78
86
  }
79
87
  end
80
88
 
@@ -1,7 +1,7 @@
1
1
  module Elasticsearch
2
2
  module Model
3
3
  module Extensions
4
- VERSION = "0.0.3"
4
+ VERSION = "0.0.4"
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elasticsearch-model-extensions
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yusuke KUOKA