Class: Deimos::ActiveRecordConsume::SchemaModelConverter
- Inherits:
- 
      Object
      
        - Object
- Deimos::ActiveRecordConsume::SchemaModelConverter
 
- Defined in:
- lib/deimos/active_record_consume/schema_model_converter.rb
Overview
Convert a message with a schema to an ActiveRecord model
Instance Method Summary collapse
- 
  
    
      #convert(payload)  ⇒ Hash 
    
    
  
  
  
  
  
  
  
  
  
    Convert a message from a decoded hash to a set of ActiveRecord attributes. 
- 
  
    
      #initialize(decoder, klass)  ⇒ SchemaModelConverter 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    Create new converter. 
Constructor Details
#initialize(decoder, klass) ⇒ SchemaModelConverter
Create new converter
| 10 11 12 13 | # File 'lib/deimos/active_record_consume/schema_model_converter.rb', line 10 def initialize(decoder, klass) @decoder = decoder @klass = klass end | 
Instance Method Details
#convert(payload) ⇒ Hash
Convert a message from a decoded hash to a set of ActiveRecord attributes. Attributes that don't exist in the model will be ignored.
| 19 20 21 22 23 24 25 26 27 28 29 | # File 'lib/deimos/active_record_consume/schema_model_converter.rb', line 19 def convert(payload) attributes = {} @decoder.schema_fields.each do |field| column = @klass.columns.find { |c| c.name == field.name } next if column.nil? next if %w(updated_at created_at).include?(field.name) attributes[field.name] = _coerce_field(column, payload[field.name]) end attributes end |