Class: DatoDump::RecordDumper

Inherits:
Object
  • Object
show all
Defined in:
lib/dato_dump/record_dumper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(record, repo) ⇒ RecordDumper

Returns a new instance of RecordDumper.



9
10
11
12
# File 'lib/dato_dump/record_dumper.rb', line 9

def initialize(record, repo)
  @record = record
  @repo = repo
end

Instance Attribute Details

#recordObject (readonly)

Returns the value of attribute record.



7
8
9
# File 'lib/dato_dump/record_dumper.rb', line 7

def record
  @record
end

#repoObject (readonly)

Returns the value of attribute repo.



7
8
9
# File 'lib/dato_dump/record_dumper.rb', line 7

def repo
  @repo
end

Instance Method Details

#dumpObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/dato_dump/record_dumper.rb', line 14

def dump
  attributes = { id: record.id }
  content_type = record.content_type

  content_type.fields.each do |field|
    attributes[field.api_key] = dump_attribute(
      record.send(field.api_key),
      field
    )
  end

  if content_type.sortable
    attributes["position"] = record.position
  end

  attributes.to_h
end