Class: Traject::Indexer::Context
- Inherits:
-
Object
- Object
- Traject::Indexer::Context
- Defined in:
- lib/traject/indexer/context.rb
Instance Attribute Summary collapse
-
#clipboard ⇒ Object
Returns the value of attribute clipboard.
-
#index_step ⇒ Object
Returns the value of attribute index_step.
-
#input_name ⇒ Object
sometimes we have multiple inputs, input_name describes the current one, and position_in_input the position of the record in the current input -- both can sometimes be blanl when we don't know.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#output_hash ⇒ Object
Returns the value of attribute output_hash.
-
#position ⇒ Object
'position' is a 1-based position in stream of processed records.
-
#position_in_input ⇒ Object
sometimes we have multiple inputs, input_name describes the current one, and position_in_input the position of the record in the current input -- both can sometimes be blanl when we don't know.
-
#settings ⇒ Object
Returns the value of attribute settings.
-
#skipmessage ⇒ Object
Should we be skipping this record?.
-
#source_record ⇒ Object
Returns the value of attribute source_record.
-
#source_record_id_proc ⇒ Object
Returns the value of attribute source_record_id_proc.
Instance Method Summary collapse
-
#initialize(hash_init = {}) ⇒ Context
constructor
A new instance of Context.
-
#record_inspect ⇒ Object
a string label that can be used to refer to a particular record in log messages and exceptions.
-
#skip!(msg = '(no message given)') ⇒ Object
Set the fact that this record should be skipped, with an optional message.
-
#skip? ⇒ Boolean
Should we skip this record?.
-
#source_record_id ⇒ Object
Useful for describing a record in a log or especially error message.
Constructor Details
#initialize(hash_init = {}) ⇒ Context
Returns a new instance of Context.
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/traject/indexer/context.rb', line 8 def initialize(hash_init = {}) # TODO, argument checking for required args? self.clipboard = {} self.output_hash = {} hash_init.each_pair do |key, value| self.send("#{key}=", value) end @skip = false end |
Instance Attribute Details
#clipboard ⇒ Object
Returns the value of attribute clipboard.
21 22 23 |
# File 'lib/traject/indexer/context.rb', line 21 def clipboard @clipboard end |
#index_step ⇒ Object
Returns the value of attribute index_step.
22 23 24 |
# File 'lib/traject/indexer/context.rb', line 22 def index_step @index_step end |
#input_name ⇒ Object
sometimes we have multiple inputs, input_name describes the current one, and position_in_input the position of the record in the current input -- both can sometimes be blanl when we don't know.
28 29 30 |
# File 'lib/traject/indexer/context.rb', line 28 def input_name @input_name end |
#logger ⇒ Object
Returns the value of attribute logger.
21 22 23 |
# File 'lib/traject/indexer/context.rb', line 21 def logger @logger end |
#output_hash ⇒ Object
Returns the value of attribute output_hash.
21 22 23 |
# File 'lib/traject/indexer/context.rb', line 21 def output_hash @output_hash end |
#position ⇒ Object
'position' is a 1-based position in stream of processed records.
24 25 26 |
# File 'lib/traject/indexer/context.rb', line 24 def position @position end |
#position_in_input ⇒ Object
sometimes we have multiple inputs, input_name describes the current one, and position_in_input the position of the record in the current input -- both can sometimes be blanl when we don't know.
28 29 30 |
# File 'lib/traject/indexer/context.rb', line 28 def position_in_input @position_in_input end |
#settings ⇒ Object
Returns the value of attribute settings.
22 23 24 |
# File 'lib/traject/indexer/context.rb', line 22 def settings @settings end |
#skipmessage ⇒ Object
Should we be skipping this record?
31 32 33 |
# File 'lib/traject/indexer/context.rb', line 31 def @skipmessage end |
#source_record ⇒ Object
Returns the value of attribute source_record.
22 23 24 |
# File 'lib/traject/indexer/context.rb', line 22 def source_record @source_record end |
#source_record_id_proc ⇒ Object
Returns the value of attribute source_record_id_proc.
22 23 24 |
# File 'lib/traject/indexer/context.rb', line 22 def source_record_id_proc @source_record_id_proc end |
Instance Method Details
#record_inspect ⇒ Object
a string label that can be used to refer to a particular record in log messages and exceptions. Includes various parts depending on what we got.
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/traject/indexer/context.rb', line 59 def record_inspect str = "<" str << "record ##{position}" if position if input_name && position_in_input str << " (#{input_name} ##{position_in_input}), " elsif position str << ", " end if source_id = source_record_id str << "source_id:#{source_id} " end if output_id = self.output_hash["id"] str << "output_id:#{[output_id].join(',')}" end str.chomp!(" ") str.chomp!(",") str << ">" str end |
#skip!(msg = '(no message given)') ⇒ Object
Set the fact that this record should be skipped, with an optional message
35 36 37 38 |
# File 'lib/traject/indexer/context.rb', line 35 def skip!(msg = '(no message given)') @skipmessage = msg @skip = true end |
#skip? ⇒ Boolean
Should we skip this record?
41 42 43 |
# File 'lib/traject/indexer/context.rb', line 41 def skip? @skip end |
#source_record_id ⇒ Object
Useful for describing a record in a log or especially error message. May be useful to combine with #position in output messages, especially since this method may sometimes return empty string if info on record id is not available.
Returns id from source_record (if we can get it from a source_record_id_proc), then a slash,then output_hash["id"] -- if both are present. Otherwise may return just one, or even an empty string.
53 54 55 |
# File 'lib/traject/indexer/context.rb', line 53 def source_record_id source_record_id_proc && source_record_id_proc.call(source_record) end |