Class Populator::Record
In: lib/populator/record.rb
Parent: Object

This is what is passed to the block when calling populate.

Methods

attribute_values   id   new   type  

Attributes

attributes  [RW] 

Public Class methods

Creates a new instance of Record. Some attributes are set by default:

  • id - defaults to id passed
  • created_at - defaults to current time
  • updated_at - defaults to current time
  • created_on - defaults to current date
  • updated_on - defaults to current date
  • type - defaults to class name (for STI)

[Source]

    # File lib/populator/record.rb, line 14
14:     def initialize(model_class, id)
15:       @attributes = { model_class.primary_key.to_sym => id }
16:       @columns = model_class.column_names
17:       @columns.each do |column|
18:         case column
19:         when 'created_at', 'updated_at'
20:           @attributes[column.to_sym] = Time.now
21:         when 'created_on', 'updated_on'
22:           @attributes[column.to_sym] = Date.today
23:         when model_class.inheritance_column
24:           @attributes[column.to_sym] = model_class.to_s
25:         end
26:       end
27:     end

Public Instance methods

Return values for all columns inside an array.

[Source]

    # File lib/populator/record.rb, line 40
40:     def attribute_values
41:       @columns.map do |column|
42:         @attributes[column.to_sym]
43:       end
44:     end

override id since method_missing won‘t catch this column name

[Source]

    # File lib/populator/record.rb, line 30
30:     def id
31:       @attributes[:id]
32:     end

override type since method_missing won‘t catch this column name

[Source]

    # File lib/populator/record.rb, line 35
35:     def type
36:       @attributes[:type]
37:     end

[Validate]