elasticsearch-model-extensions 0.3.1 → 0.3.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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 076cb7342044b51ad4a7920aae0dfc09070c015e
|
4
|
+
data.tar.gz: bfc79e42c19c27aad6852d0df43513c4517678a5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 553c045a7765157dadc41acf13e3cd14194efe87369088cbda79390dab9e48aa4f8655105af1dd0ccd06875fa5691d2def56c68438cffbefd7aaad5cac0bea81
|
7
|
+
data.tar.gz: 7879a6be1cf2bf6f9292df21f8aa267d052d70354b8c1b19098ac32e9482c25742b0d3d47a7d63c06f405a295f8258d4051dce46e19b811fdbd11515ed13d217
|
@@ -70,26 +70,44 @@ module Elasticsearch
|
|
70
70
|
@association_path_finder ||= Elasticsearch::Model::Extensions::AssociationPathFinding::AssociationPathFinder.new
|
71
71
|
end
|
72
72
|
|
73
|
-
def
|
74
|
-
|
73
|
+
def provided_parent_to_child_path
|
74
|
+
field_to_update = @field_to_update
|
75
|
+
|
76
|
+
@parent_to_child_path ||=
|
77
|
+
if field_to_update.is_a? Hash
|
78
|
+
extract_path_from_hash(field_to_update)
|
79
|
+
elsif field_to_update.is_a? Symbol
|
80
|
+
[field_to_update]
|
81
|
+
elsif field_to_update.nil?
|
82
|
+
@calculated_path = association_path_finder.find_path(from: @parent_class, to: @active_record_class)
|
83
|
+
@calculated_path.map(&:name)
|
84
|
+
else
|
85
|
+
raise "Unexpected type for field_to_update: #{field_to_update}(#{field_to_update.class})"
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def extract_path_from_hash(hash)
|
90
|
+
hash.is_a?(Symbol) ? [hash] : (hash.keys.empty? ? [] : [hash.keys.first] + extract_path_from_hash(hash[hash.keys.first]))
|
91
|
+
end
|
75
92
|
|
76
|
-
|
77
|
-
|
78
|
-
|
93
|
+
def provided_field_to_update
|
94
|
+
# a has_a b has_a cという関係のとき、cが更新されたらaのフィールドbをupdateする必要がある。
|
95
|
+
# そのとき、
|
96
|
+
# 親aから子cへのパスが[:b, :c]だったら、bだけをupdateすればよいので
|
97
|
+
provided_parent_to_child_path.first
|
98
|
+
end
|
79
99
|
|
80
|
-
|
81
|
-
|
82
|
-
# 親aから子cへのパスが[:b, :c]だったら、bだけをupdateすればよいので
|
83
|
-
parent_to_child_path.first
|
84
|
-
end
|
100
|
+
def build_hash
|
101
|
+
child_class = @active_record_class
|
85
102
|
|
86
|
-
|
103
|
+
field_to_update = provided_field_to_update
|
104
|
+
parent_to_child_path = provided_parent_to_child_path
|
87
105
|
|
88
106
|
puts "#{child_class.name} updates #{@parent_class.name}'s #{field_to_update}"
|
89
107
|
|
90
108
|
@nested_object_fields = @parent_class.__mapping_reflector__.nested_object_fields_for(parent_to_child_path).map(&:to_s)
|
91
109
|
@has_dependent_fields = @parent_class.__dependency_tracker__.has_dependent_fields?(field_to_update) ||
|
92
|
-
(
|
110
|
+
(@calculated_path && @calculated_path.first.destination.through_class == child_class && @parent_class.__dependency_tracker__.has_association_named?(field_to_update) && @parent_class.__mapping_reflector__.has_document_field_named?(field_to_update))
|
93
111
|
|
94
112
|
custom_if = @if
|
95
113
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: elasticsearch-model-extensions
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yusuke KUOKA
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-12-
|
11
|
+
date: 2014-12-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|