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: 8e9cf38a42182748cb66ae4cbe9b0fdee0ee0e28
4
- data.tar.gz: 1697512262d0dc064e714f916475ca2a98bdfa28
3
+ metadata.gz: 2cd736ee5bb577b00f067cd4943957b7336784c8
4
+ data.tar.gz: e84165172550c0b184edb034c407b1351aaa2927
5
5
  SHA512:
6
- metadata.gz: aadbe716cbbb97d6a22147a1b0341df7a7ce06b8eef371d3e1e00f2570c1fe1a1d8a2bcb4b809a5a199c98a1d8596ac11241b1c1beb1613901a948d2a4d8c840
7
- data.tar.gz: 469c6dec4d4fa66a1972a9c4cb5b1d860ad9fd939024ad7e9cb6842652f084e77084cfce4bd4599ece4e4f56f9a526058fb819e9e45ca1b8beab7f8d598f47f5
6
+ metadata.gz: afdad315e8e9a9c74dabbc3c6c648dd23c6583e908ced70144c8a1b4e11e1bd2933ebb2dfcb390293108a99d08db9c916f62e8e24dab7bf1725c973359073763
7
+ data.tar.gz: d716cd9b912a55146524bac052a47c171bc3d119008d54efdaa5b1e237b73dbcab6f97c53fae54068733c5577c0f5ab498ea05362b467fc6cd1111dccbd5d319
@@ -1,4 +1,4 @@
1
- require 'aws-sdk-cloudsearch'
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 transform_attributes(attributes)
18
- attributes.each_with_object({}) do |(name, value), hash|
19
- type = field_types[name]
17
+ def attribute_transformer
18
+ return @attribute_transformer if defined?(@attribute_transformer)
20
19
 
21
- if type.end_with?('array')
22
- hash[name] = value
23
- else
24
- hash[name] = value.first
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.transform_attributes(
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
@@ -1,7 +1,7 @@
1
1
  module Nazrin
2
2
  module Searchable
3
3
  class Configuration
4
- attr_accessor :domain_name
4
+ attr_accessor :domain_name, :attribute_transformer
5
5
 
6
6
  %i(
7
7
  search_endpoint
@@ -1,3 +1,3 @@
1
1
  module Nazrin
2
- VERSION = '2.6.3'
2
+ VERSION = '2.7.0'
3
3
  end
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.6.3
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-03-12 00:00:00.000000000 Z
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