nazrin 2.6.3 → 2.7.0
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2cd736ee5bb577b00f067cd4943957b7336784c8
|
4
|
+
data.tar.gz: e84165172550c0b184edb034c407b1351aaa2927
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: afdad315e8e9a9c74dabbc3c6c648dd23c6583e908ced70144c8a1b4e11e1bd2933ebb2dfcb390293108a99d08db9c916f62e8e24dab7bf1725c973359073763
|
7
|
+
data.tar.gz: d716cd9b912a55146524bac052a47c171bc3d119008d54efdaa5b1e237b73dbcab6f97c53fae54068733c5577c0f5ab498ea05362b467fc6cd1111dccbd5d319
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
1
|
+
require 'nazrin/data_accessor/struct/attribute_transformer'
|
2
2
|
|
3
3
|
module Nazrin
|
4
4
|
class DataAccessor
|
@@ -14,43 +14,15 @@ module Nazrin
|
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
-
def
|
18
|
-
|
19
|
-
type = field_types[name]
|
17
|
+
def attribute_transformer
|
18
|
+
return @attribute_transformer if defined?(@attribute_transformer)
|
20
19
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
end
|
20
|
+
if config.attribute_transformer
|
21
|
+
@attribute_transformer = config.attribute_transformer
|
22
|
+
else
|
23
|
+
@attribute_transformer = AttributeTransformer.new(config)
|
26
24
|
end
|
27
25
|
end
|
28
|
-
|
29
|
-
def field_types
|
30
|
-
return @field_types if defined?(@field_types)
|
31
|
-
|
32
|
-
response = cloudsearch_client.describe_index_fields(
|
33
|
-
domain_name: config.domain_name
|
34
|
-
)
|
35
|
-
|
36
|
-
@field_types = response.index_fields.each_with_object({}) do |field, fields|
|
37
|
-
name = field.options[:index_field_name]
|
38
|
-
type = field.options[:index_field_type]
|
39
|
-
|
40
|
-
fields[name] = type
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
private
|
45
|
-
|
46
|
-
def cloudsearch_client
|
47
|
-
@cloudsearch_client ||= Aws::CloudSearch::Client.new(
|
48
|
-
region: config.region,
|
49
|
-
access_key_id: config.access_key_id,
|
50
|
-
secret_access_key: config.secret_access_key,
|
51
|
-
logger: config.logger
|
52
|
-
)
|
53
|
-
end
|
54
26
|
end
|
55
27
|
|
56
28
|
def load_all(data)
|
@@ -61,7 +33,7 @@ module Nazrin
|
|
61
33
|
|
62
34
|
def data_from_response(res)
|
63
35
|
res.data[:hits][:hit].map do |hit|
|
64
|
-
self.class.
|
36
|
+
self.class.attribute_transformer.call(
|
65
37
|
{ 'id' => hit[:id] }.merge(hit[:fields] || {})
|
66
38
|
)
|
67
39
|
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'aws-sdk-cloudsearch'
|
2
|
+
|
3
|
+
module Nazrin
|
4
|
+
class DataAccessor
|
5
|
+
class Struct < Nazrin::DataAccessor
|
6
|
+
class AttributeTransformer
|
7
|
+
attr_reader :config, :cloudsearch_client
|
8
|
+
private :config, :cloudsearch_client
|
9
|
+
|
10
|
+
def initialize(config)
|
11
|
+
@config = config
|
12
|
+
@cloudsearch_client = Aws::CloudSearch::Client.new(
|
13
|
+
region: config.region,
|
14
|
+
access_key_id: config.access_key_id,
|
15
|
+
secret_access_key: config.secret_access_key,
|
16
|
+
logger: config.logger
|
17
|
+
)
|
18
|
+
end
|
19
|
+
|
20
|
+
def call(attributes)
|
21
|
+
attributes.each_with_object({}) do |(name, value), hash|
|
22
|
+
type = field_types[name]
|
23
|
+
|
24
|
+
if type.end_with?('array')
|
25
|
+
hash[name] = value
|
26
|
+
else
|
27
|
+
hash[name] = value.first
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def field_types
|
33
|
+
return @field_types if defined?(@field_types)
|
34
|
+
|
35
|
+
response = cloudsearch_client.describe_index_fields(
|
36
|
+
domain_name: config.domain_name
|
37
|
+
)
|
38
|
+
|
39
|
+
@field_types = response.index_fields.each_with_object({}) do |field, fields|
|
40
|
+
name = field.options[:index_field_name]
|
41
|
+
type = field.options[:index_field_type]
|
42
|
+
|
43
|
+
fields[name] = type
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
data/lib/nazrin/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nazrin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tomohiro Suwa
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-04-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk-core
|
@@ -217,6 +217,7 @@ files:
|
|
217
217
|
- lib/nazrin/data_accessor/active_record.rb
|
218
218
|
- lib/nazrin/data_accessor/mongoid.rb
|
219
219
|
- lib/nazrin/data_accessor/struct.rb
|
220
|
+
- lib/nazrin/data_accessor/struct/attribute_transformer.rb
|
220
221
|
- lib/nazrin/document_client.rb
|
221
222
|
- lib/nazrin/paginated_array.rb
|
222
223
|
- lib/nazrin/pagination_generator.rb
|