Class: Tem::Mr::Search::MapReduceJob::Mapper

Inherits:
JobPart
  • Object
show all
Defined in:
lib/tem_mr_search/map_reduce_job.rb

Overview

Wrapper for the map SECpack.

Instance Method Summary collapse

Methods inherited from JobPart

#bind, #migrate, #to_plain_object

Constructor Details

#initialize(secpack, job) ⇒ Mapper

Returns a new instance of Mapper.



96
97
98
99
100
# File 'lib/tem_mr_search/map_reduce_job.rb', line 96

def initialize(secpack, job)
  super
  @attributes = job.attributes
  @id_attribute = job.id_attribute
end

Instance Method Details

#map_for_object(object_data) ⇒ Object

SECpack for mapping the given object data into the query.



103
104
105
106
107
108
109
110
111
112
113
# File 'lib/tem_mr_search/map_reduce_job.rb', line 103

def map_for_object(object_data)
  return nil unless @secpack
  object_id = object_data[@id_attribute.to_s]    
  new_secpack = Tem::SecPack.new_from_array @secpack.to_array
  new_secpack.set_bytes :_id, [object_id].pack('q').unpack('C*').reverse
  @attributes.each do |attribute|
    name, type = attribute[:name], attribute[:type]
    new_secpack.set_value name.to_sym, type, object_data[name.to_s]
  end
  new_secpack
end

#map_object(object_data, tem) ⇒ Object

Maps the given object into the query.



116
117
118
119
# File 'lib/tem_mr_search/map_reduce_job.rb', line 116

def map_object(object_data, tem)    
  secpack = map_for_object object_data
  secpack ? tem.execute(secpack) : object_data
end