class Nazrin::DataAccessor::Struct::AttributeTransformer
Attributes
cloudsearch_client[R]
config[R]
Public Class Methods
new(config)
click to toggle source
# File lib/nazrin/data_accessor/struct/attribute_transformer.rb, line 10 def initialize(config) @config = config @cloudsearch_client = Aws::CloudSearch::Client.new( region: config.region, access_key_id: config.access_key_id, secret_access_key: config.secret_access_key, logger: config.logger ) end
Public Instance Methods
call(attributes)
click to toggle source
# File lib/nazrin/data_accessor/struct/attribute_transformer.rb, line 20 def call(attributes) attributes.each_with_object({}) do |(name, value), hash| type = field_types[name] if type.end_with?('array') hash[name] = value else hash[name] = value.first end end end
field_types()
click to toggle source
# File lib/nazrin/data_accessor/struct/attribute_transformer.rb, line 32 def field_types return @field_types if defined?(@field_types) response = cloudsearch_client.describe_index_fields( domain_name: config.domain_name ) @field_types = response.index_fields.each_with_object({}) do |field, fields| name = field.options[:index_field_name] type = field.options[:index_field_type] fields[name] = type end end