elasticsearch-model-extensions 0.3.1 → 0.3.2

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: 391098b48433332f19ef9836bd8e49dd95dbbcf1
4
- data.tar.gz: f2c5d5ff94939acf9455c13816cee7136ff8355e
3
+ metadata.gz: 076cb7342044b51ad4a7920aae0dfc09070c015e
4
+ data.tar.gz: bfc79e42c19c27aad6852d0df43513c4517678a5
5
5
  SHA512:
6
- metadata.gz: aba8b1b0a198b56f8922561bfc9f0b2fae188385e12d4d78636ce842e2129aecf314667081ec27d4f3ccb99e01f5feb57b8a2df0bd8b0e6b4334708d2c303deb
7
- data.tar.gz: a60735a7d26bf1e287e393bb0b1177d7f886df09b366d854b3954729db793240b3820558c66634798539803116c20dfd95a77c7133ee9f8a011c0c7c4b96ed42
6
+ metadata.gz: 553c045a7765157dadc41acf13e3cd14194efe87369088cbda79390dab9e48aa4f8655105af1dd0ccd06875fa5691d2def56c68438cffbefd7aaad5cac0bea81
7
+ data.tar.gz: 7879a6be1cf2bf6f9292df21f8aa267d052d70354b8c1b19098ac32e9482c25742b0d3d47a7d63c06f405a295f8258d4051dce46e19b811fdbd11515ed13d217
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: /Users/mumoshu/Repositories/elasticsearch-model-extensions
3
3
  specs:
4
- elasticsearch-model-extensions (0.2.2)
4
+ elasticsearch-model-extensions (0.3.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -70,26 +70,44 @@ module Elasticsearch
70
70
  @association_path_finder ||= Elasticsearch::Model::Extensions::AssociationPathFinding::AssociationPathFinder.new
71
71
  end
72
72
 
73
- def build_hash
74
- child_class = @active_record_class
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
- field_to_update = @field_to_update || begin
77
- path = association_path_finder.find_path(from: @parent_class, to: child_class)
78
- parent_to_child_path = path.map(&:name)
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
- # a has_a b has_a cという関係のとき、cが更新されたらaのフィールドbをupdateする必要がある。
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
- parent_to_child_path ||= [field_to_update]
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
- (path && 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))
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
 
@@ -1,7 +1,7 @@
1
1
  module Elasticsearch
2
2
  module Model
3
3
  module Extensions
4
- VERSION = "0.3.1"
4
+ VERSION = "0.3.2"
5
5
  end
6
6
  end
7
7
  end
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.1
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-25 00:00:00.000000000 Z
11
+ date: 2014-12-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler