elos 1.0.22 → 1.0.23

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: 9ff9706189ea5a190be433cce62e342e05552d05
4
- data.tar.gz: 2ab9903f440a63db5e69ef32a087895b6dba2b00
3
+ metadata.gz: 141f44ad81bf0ce324ac8918170dd06db0df709b
4
+ data.tar.gz: ce57df759708da43d8055905e3bd7c7d106b846c
5
5
  SHA512:
6
- metadata.gz: e07f881970b0912a7f1d15f3ec6dcc5d70beb284f0392e0b06281dbb10ef8f4e28f512a2689026de050fd0a2cd5f913cf2d599df0b8c9df5faa15a56a233d859
7
- data.tar.gz: 6769fd11b933634fda7f3ef626386cec2f0c1a972ea52cc402db7f5e6326137c8c7551b9f598d70e34901ee3a211ab28cae85a0682a0b8199cd2a72921f9d736
6
+ metadata.gz: 03c23fba73664c3facd81d9808da21292e4a35baadcbffb242591372f2ecfd703d8f7280864d06d3a50281f141526611e2928f65a5818e825e10e4785a2e3f5b
7
+ data.tar.gz: 423bd408370fca519eb2e67bcf438491a03ced41a6df7c5b90171203ab987f1955b9315f0164e97478dd3dcdb9d600c413c5019bc5e66969348765db4df4be5f
@@ -15,9 +15,7 @@ module Elos::Index::Indexable
15
15
  end
16
16
 
17
17
  def index(obj, destroy: false, unindex: false)
18
- if !unindex && data = index_data.(obj)
19
- data.merge!(_destroyed: destroy)
20
- data[:json] = data[:json].to_json if data[:json]
18
+ if !unindex && data = wrap_index_data(obj, destroy)
21
19
  params = { index: write_alias_name, type: type_name, body: data }
22
20
  params.merge!(id: obj.id) if obj.id
23
21
  client.index(params)['_id']
@@ -29,5 +27,15 @@ module Elos::Index::Indexable
29
27
  end
30
28
  end
31
29
  end
30
+
31
+ private
32
+
33
+ def wrap_index_data(obj, destroy)
34
+ data = index_data.(obj)
35
+ return unless data
36
+ data.merge!(_destroyed: destroy)
37
+ data[:json] = Elos::Index::Model::Object.encode(data[:json]) if data[:json]
38
+ data
39
+ end
32
40
  end
33
41
  end
@@ -6,7 +6,7 @@ module Elos::Index::Model::Initializable
6
6
  end
7
7
 
8
8
  def initialize(attrs = {})
9
- @_data = Elos::DataObject.new
9
+ @_data = Elos::Index::Model::Object.new
10
10
  @_attrs = attrs
11
11
  run_callbacks :new
12
12
  end
@@ -0,0 +1,54 @@
1
+ class Elos::Index::Model::Object
2
+ attr_reader :object
3
+
4
+ def self.encode(object)
5
+ inner_encode(object).to_json
6
+ end
7
+
8
+ def initialize(params = {})
9
+ @params = params
10
+ @object = objectify(params)
11
+ end
12
+
13
+ def method_missing(method, *args, **hargs, &block)
14
+ if method.to_s.end_with?('=')
15
+ object.send(method, objectify(args[0]))
16
+ elsif object.respond_to?(method)
17
+ object.send(method, *args)
18
+ else
19
+ super
20
+ end
21
+ end
22
+
23
+ protected
24
+
25
+ def self.inner_encode(object)
26
+ if object.is_a?(Hash)
27
+ object.each do |k, v|
28
+ object[k] = inner_encode(v)
29
+ end
30
+ elsif object.is_a?(Array)
31
+ object.each_with_index do |o, i|
32
+ object[i] = inner_encode(o)
33
+ end
34
+ elsif object.is_a?(Elos::Index)
35
+ object.attributes.merge!(type: object.class.name)
36
+ else
37
+ object
38
+ end
39
+ end
40
+
41
+ def objectify(value)
42
+ if value.is_a?(Hash)
43
+ if value.key?(:type)
44
+ value.delete(:type).constantize.new(value)
45
+ else
46
+ OpenStruct.new(Hash[value.map { |k, v| [k, objectify(v)] }])
47
+ end
48
+ elsif value.is_a?(Array)
49
+ value.map { |v| objectify(v) }
50
+ else
51
+ value
52
+ end
53
+ end
54
+ end
data/lib/elos/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class Elos
2
- VERSION = '1.0.22'
2
+ VERSION = '1.0.23'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elos
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.22
4
+ version: 1.0.23
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tetsuri Moriya
@@ -146,7 +146,6 @@ files:
146
146
  - lib/elos.rb
147
147
  - lib/elos/configuration.rb
148
148
  - lib/elos/criteria.rb
149
- - lib/elos/data_object.rb
150
149
  - lib/elos/errors/not_found.rb
151
150
  - lib/elos/errors/validation_failed.rb
152
151
  - lib/elos/helpers.rb
@@ -161,6 +160,7 @@ files:
161
160
  - lib/elos/index/model/attributes.rb
162
161
  - lib/elos/index/model/identifiable.rb
163
162
  - lib/elos/index/model/initializable.rb
163
+ - lib/elos/index/model/object.rb
164
164
  - lib/elos/index/properties.rb
165
165
  - lib/elos/index/raw_helpers.rb
166
166
  - lib/elos/index/refreshable.rb
@@ -1,30 +0,0 @@
1
- class Elos::DataObject
2
- attr_reader :object
3
-
4
- def initialize(params = {})
5
- @params = params
6
- @object = objectify(params)
7
- end
8
-
9
- def method_missing(method, *args, **hargs, &block)
10
- if method.to_s.end_with?('=')
11
- object.send(method, objectify(args[0]))
12
- elsif object.respond_to?(method)
13
- object.send(method, *args)
14
- else
15
- super
16
- end
17
- end
18
-
19
- protected
20
-
21
- def objectify(value)
22
- if value.is_a?(Hash)
23
- OpenStruct.new(Hash[value.map { |k, v| [k, objectify(v)] }])
24
- elsif value.is_a?(Array)
25
- value.map { |v| objectify(v) }
26
- else
27
- value
28
- end
29
- end
30
- end